Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am new to selenium webdriver and by default when i run a script it is opening a session in Firefox. now i want to open this session in other browsers like Google Chrome, IE.

How can i open this sessions?

Thanks Kamlesh

share|improve this question

To create an instance of a browser when running WebDriver test you need to create a driver specific to that browser. Firefox works by default, but to work with other browsers such as chrome you may have to download the driver separately.

This website will give you information on how to install the chrome driver and how to get it running.

You will need to have chrome installed on your test machine as well. Other drivers for other browsers can be installed in the same manner.

You can download them from the links given below,

share|improve this answer
    package mercuryreg;
    import java.util.regex.Pattern;
    import java.util.concurrent.TimeUnit;
    import org.junit.*;
    import static org.junit.Assert.*;
    import static org.hamcrest.CoreMatchers.*;  
    import org.openqa.selenium.*;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.support.ui.Select;
    import com.thoughtworks.selenium.webdriven.commands.IsElementPresent;

    public class MercuryReg {

      @Test
      public void mMercuryReg() throws Exception {

          System.setProperty("webdriver.chrome.driver", "E:\\Softwares_Must_Have\\sele\\chromedriver\\chromedriver.exe");

            WebDriver driver = new ChromeDriver(); 
            driver.manage().window().maximize();


            //Open Home Page
            driver.get("http://newtours.demoaut.com/mercuryregister.php?osCsid=78d86f0aad105bdce1a01c8531e3b2c6");
            //Enter text in search box
            WebElement fname=driver.findElement(By.name("firstName"));
            fname.clear();
            fname.sendKeys("firstName");

............
..........
........
.......
.....
...
..
.
share|improve this answer
    
It would help if you explained what your code is doing to open the session in different browsers instead of just pasting code. That will make your answer useful to anyone looking for this information. – Kate Paulk Jul 15 '14 at 10:59
System.setProperty("webdriver.chrome.driver", "E:\\Softwares_Must_Have\\sele\\chromedriver\\chromedriver.exe");
     WebDriver driver = new ChromeDriver(); 

this is the syntax to locate the third party driver,. you have to download the driver. then you have to initiate and call it..

thanks Prakash and am new to stackexchange..

share|improve this answer

This is possible using the cookies concept of selenium webdriver.

Please refer the below code

public class SessionRestoring {
public WebDriver driver;

    @Test
    public void test() throws InterruptedException{
        driver=new FirefoxDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        //I took gmail.com to show session management
        driver.get("http://gmail.com/");
        //First login to gmail using the firefox driver
        driver.findElement(By.id("Email")).sendKeys("email id here");
        driver.findElement(By.id("Email")).sendKeys(Keys.ENTER);
        driver.findElement(By.id("Passwd")).sendKeys("mail password here");
        driver.findElement(By.id("Passwd")).sendKeys(Keys.ENTER);
        //After login store all cookies into Set<Cookie> type reference variable
        Set<Cookie> allCookies=driver.manage().getCookies();
        //Quit the driver
        driver.quit();
        Thread.sleep(3000);
        //setProperty to the system to open Chrome Driver
        System.setProperty("webdriver.chrome.driver","C:\\Users\\kbmst\\Desktop\\temp\\chromedriver.exe");
        driver=new ChromeDriver();
        driver.manage().window().maximize();
        //Get the same webpage in the new driver i.e, ChromeDriver
        driver.get("http://www.gmail.com/");
        //Add all the cookies which you saved previously.
        for(Cookie c:allCookies){
            driver.manage().addCookie(c);
        }
        //Just Refresh the browser using navigate().refresh() method.
        driver.navigate().refresh();
        //You are done with restoring the session.
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.