如何解决如何在页面对象模型中使用 ThreadLocal<WebDriver>
我已经在这个自动化项目上工作了 2 年,现在我正在尝试使用 ThreadLocal 实现并行测试。我对此进行了大量研究,并且已经实现了 ThreadLocal driver = new ThreadLocal();在我的 BaseTestClass 中。我的问题是我正在使用页面对象模型,其中每个页面都是一个带有对象的类。 Eclipse 说将构造函数更改为
public LoginlogoutPage(ThreadLocal<WebDriver> driver) {
this.driver = driver;
}
我这样做了,然后系统会提示我更改 WebDriver 驱动程序;到 ThreadLocal 驱动程序。在我这样做之后,我所有流畅的等待下面都有一条红线说
"The constructor FluentWait<WebDriver>(ThreadLocal<WebDriver>) is undefined"
public class BaseTestCriticalScenarios {
protected static ThreadLocal<WebDriver> driver = new ThreadLocal<>();
@BeforeClass
public void setUp() throws InterruptedException,MalformedURLException {
// --------Extent Report--------
report = ExtentManager.getInstance();
// -----------------------------
System.setProperty("webdriver.chrome.driver","C:\\GRID\\chromedriver.exe");
ChromeOptions option = new ChromeOptions();
// --https://stackoverflow.com/questions/43143014/chrome-is-being-controlled-by-automated-test-software
option.setExperimentalOption("useAutomationExtension",false);
option.setExperimentalOption("excludeSwitches",Collections.singletonList("enable-automation"));
// --https://stackoverflow.com/questions/56311000/how-can-i-disable-save-password-popup-in-selenium
option.addArguments("--disable-features=VizdisplayCompositor");
option.addArguments("--start-maximized");
option.addArguments("--disable-gpu");
Map<String,Object> prefs = new HashMap<String,Object>();
prefs.put("credentials_enable_service",false);
prefs.put("profile.password_manager_enabled",false);
option.setExperimentalOption("prefs",prefs);
System.out.println(System.getenv("BUILD_NUMBER"));
String env = System.getProperty("BUILD_NUMBER");
if (env == null) {
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CapabilityType.broWSER_NAME,"Chrome");
capability.setCapability(ChromeOptions.CAPABILITY,option);
option.merge(capability);
driver.set(new RemoteWebDriver(new URL(COMPLETE_NODE_URL),capability));
getDriver().get(HOME_PAGE);
getDriver().manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
} else {
driver.set(new ChromeDriver(option));
getDriver().manage().window().maximize();
getDriver().get(HOME_PAGE);
getDriver().manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
}
}
public WebDriver getDriver() {
//Get driver from ThreadLocalmap
return driver.get();
}
下面是我的页面对象类
任何帮助将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。