TESTEVERYTHING

Showing posts with label FirefoxDriver. Show all posts
Showing posts with label FirefoxDriver. Show all posts

Monday, 14 November 2016

WebDriver | Automation | launch/Execute on different version of Firefox

Run tests on specific Firefox version | Selenium


Firefox binary

Imagine a situation where you have to test your web application against two different versions of the Firefox browser. By default, when you instantiate FirefoxDriver, the Firefox version that is available on the PATH variable is launched. But if you want to launch a different version of Firefox, we need to use Firefox Binary. For this first steps you have to install all the versions of Firefox which you want to test on your system.

Make sure the installed Firefox versions on different path locations using Custom installation

Installing multiple versions of Firefox


Suppose you have already installed the Firefox(version 22) means default Firefox is already installed. this can be found on your program file location like this..

"C:\Program Files (x86)\Mozilla Firefox"

Now we have to install another Firefox version (lets take Firefox version 23).

1. Download this version from Mozilla site and start installing it.

2. When you reach the following screen in your installation, select Custom.




3. Enter the path as "C:\Mozilla Firefox\" in the path field as shown as follows, and proceed with the installation:



4. Now try to launch Firefox from your code; it will launch Firefox 22 version (default Firefox browser) as it is available in the PATH variable.

5. So, in order to use Firefox 23.0, try to use Firefox Binary. The following is the code example for it:

Here we have to define the path of my another installed Firefox version


import java.io.File;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;

private WebDriver driver;

FirefoxBinary binary = new FirefoxBinary(new File("C:\\Mozilla Firefox\\firefox.exe"));

FirefoxProfile profile = new FirefoxProfile();   

driver = new FirefoxDriver(binary, profile);

driver.get("http://www.google.com");








Monday, 22 September 2014

How to handle login pop up window using Selenium WebDriver?

Hi All,

Some times while using webdriver we have to face login popup handle.  When we passing the url using webdriver.get or webdriver.navigate.to("URL") at this time browser asks for login credentials.
For handle this situation we have to do following things.

1. HTTP Basic Authentication with Selenium WebDriver

the authentication prompt is not available from the Selenium WebDriver. One of the way to handle this limitation is to pass user and password in the url like like below:


         http://username:password@the-site.com
So just to make it more clear. The username is username password is password and the rest is usual URL of your test web

        WebDriver driver = getDriver();
        String URL = "http://" + username + ":" + password + "@" + "link";
        driver.get(URL);
but sometimes it does not work for IE browser
 we can use robot  method


import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

import org.openqa.selenium.Alert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class FillAuthAlert {
 private static final String MY_URL = "https://myurl.com";
 private static final String USERNAME= "myuser";
 private static final String PASSWORD= "mypass";
 
 public static void main(String[] args) throws Exception {

  WebDriver driver = new FirefoxDriver();
  driver.get(MY_URL);
  Alert alert = driver.switchTo().alert();
  Robot robot = new Robot();
  Thread.sleep(1000);
  type(robot, USERNAME);
  robot.keyPress(KeyEvent.VK_TAB);
  robot.keyRelease(KeyEvent.VK_TAB);
  Thread.sleep(1000);
  type(robot, PASSWORD);
  alert.accept();
 }
 
 public static void type(Robot robot, String characters) {
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        StringSelection stringSelection = new StringSelection( characters );
        clipboard.setContents(stringSelection, null);

        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_V);
        robot.keyRelease(KeyEvent.VK_CONTROL);
    }
}

Friday, 10 August 2012

Selenium Webdriver 2 Wait /Sleep for time period/wait next step execution/ Set speed for next execution

Some times we have to wait while running the script like for next execution wait for specific duration.But in web driver 2, I did not find the simple way to wait for next step execution after that I have decided to use simplest way to wait in looping statement. I have created a method just call the method with waiting time in seconds.It will wait for given time period.


Which one is right ?

Translate







Tweet