Skip to main content
added 518 characters in body
Source Link
Niks
  • 9
  • 1
  • 3

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>

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"));

    
}

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>
added 180 characters in body
Source Link
Michael Durrant
  • 25.2k
  • 3
  • 41
  • 113

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 tldriver = new ThreadLocal();

/**

  • 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));

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

}

public static synchronized WebDriver getDriver() { return tldriver.get(); } BelowBelow code I am using in my test class

@BeforeMethod public void setUp() {

@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")); 

    
}

}

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 tldriver = new ThreadLocal();

/**

  • 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"));

}

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")); 

    
}
Source Link
Niks
  • 9
  • 1
  • 3

Selenium- Parallel test case using testng not working correctly. The same working fine in sequential mode

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 tldriver = new ThreadLocal();

/**

  • 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"));

}