【问题标题】:ElementClickInterceptedException on cucumber parallel AbstractTestNGCucumberTests黄瓜并行 AbstractTestNGCucumberTests 上的 ElementClickInterceptedException
【发布时间】: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 实例上。

我尝试了许多问题中提到的几种解决方案,但它们似乎都对我的方案没有帮助

我尝试了以下解决方案

  1. global.wait.until(ExpectedConditions.visibilityOf(PageObjects.AddUser));

  2. global.jsExecutor.executeScript("arguments[0].click();", PageObjects.AddUser);

  3. PageObjects.AddUser.sendKeys(Keys.ENTER);

  4.   Actions builder = new Actions(global.driver); 
                        Action clickElement = (Action) builder.click(PageObjects.AddUser);
                        clickElement.perform();
    
  5. 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


    【解决方案1】:

    您将需要使用 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);
    

    【讨论】:

    • 我试过这个但我得到了同样的错误org.openqa.selenium.ElementClickInterceptedException: Element &lt;button class="btn btn-link pull-right" type="add"&gt; is not clickable at point (1380,80)。我还在上面进行了编辑以包含我所做的更改
    【解决方案2】:

    我使用 courgette-jvm 实现了黄瓜并行性。它开箱即用并在场景级别运行并行测试

    只需在黄瓜中包含类似的跑步者类。我的测试进一步使用RemoteWebdriver 在 selenium 网格上打开多个实例。确保网格已启动并正在运行,并且节点已注册到网格。

    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();
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多