1

The driver instance initializes as Threadsafe. Till the launching of the browser and pass the URL everything seems to be working. But the credentials passing on anyone's browser, instead of all instances.

Below is the code for set and get the driver.

public static ThreadLocal<WebDriver> tldriver = new ThreadLocal<WebDriver>();

/**
 * This method is used to initialize on the basis of browser name
 * 
 * @param browserName
 * @return
 */

public WebDriver init_driver(String browserName) {
    if (browserName.equals("chrome")) {
        WebDriverManager.chromedriver().setup();
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.setPageLoadStrategy(PageLoadStrategy.NORMAL);
        chromeOptions.addArguments("--incognito");
        tldriver.set(new ChromeDriver(chromeOptions));

    } else if (browserName.equals("ff")) {
        WebDriverManager.firefoxdriver();
        tldriver.set(new FirefoxDriver());
    } else {
        System.out.println(browserName + "Browser value wrong, provide correct browser");
    }
    getDriver().manage().deleteAllCookies();
    getDriver().manage().window().maximize();
    return getDriver();
}

public static synchronized WebDriver getDriver() {
    return tldriver.get();
}

Below code I am using in my test class

@BeforeMethod
public void setUp() {
    
    basePage = new BasePage();
    prop = basePage.init_proprties();
    String browser = prop.getProperty("browser");
    driver = basePage.init_driver(browser);
    loginPage = new LoginPage(driver);
    driver.get(prop.getProperty("url"));
    homePage = loginPage.doLogin(prop.getProperty("username"), prop.getProperty("password"));

    
}

TestNG - XML

<listeners>
    <listener
        class-name="com.qa.zoho.listeners.ExtentReportListener" />
    <!-- <listener class-name="com.qa.zoho.listeners.TestAllureListener" /> -->
</listeners>

<test name="CRM Sanity Test">
    <classes>
        <class name="com.qa.zoho.tests.HomePageTest" />


    </classes>
</test>
2
  • I've imporved formatting but it is hard to help as the details aren't clear enough. need more context and detail such as clearly showing the separate code for the two tests Commented Sep 10, 2021 at 12:14
  • I have 2 test cases, both are running in parallel. In one test case, I m verifying the login user details on the dashboard and in 2nd one verifying the Title and Some other areas. But after launching the browser and pasting the URL the username and password are entered in the single browser only. 2 instances just remain open.
    – Niks
    Commented Sep 13, 2021 at 10:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.