所以我有以下代码,它按预期工作,我只是不明白为什么我需要使用setContext方法将驱动程序设置为上下文,而当我搜索设置时,答案可能对其他人有帮助驱动程序进入上下文,什么也找不到。
我将驱动程序添加到上下文中,以便稍后可以在测试失败侦听器上使用它以获取范围报告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;
}