Home

Selenium Kick Start:

       Selenium is an open source and one can find its official web site here

You are on this page because you are interested in using selenium tool. Apparently, the key aspects of selenium tool to go when you are interested in the following requirement

 1. Application Under Test (AUT) is a web based which needs to be tested on multiple browsers

 2. Tests has to perform on parallely when time is a main constraint
 3. Needs to execute tests on remote machine, perhaps on developer environment or client machine

Inject to brain:  Alright, before going to start I would like to say that, I am not an expert to explain about selenium on my finger tips, instead would like to share my experience and the common mistakes and solutions I passed through. Also, note that I am going to use java as my language as part of code implementation in the examples you see.

The most of the functions we discuss are available on selenium's official API , for example, if you find terms WebDriver or WebDriverBackedSelenium, Actions, ChromeDriver and so on


Before explaining further, let me start a very simple program, that is will see how to launch browser


Program #1 :

I have named class name as Setup and its in default package

// Importing respective packages for drivers
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Setup {
public static void main(String[] args) {
//Created firefox instance 
WebDriver driver = new FirefoxDriver();
// Magics happens here to launch firefox driver by calling 'get(String url)' method
driver.get("http://www.google.com");
}
}

Lets see the possible beginners mistakes:

1) On console I am seeing following an error:

     Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot find firefox binary in  PATH. 
     Make sure firefox is installed. OS appears to be: WIN8
     Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
     System info: os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_45'
     Driver info: driver.version: FirefoxDriver

which means, we don't have a fire fox browser installed in our computer

Q) How to resolve?

A)  > You can install fire fox browser
      > You can change the browser type to chrome or IE

Q) How can I create Chrome or IE browser object / how can I launch browser other than default fire fox browser?
A)  > Before creating other browser objects other than default fire fox browser we need to set path to respective browser executable file. We will see this in the following code snippet

// Importing respective packages for drivers
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class Setup {

// Chrome executable path
private final static String CHROME_PATH = "C:\\Users\\<user name>\\Downloads\\Selenium\\chromedriver.exe" ;
public static void main(String[] args) {
// Setting here system properties for chrome browser by specifying chrome executable path
System.setProperty("webdriver.chrome.driver", CHROME_PATH);
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
}
}

Q) Where can I find these executable drivers
A) Answer is simple, selenium is an open source so developer are providing these files too, here.

2) I have given everything fine, but page is not loading with URL and giving the following error on console

     FAILED: test
     org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error:              { "code":-    32603,"message":"Cannot navigate to invalid URL"}
     (Session info: chrome=27.0.1453.116)
     (Driver info: chromedriver=2.1,platform=Windows NT 6.1 SP1 x86) (WARNING: The server did not            provide any stacktrace information)
     Command duration or timeout: 158 milliseconds 
     Build info: version: '2.35.0', revision: 'c916b9d', time: '2013-08-12 15:42:01'
     System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_45'
     Session ID: 1ca2288cf0164b957c20be8514e1fb5c
     Driver info: org.openqa.selenium.chrome.ChromeDriver

 Perhaps, we have missed the 'http://' in the URL for example driver.get("www.google.com").






So, you have learned a simple program in selenium and its time to gear up.. may be to do actions on a page with UI... before which we will see how this web page elements can find


No comments:

Post a Comment