How to do session handling in Selenium Webdriver?

0 votes
How to do session handling in Selenium Webdriver?
Jun 20 in Selenium by Lalita
644 views

1 answer to this question.

0 votes

Hey Lalita, you can perform following steps to handle different sessions in Selenium Webdriver:

  1. Create Tests by defining different sessions:
    • public class CreateSessions {
      @Test    
      public void createSession1(){
      //First session of WebDriver
      System.setProperty("WebDriver.chrome.driver","..\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      driver.get("https://www.google.com/");
      driver.findElement(By.xpath("//*[@id='lst-ib']")).sendKeys("Test");
      driver.close();
      }
      @Test    
      public void createSession2(){
      //Second session of WebDriver
      System.setProperty("WebDriver.chrome.driver","..\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      driver.get("https://www.google.com/");
      driver.findElement(By.xpath("//*[@id='lst-ib']")).sendKeys("Test");
      driver.close();
      }      
      }
  2. Next, configure the testng.xml file by adding parallel attribute to the suite tag:

    • <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
      <suite name="TestSuite" thread-count="3" parallel="methods" >
      <test name="test">
      <classes>
      <class name="tests.CreateSessions">
      </class>
      </classes>
      </test>
      </suite>
  3. Now run the testng.xml file. You will note that the two test methods have created 2 sessions with unique Session Ids and they are running parallelly.
answered Jun 20 by Subhash

Related Questions In Selenium

0 votes
3 answers

How to specify "ENTER" button functionality in Selenium WebDriver code?

using OpenQA.Selenium.Interactions; Actions builder = new Actions(driver); ...READ MORE

answered Feb 12 in Selenium by anonymous
11,345 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,110 points
2,278 views
0 votes
2 answers

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

You first need to download chrome driver ...READ MORE

answered Aug 26 in Selenium by Abha
• 27,180 points
305 views
0 votes
1 answer

How to perform mouse hovering in Selenium WebDriver (Java)?

You many not actually be able to ...READ MORE

answered Apr 3, 2018 in Selenium by nsv999
• 5,110 points

edited Apr 4, 2018 by nsv999 3,300 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
935 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,117 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
856 views
+9 votes
15 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,270 points
70,109 views