黄瓜并行 AbstractTestNGCucumberTests 上的 ElementClickInterceptedException
ElementClickInterceptedException on cucumber parallel AbstractTestNGCucumberTests
我在 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 实例上。
我已经尝试了很多问题中提到的几种解决方案,但其中 none 似乎对我的情况有所帮助
我尝试了以下解决方案
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();
}
您将需要使用 ThreadLocal,因为 WebDriver 不是 ThreadSafe。
复制代码,但思路相同
protected ThreadLocal<WebDriver> wbdriver = new ThreadLocal<WebDriver>();
String url = "https://google.com";
wbdriver.set(new ChromeDriver(options));
wbdriver.get().manage().window().maximize();
wbdriver.get().get(url);
我使用 courgette-jvm
实现了黄瓜并行性。它开箱即用,运行 场景级别的并行测试
只需在黄瓜中包含类似的 运行ner class。我的测试进一步使用 RemoteWebdriver
在 selenium 网格上打开多个实例。确保网格已启动并且 运行ning 并且节点已注册到网格。
import courgette.api.CourgetteOptions;
import courgette.api.CourgetteRunLevel;
import courgette.api.CucumberOptions;
import courgette.api.testng.TestNGCourgette;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@Test
@CourgetteOptions(
threads = 10,
runLevel = CourgetteRunLevel.SCENARIO,
rerunFailedScenarios = true,
rerunAttempts = 1,
showTestOutput = true,
reportTitle = "Courgette-JVM Example",
reportTargetDir = "build",
environmentInfo = "browser=chrome; git_branch=master",
cucumberOptions = @CucumberOptions(
features = "src/test/resources/com/test/",
glue = "com.test.stepdefs",
publish = true,
plugin = {
"pretty",
"json:target/cucumber-report/cucumber.json",
"html:target/cucumber-report/cucumber.html"}
))
class AcceptanceIT extends TestNGCourgette {
}
RemoteWebdriver 配置为
protected RemoteWebDriver createDriver() throws MalformedURLException , IOException {
Properties properties = new Properties();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
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();
}
我在 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 实例上。
我已经尝试了很多问题中提到的几种解决方案,但其中 none 似乎对我的情况有所帮助
我尝试了以下解决方案
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();
}
您将需要使用 ThreadLocal,因为 WebDriver 不是 ThreadSafe。
复制代码,但思路相同
protected ThreadLocal<WebDriver> wbdriver = new ThreadLocal<WebDriver>();
String url = "https://google.com";
wbdriver.set(new ChromeDriver(options));
wbdriver.get().manage().window().maximize();
wbdriver.get().get(url);
我使用 courgette-jvm
实现了黄瓜并行性。它开箱即用,运行 场景级别的并行测试
只需在黄瓜中包含类似的 运行ner class。我的测试进一步使用 RemoteWebdriver
在 selenium 网格上打开多个实例。确保网格已启动并且 运行ning 并且节点已注册到网格。
import courgette.api.CourgetteOptions;
import courgette.api.CourgetteRunLevel;
import courgette.api.CucumberOptions;
import courgette.api.testng.TestNGCourgette;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@Test
@CourgetteOptions(
threads = 10,
runLevel = CourgetteRunLevel.SCENARIO,
rerunFailedScenarios = true,
rerunAttempts = 1,
showTestOutput = true,
reportTitle = "Courgette-JVM Example",
reportTargetDir = "build",
environmentInfo = "browser=chrome; git_branch=master",
cucumberOptions = @CucumberOptions(
features = "src/test/resources/com/test/",
glue = "com.test.stepdefs",
publish = true,
plugin = {
"pretty",
"json:target/cucumber-report/cucumber.json",
"html:target/cucumber-report/cucumber.html"}
))
class AcceptanceIT extends TestNGCourgette {
}
RemoteWebdriver 配置为
protected RemoteWebDriver createDriver() throws MalformedURLException , IOException {
Properties properties = new Properties();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
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();
}