Selenium

20
R B S 5 4 2 7 3

Transcript of Selenium

Page 1: Selenium

RB

S54273

Page 2: Selenium

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.

Page 3: Selenium

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.

Page 4: Selenium

4

RB

S54273

Types

• IDE

• RC – Selenium 1

• Webdriver – Selenium 2

• Grid

Page 5: Selenium

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.

Page 6: Selenium

6

RB

S54273

Locators

• ID– id=textId

• Name–name=textName

• CSS–css=em

• XPATH–Relative (//div[@id=‘123’]/span)–Absolute (/html/body/div[1])

Page 7: Selenium

7

RB

S54273

IDE

Page 8: Selenium

8

RB

S54273

IDE Cont-d

Page 9: Selenium

9

RB

S54273

IDE Cont-d

Page 10: Selenium

10

RB

S54273

RC

Page 11: Selenium

11

RB

S54273

WebDriver

Page 12: Selenium

12

RB

S54273

RC Vs WebDriver

Page 13: Selenium

13

RB

S54273

RC Vs WebDriver Cont-d

Page 14: Selenium

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.

Page 15: Selenium

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#”);

Page 16: Selenium

16

RB

S54273

Grid

Page 17: Selenium

17

RB

S54273

Grid - console

Page 18: Selenium

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.

singmaz, 04/02/2014
environment can be : *safari, *iexplore, *firefox etc.
Page 19: Selenium

19

RB

S54273

Page 20: Selenium

20

RB

S54273