【发布时间】:2021-07-01 16:34:52
【问题描述】:
我在 cucumber 6.9.1 中使用 AbstractTestNGCucumberTests 进行并行测试设置,然后使用 RemoteWebDriver 将测试定向到网格
@Override
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
并像下面这样创建 RemoteWebDriver
String hubURL = "http://192.168.1.7:65299/wd/hub";
System.setProperty("webdriver.gecko.driver", "/Users/../../geckodriver");
FirefoxProfile profile = new FirefoxProfile();
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setPlatform(Platform.ANY);
FirefoxOptions options = new FirefoxOptions();
options.merge(capabilities);
return driver = new RemoteWebDriver(new URL(hubURL),options);
它打开了两个 firefox 实例,它们相互重叠,我不断得到
org.openqa.selenium.ElementClickInterceptedException: Element <button class="btn btn-link pull-right" 在一个或另一个 firefox 实例上。
我尝试了许多问题中提到的几种解决方案,但它们似乎都对我的方案没有帮助
我尝试了以下解决方案
-
global.wait.until(ExpectedConditions.visibilityOf(PageObjects.AddUser)); -
global.jsExecutor.executeScript("arguments[0].click();", PageObjects.AddUser); -
PageObjects.AddUser.sendKeys(Keys.ENTER); -
Actions builder = new Actions(global.driver); Action clickElement = (Action) builder.click(PageObjects.AddUser); clickElement.perform(); -
global.wait.until(ExpectedConditions.invisibilityOfElementLocated((By) PageObjects.allDom));
我正在 FF 77.0 和 Mac OS (catalina) 上运行测试
我该如何解决这个问题?
编辑。包括ThreadLocal更改
public class FirefoxManager extends DriverManager{
private final ThreadLocal<RemoteWebDriver> driver = new ThreadLocal<>();
@Override
protected RemoteWebDriver createDriver() throws MalformedURLException , IOException {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
System.out.println("hubport from sys prop var.."+System.getProperty("hub.port"));
String hubURL = "http://192.168.1.7:65299/wd/hub";
System.setProperty("webdriver.gecko.driver", "/Users/amit/Desktop/amit/projects/misc/geckodriver");
FirefoxProfile profile = new FirefoxProfile();
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setPlatform(Platform.ANY);
FirefoxOptions options = new FirefoxOptions();
options.merge(capabilities);
driver.set(new RemoteWebDriver(new URL(hubURL),options));
return driver.get();
}
【问题讨论】:
标签: selenium-webdriver testng selenium-grid cucumber-jvm