How to do session handling in Selenium Webdriver?

0 votes
How to do session handling in Selenium Webdriver?
Jun 20 in Selenium by Lalita
38 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
6,395 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,050 points
1,619 views
0 votes
1 answer

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

Download the executable driver from: ChromeDriver Download Before ...READ MORE

answered Mar 29, 2018 in Selenium by nsv999
• 5,050 points
180 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,050 points

edited Apr 4, 2018 by nsv999 2,346 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,050 points
259 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
628 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
257 views
+9 votes
13 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,280 points
47,711 views
0 votes
5 answers