Note that there are some explanatory texts on larger screens.

plurals
  1. POmaintain browser session in webdriver
    text
    copied!<p>I am using Junit 4 and Selenium webdriver in my automation process. I have multiple test cases and each test case requires login functionality.</p> <p>I want to run all the test cases in the same browser window and maintain the login session instead of opening the new browser for each test case and do login everytime. (In my current scripts, am initiating webdriver in each test case and it opens a new window for each test case and do login every time)</p> <p>I want to run a test suite, in which i want to run all my test cases in the same browser window. Please provide me a solution. Code :</p> <pre><code>public class first { public static WebDriver driver; @BeforeClass public static void beforeClass() { System.setProperty("webdriver.chrome.driver", "E:/chromedriver.exe"); System.out.println("Before class"); driver = new ChromeDriver(); } @Test public void login()throws Exception { driver.get("URL"); WebElement login = driver.findElement(By.xpath("my xpath"); login.findElement(By.id("username")).sendKeys("username"); login.findElement(By.id("password")).sendKeys("pwd"); driver.findElement(By.xpath("my xpath")).click(); } </code></pre> <p>}</p> <p>Created second class :</p> <pre><code>public class second { public static WebDriver driver; { @Test public void nextstep()throws Exception { WebElement buttons = driver.findElement(By.xpath("my xpath")); buttons.findElement(By.className("Classname")).click(); } </code></pre> <p>} </p> <p>Test suite class :</p> <pre><code>@RunWith(Suite.class) @SuiteClasses({first.class, second.class}) public class testsuite { public static WebDriver driver; @BeforeClass public static void setUpClass() { System.out.println("Master Setup"); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload