when concurrent threads fill a form in different browser windows, only one form is filled (and not completely either)

StackOverflow https://stackoverflow.com/questions/22711974

質問

First off, I only recently got acquainted Selenium/WebDriver/Maven/TestNG. Here's the situation:

  • I need to test a webapp. The first page has a form to be filled; subsequent pages have various other actions.
  • I have a class (say App.java )that automates most of the webapp using Selenium WebDriver.
  • I now need to execute some test-cases in N parallel threads; which will call various methods from the earlier class. (based on the testcase)
  • For this, I used Selenium Grid/Maven/TestNG using tips gleaned from this link. (and of course, Grid and TestNG documentation.)
  • After setting everything up, I had the following architecture:
    • an App.java (and helper classes) that does the legwork of navigating each page of the webapp;
    • an AppTest.java (and Test01...N.java) that has testcases which call various methods in App.java.

Here's AppTest.java:

public class AppTest {
    protected ThreadLocal<RemoteWebDriver> threadDriver = null;

    @BeforeMethod
    public void setUp() throws Exception {

        threadDriver = new ThreadLocal<RemoteWebDriver>();
        DesiredCapabilities dc = DesiredCapabilities.chrome();
        threadDriver.set(new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc));
    }

    public WebDriver getDriver() {
        return threadDriver.get();
    }

    @AfterMethod
    public void closeBrowser() {
        getDriver().quit();
    }
}

Here's Test01.java

public class TestGroup01 extends AppTest {
    //Doc wasnt clear, but with the values below, I got this testcase to be called 3 times in parallel
    @Test(threadPoolSize = 3, invocationCount = 3,  timeOut = 10000)     
    public void TestCase1() throws Exception {
            App.doSomething(getDriver());
            Thread.sleep(2000);
}

And here's App.doSomething

  public static WebDriver driver;
  public class App {
  public static void doSomething(WebDriver drv) throws Exception {
    driver = drv; //I did this to avoid having to pass drv to every method
    drv.get(URL_TO_TEST);
    AppHelper.enterData(); // this method now accesses driver
  }
  }

Problem

  • The testcase opens up 3 browser windows (as expected). The URL gets loaded and the form opens (as expected). But only one of those windows has any data entered into it. And in that window, only one field is filled. I am completely unable to figure out why this is happening.
  • The App.doSomething method is setting a static variable driver to avoid having to pass drv to every method. Is this somehow a cause?
役に立ちましたか?

解決

This behavior was due to the timeout parameter passed to the @Test annotation.

@Test(threadPoolSize = 3, invocationCount = 3,  timeOut = 10000)     

The parameter determines the maximum time that a test can run. Since I had set it to 10000ms, the test was being silently aborted after that time.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top