Search code examples
javaseleniumselenium-grid

How to make a selenium grid test to login simultaneously


I have a test case that runs using grid. What I want to achieve is executing three different test cases all clicking on login button at the exact same time. When I run pure grid there is always a delay between browsers. How to achieve this using selenium grid and Java?

BR


Solution

  • I solved this issue using a lock and synchronized function. Threads almost click login button Simultaneously

    public class Test extends AstractTest {
     private static int lock = 0;    //Here the lock is initiated once
    
    @DataProvider(name = "Test", parallel = true)
    public Object[][] loadInputDataFromExcel() {
        return Taf.files().populateExcelDataProvider(getGlobalInputDataFileName("testsConfig"));
    }
    
    @Test(description="Simultaneous Login", dataProvider="Test", enabled=true)
    public void SimultaneousLogin(Map<String, String> dp) throws InterruptedException {
    
        setupThreadedBrowserDriver(dp.get("browser")); 
    
        actionNavigateToPage(dp.get("url"));
    
        LoginPage loginPage = new LoginPage();
    
        loginPage.login(dp.get("PersonalNumber"), "password");
        lock++;
        // surround the login button with synchronized block
        synchronized (this) {
            while (lock < 3)
                this.wait();
            this.notifyAll();
            loginPage.loginBtn.clickButton();
        }