Selenium
-
Upload
manjyot-singh -
Category
Documents
-
view
152 -
download
0
Transcript of Selenium
RB
S54273
2
RB
S54273
History
• 2004, ThoughtWorks, Chicago, Jason Huggins, Core code.
• Shinya Kasatani, ThoughtWorks, Japan, Selenium IDE.
• Jason Huggins, left ThoughtWorks, 2007.
• Jennifer Bevan & Jason Huggins, Google, Worked on RC.
• Simon Stewart, ThoughtWorks, WebDriver.
3
RB
S54273
What
• Framework that runs in your web-browser and in headless mode.
• Hooks for many other languages.–Java, Ruby, Python, C# etc
• Simulate a user navigating through pages and then assert for specific marks on the pages.
• Antidote to Mercury poisoning.
4
RB
S54273
Types
• IDE
• RC – Selenium 1
• Webdriver – Selenium 2
• Grid
5
RB
S54273
Why
• Open source.
• Supports multiple languages.
• Cross browser support.
• Cross OS support.
• Runs in both headless and browser mode.
• Parallel execution.
• CI compatible.
• Unit testing framework support like Junit, TestNG, NUnit, Rspec etc.
• Mobile testing support using Android, IPhone, IPad & Blackberry drivers etc.
6
RB
S54273
Locators
• ID– id=textId
• Name–name=textName
• CSS–css=em
• XPATH–Relative (//div[@id=‘123’]/span)–Absolute (/html/body/div[1])
7
RB
S54273
IDE
8
RB
S54273
IDE Cont-d
9
RB
S54273
IDE Cont-d
10
RB
S54273
RC
11
RB
S54273
WebDriver
12
RB
S54273
RC Vs WebDriver
13
RB
S54273
RC Vs WebDriver Cont-d
14
RB
S54273
Page object model
• Challenge–Unmaintainable project.–Duplicated code.–Not easy to track changes.
• Solution–Use Page object model.
• About–All page specific elements/ methods has to be extracted to separate classes.–Eliminates duplication.– Improves readability. – Less key strokes.
15
RB
S54273
P.O.M Cont-d
public class LoginPage
{
//Locators assigned to variables
@FindBy(how = How.ID, using = “password")
private static WebElement passwordTextField = null;
@FindBy(how = How.NAME, using = “username")
private static WebElement userNameTextField = null;
@FindBy(how = How.XPATH, using = "//input[@name=‘loginButton’]")
private static WebElement loginButton = null;
//Expose methods
public HomePage login(String userName, String password )
{
userNameTextField.sendKeys(userName);
passwordTextField.sendKeys(password);
loginButton.click();
return new HomePage();
}
}
Then in any test class we can call above function like :
LoginPage loginPage=new LoginPage();
HomePage homePage=loginPage.login(“singmaz”,”pass123#”);
16
RB
S54273
Grid
17
RB
S54273
Grid - console
18
RB
S54273
Steps
1) java -jar selenium-server-standalone-2.14.0.jar -role hub (by default it registers at 4444)
2) Open the browser and run the following URL http://localhost:4444/console
3) Open the command prompt at node1 and go to the directory “\selenium-grid-1.0.8-bin\selenium-grid-1.0.8”
4) Type : java -jar selenium-server-standalone-2.14.0.jar -role node -Dport=5555 -Dhost=192.168.1.149 -DhubURL=http://192.168.1.25:4444 -Denvironment=*firefox launch-remote-control
5) Similarly for node2…….noden
6) Everything is sorted.
19
RB
S54273
20
RB
S54273