Selenium BasicAutomatedTesting Tutorial
Selenium BasicAutomatedTesting Tutorial
Chapter 0: Foreword
In order to follow with the following instructions, it will be good for you to
understand the basic programming and syntax of Java. The links below point to a
useful site on Java, however, only the most basic Java understanding is needed,
so, theres no need to delve too deep into it yet.
http://www.javabeginner.com/learn-java/basic-language-elements
http://www.javabeginner.com/learn-java/java-control-flow-statements
I hope this will be helpful for all testers out there who is willing to learn more
about Test Automation.
The first line, WebDriver calls upon the driver for the browser. Basically it is a
control and an identifier for the window. For example:
WebDriver driver1 = new FirefoxDriver();
WebDriver driver2 = new FirefoxDriver();
driver1.doSomeShit();
driver2.doSomeEvenMoreSeriousShit();
Some shit will be done on FireFox Browser window 1, and some even more
serious shit will be done on FireFox Browser window 2.
The 2nd line, the driver tries to navigate to the url specified.
The 3rd line, the driver maximizes the window.
Commonly used function in WebDriver is:
close : To close the window.
get: Go to the URL.
findElement: Find an element on a page.
The 4th line, the id of the element of query box is found. This is in order for us
to manipulate (enter text, read) from the element (which is the query box). The
id of the item can be found in the following way.
1. Right click and select Inspect Element
The 5th line is entering text into the element (query box).
Elements can be found by multiple ways. It is determined by the By. as shown.
The following are the commonly used methods to find the element.
Do avoid using cssSelector if possible. The simplest and most effective way is to
use id.
The 6th line is to click on the Google Search.
Tips: Always use the . in NetBeans to see what are the available functions are
provided along with the API.
Quiz1:
Write down the code if you are to combine the action in line 4 and line 5 into 1
single line (only 1 ; instead of 2). (Hint: Refer to line 6)
Challenge1:
Code a simple Function that will take in the variable below, and do navigations
and searches according to what is specified:
String [][] testData =
{
{"google","my first search"},//search on google.com for the text "my first
search"
{"yahoo","my second search"},//search on yahoo.com for the text "my
first search"
{"google","my final search"}
};
Solution:
The solution: