1

I am trying to execute parallel testing in tow test cases(methods) in two same browsers. But when I run, it opens two same browsers but the execution is performed in one browser, means two test methods executed in one browser.

BaseClass.Java

 public class BaseClass {

    public WebDriver driver;
    public FBLoginPage loginPage;

    @BeforeMethod
    public void launch() {

        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();
        
        driver.manage().window().maximize();
        driver.get("http://demo.guru99.com/test/newtours/");
        
        loginPage = new FBLoginPage();
        PageFactory.initElements(driver, loginPage);
    }

    @AfterMethod
    public void tearDown() {
        driver.quit();
    }
}

FBLoginPage.java (Page Class)

 public class FBLoginPage {
    
    @FindBy(xpath = "//input[@name='userName']")
    public WebElement userName;
    
    @FindBy(xpath = "//input[@name='password']")
    public WebElement password;
    
    @FindBy(xpath = "//input[@name='submit']")
    public WebElement submitButton;
    
    
    @FindBy(xpath = "//a[normalize-space()='REGISTER']")
    public WebElement registerLink;
    
    
    public void doLogin(String uname, String pwd) throws Exception {
        
        Thread.sleep(2000);
        userName.sendKeys(uname);
        password.sendKeys(pwd);
        
        Thread.sleep(2000);
        submitButton.click();   
    }
    
    public void clickOnRegisterLink() throws Exception {
        
        Thread.sleep(2000);
        registerLink.click();
    }
}

FBLoginTest.java (Test Class)

public class FBLoginTest extends BaseClass {

    @Test(priority = 1)
    public void loginTest_ValidCredential() throws Exception {

        String beforeLoginURL = driver.getCurrentUrl();
        Thread.sleep(1000);
        loginPage.doLogin("abc@gmail.com", "password");

        Thread.sleep(2000);
        String afterLoginURL = driver.getCurrentUrl();

        Assert.assertEquals(true, !(beforeLoginURL.equals(afterLoginURL)), "Login unSuccessful");
    }
    
    @Test(priority = 2)
    public void clickOnSecurityProject_LoginPage() throws Exception {

        String beforeLoginURL = driver.getCurrentUrl();
        loginPage.clickOnRegisterLink();

        Thread.sleep(2000);
        String afterLoginURL = driver.getCurrentUrl();

        Assert.assertEquals(true, !(beforeLoginURL.equals(afterLoginURL)), "Test case fail");
    }
}

testNG.xml

<suite name="Suite">
    <test thread-count="2" name="Test" parallel="methods">
        <classes>
            <class name="demo.TestCases.FBLoginTest" />
        </classes>
    </test>
</suite>

In the above code, when I run it through xml, then two same(chrome) browser are opening but exction is performed in one browser. Please help me to solve this problem Thank You

Raj
  • 11
  • 1

0 Answers0