Итак, у меня есть следующий код, который работает, как и ожидалось, я просто не понимаю, почему мне нужно использовать метод setContext для установки драйвера в контексте, и ответ может быть полезен для других, поскольку я гуглюл о настройкеводитель в контекст и ничего не смог найти.
Я добавляю драйвер в контекст, чтобы позже его можно было использовать в прослушивателе неудачных тестов для скриншота в Extent Reports 3.
Любое объяснение будет полезно.
private static ITestContext context;
/**
* @param context
*/
@BeforeClass
public void setUp(ITestContext context) {
setChromeDriverProperty();
if (driver == null) {
TestBase.driver = new ChromeDriver();
}
if (driver != null) {
TestBase.wait = new WebDriverWait(driver, 20);
}
if (driver != null) {
TestBase.fluentWait = new FluentWait<WebDriver>(driver).withTimeout(Duration.ofSeconds(1))
.pollingEvery(Duration.ofMillis(500)).ignoring(NoSuchElementException.class)
.ignoring(StaleElementReferenceException.class);
}
**//So if I use the method below(setContext) everything works as expected**
TestBase.context = setContext(context, driver);
**//But if I want to set the driver into the context like below(I get Type
mismatch: cannot convert from void to ITestContext)**
Can anyone explain why is this the case and how does the below method
solve that? I tried to set the setUp method as ITestContext instead of void but that didn't help.**
TestBase.context = context.setAttribute("driver", driver);
TestBase.driver.manage().window().maximize();
Reporter.log("====================Application Started====================", true);
}
public static ITestContext setContext(ITestContext context, WebDriver driver) {
context.setAttribute("driver", driver);
return context;
}