How to do session handling in Selenium Webdriver

0 votes
How to do session handling in Selenium Webdriver?
Jun 20, 2019 in Selenium by Lalita
11,035 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, 2019 by Subhash

Related Questions In Selenium

0 votes
6 answers

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

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

answered Feb 13, 2019 in Selenium by anonymous
94,752 views
+1 vote
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,500 points
7,947 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, 2019 in Selenium by Abha
• 28,140 points
1,671 views
+1 vote
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,500 points

edited Aug 22, 2023 by Khan Sarfaraz 10,254 views
0 votes
2 answers

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,500 points
12,697 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,595 views
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,910 points
6,664 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,543 views
0 votes
1 answer
+10 votes
17 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,360 points
194,110 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP