Selenium Ide basic

Embed Size (px)

Citation preview

  • 7/26/2019 Selenium Ide basic

    1/37

    Test Automation Using

    Selenium

    1

  • 7/26/2019 Selenium Ide basic

    2/37

    Test Automation

    Test automation is the use of softwareTo set test preconditions.

    To control the execution of tests.

    To compare the actual outcomes to predictedoutcomes.

    To report the Execution Status.

    Commonly, test automation involves

    automating a manual process alreadyin place that uses a formalized testingprocess.

    2

  • 7/26/2019 Selenium Ide basic

    3/37

    Why and When ToAutomate?

    re!uent regression testing

    "epeated test case #$ecution is re!uired

    User Acceptance Tests

    aster eed%ac& to the developers

    "educe the 'uman #(ort

    Test same application on multipleenvironments li&e multiple )S or multipleenv li&e staging or dev or integration

    Softsmith Infotech 3

  • 7/26/2019 Selenium Ide basic

    4/37

    Why and When ToAutomate?

    Test that need to run for multipledata set

    Test same application on multiple%rowsers and their versions*latest+and latest-

    Saucla% and %rowser stac& thatprovides multiple )S and %rowsers

    Softsmith Infotech 4

  • 7/26/2019 Selenium Ide basic

    5/37

    Test Automation Tools

    uic& Test /rofessional 0y '/

    "ational unctional Tester 0y "ational *102 Company-

    Sil& Test 0y 0orland

    Test Complete 0y Automated A A "un *Compuware -

    Watir * )pen Source-

    Selenium * )pen Source-

    Sahi *)pen Source-

    Softsmith Infotech 5

  • 7/26/2019 Selenium Ide basic

    6/37

    Selenium

    Selenium is a ro%ust set of tools thatsupports rapid development of testautomation for we%+%ased applications.

    Selenium provides a rich set of testingfunctions speci3cally geared to the needsof testing of a we% application.

    Selenium operations are highly 4e$i%le,

    allowing many options for locating U1elements and comparing e$pected testresults against actual application %ehavior.

    Softsmith Infotech 6

  • 7/26/2019 Selenium Ide basic

    7/37

    Three important thing for any U1Automation tools5

    6ocating U1 element

    /erforming actions on U1 element

    Chec& points to verify actual and

    e$pected result

    Softsmith Infotech 7

  • 7/26/2019 Selenium Ide basic

    8/37

    Selenium eatures

    Supports Cross 0rowser Testing. TheSelenium tests can %e run on multiple%rowsers.

    Allows scripting in several languages li&e7ava, C8, /'/ and /ython.

    Assertion statements provide an e9cient wayof comparing e$pected and actual results.

    1n%uilt reporting mechanism. Supports multiple )S

    Supports integration with di(erent 1:#;s

    Softsmith Infotech 8

  • 7/26/2019 Selenium Ide basic

    9/37

    :i(erent 1de;s

    #clipse

  • 7/26/2019 Selenium Ide basic

    10/37

    Selenium eatures

    Supports integration with di(erent 1:#;s

    Supports integration with di(erent unittesting framewor&

    C8+

  • 7/26/2019 Selenium Ide basic

    11/37

    Selenium Components

    Selenium 1:# add+on of 3refo$

    Selenium "emote Control Selenium We%driver

    Selenium =rid

    Softsmith Infotech 11

  • 7/26/2019 Selenium Ide basic

    12/37

    Selenium 1:#

    Selenium 1:# is an integrated developmentenvironment for Selenium tests.

    1t is implemented as a irefo$ e$tension, andallows you to record, edit, and replay the

    test in 3refo$ Selenium 1:# allows you to save tests as

    'T26, 7ava, "u%y scripts, or any other format 1t allows you to automatically add assertions

    to all the pages. Allows you to add selenese commands asand when re!uired

    Softsmith Infotech 12

  • 7/26/2019 Selenium Ide basic

    13/37

    Selenium 1:# 1nstallation

    Using irefo$, 3rst, download the 1:# from theSelenium' downloads page When downloadingfrom irefo$, you;ll %e presented with the WindowA. *See

  • 7/26/2019 Selenium Ide basic

    14/37

    Selenium 1nstallation

    Softsmith Infotech 14

    Window A Window B

    To rn the Se!enim"I#$% sim&!' se!ect it from the (irefo) Too!s men* It o&ens

    +s fo!!ows with +n em&t' scri&t"editin, window +nd + men for !o+din,% or

    cre+tin, new test c+ses* -See .e)t S!ide/

  • 7/26/2019 Selenium Ide basic

    15/37

    Selenium 1:# + U1

    Softsmith Infotech 15

    St+rt +nd Sto&

    ecordin,

    Se!eneseScri&t

    $ditor

    Se!enim o,

    e&!+'

    Too!+r

    Accessor

    Are+

  • 7/26/2019 Selenium Ide basic

    16/37

    Selenium )ptions

    Softsmith Infotech 16

    Selenium Options allow you to

    Set The Te)t $ncodin, (orm+t

    Set the #ef+!t +,e Time t

    Set The B+se recordin,o&tion

    Addin, Se!enim ore +nd I#$

    $)tension

    Add Atom+tic +,e Tit!e

    Assertions

    There +re +!so other o&tions

    nder dee!o&ment

  • 7/26/2019 Selenium Ide basic

    17/37

    "ecoding a Selenium TestCase

    )pen irefo$ that has the 1:# installed )pen the %ase U"6 of the application to

    record. >eep the application in a common %ase state. =o To ToolsSelenium 1:# and the 1:# will

    %e opened

  • 7/26/2019 Selenium Ide basic

    18/37

    =eneral SeleneseCommands

    clic&ing a lin& + clickor clickAndWaitcommands

    entering values + typecommand

    selecting options from a drop+downlist%o$ + selectcommand

    clic&ing chec&%o$es or radio %uttons+ clickcommand

    Softsmith Infotech 18

  • 7/26/2019 Selenium Ide basic

    19/37

    "unning our irst SeleniumScript

    2a&e sure the application is in thecommon %ase state.

    Clic& on the run %utton. 'ere you canalso control the speed of thee$ecution using the tool%ar

    )nce the test is run you can view the

    test log in the %ottom of the 1:#window

    Softsmith Infotech 19

  • 7/26/2019 Selenium Ide basic

    20/37

    Creating a Test Suite

    1n the Selenium 1:#you can create anynum%er of test casesand save them as test

    suite. To "un the test Suite

    clic& on the @/layentire test suite

    %utton as shown%elow.

    Softsmith Infotech 20

    Test Site with

    Test1 test2

  • 7/26/2019 Selenium Ide basic

    21/37

    /laying The test Suite with Test"unner

    Test "unner allows you to run the test case in a%rowser loaded with the Selenium+Core

    Test"unner.

    Test runner is invo&ed %y clic&ing the %elowShown %utton in the 1:#

    Softsmith Infotech 21

    n !icin, the Test nner Btton 'o wi!! the

    window +s seen in the ne)t s!ide

  • 7/26/2019 Selenium Ide basic

    22/37

    Test "unner

    Softsmith Infotech 22

    !ic this tton to rn +!! the tests

  • 7/26/2019 Selenium Ide basic

    23/37

    "unning )ptions

    "un a Test CaseClic& the "un %utton to run the currently displayed testcase.

    "un a Test SuiteClic& the "un All %utton to run all the test cases in the

    currently loaded test suite.Stop and Start

    The /ause %utton can %e used to stop the test case while itis running. The icon of this %utton then changes to indicatethe "esume %utton. To continue clic& "esume.

    Stop in the 2iddleou can set a %rea&point in the test case to cause it to stopon a particular command. This is useful for de%ugging yourtest case. To set a %rea&point, select a command, right+clic&, and from the conte$t menu select Toggle 0rea&point.

    Softsmith Infotech 23

  • 7/26/2019 Selenium Ide basic

    24/37

    "unning )ptions

    Start from the Middleou can tell the 1:# to %egin running from aspeci3c command in the middle of the test case.This also is used for de%ugging. To set a start

    point, select a command, right+clic&, and fromthe conte$t menu select SetBClear Start /oint.

    Run Any Single Command:ou%le+clic& any single command to run it %yitself. This is useful when writing a single

    command. 1t lets you immediately test acommand you are constructing, when you arenot sure if it is correct. ou can dou%le+clic& it tosee if it runs correctly. This is also availa%le fromthe conte$t menu.

    Softsmith Infotech 24

  • 7/26/2019 Selenium Ide basic

    25/37

    Adding Assertions to theScript

    Selenese allows multiple ways of chec&ing forU1 elements.

    eri3cations and assertions are used to chec& if an element is present somewhere on the page?

    speci3c te$t is somewhere on the page?

    speci3c te$t is at a speci3c location on the page?

    eri3cations and assertions are not one and thesame.

    1f an assertion fails, the script will %e a%orted%ut if a veri3cation fails the script will continue.

    Softsmith Infotech 25

  • 7/26/2019 Selenium Ide basic

    26/37

    eri3cation Commands

    Softsmith Infotech 26

    verifyTextPresentThis comm+nd is sed to

    chec if + &+rtic!+r te)t is

    &resent in + &+,e or not*

    To +dd this comm+nd % Whi!e

    recordin, the test ste&s ri,htc!ic on the te)t item th+t 'o

    w+nt erif'* nce ri,ht c!iced

    'o c+n find +n o&tion :Show

    +!! comm+nds;* n !icin, it

    'o wi!! find +n o&tion

    :erif'Te)tresent;% se!ect it

  • 7/26/2019 Selenium Ide basic

    27/37

    eri3cation Commands

    verifyTitle This command is used to

    chec& if the page title iscorrect or not.

    To add this command ,

    While recording the teststeps right clic& anywhere on the page thatyou want verify. )nceright clic&ed you can 3ndan option @Show all

    commands. )n Clic&ingit you will 3nd an option@verifyTitle, select it

    Softsmith Infotech 27

  • 7/26/2019 Selenium Ide basic

    28/37

    eri3cation Commands

    verify#lement/resent This command is used to

    verify if a page element ispresent in the page or not.

    To add this command ,

    While recording the teststeps right clic& anyelement on the pagethat you want verify.)nce right clic&ed youcan 3nd an option

    @Show all commands.)n Clic&ing it you will3nd an option@verify#lement/resent,select it

    Softsmith Infotech 28

  • 7/26/2019 Selenium Ide basic

    29/37

    eri3cation Commands

    verifyalue This method is used to chec&

    if edit %o$ has particularvalue or if the chec& %o$ ison. 0asically this methodreturns the value of present

    in the o%Dect. To add this command , While

    recording the test steps rightclic& any element on thepage that you want verifythe value of. )nce right

    clic&ed you can 3nd anoption @Show allcommands. )n Clic&ing ityou will 3nd an option@verifyalue, select it.

    Softsmith Infotech 29

  • 7/26/2019 Selenium Ide basic

    30/37

    Assertions

    Assertions are same as eri3cations.The only di(erence is, if theassertions fail the script will a%ort. 0ut

    the script will continue run in case averi3cation point fails.

    The steps for inserting the assertionsis same as that of veri3cation point.

    While recording "ight Clic& Show allcommands select an assertion.

    Softsmith Infotech 30

  • 7/26/2019 Selenium Ide basic

    31/37

    Assertion Statements

    assertTextPresentThis will assert if the te$t is present in the page.

    assertTextThis will assert if a particular element is having the particular te$t.

    assertTitle This will assert if the page is having a proper title.

    assertValueThis will assert if a Te$t %o$ or chec& %o$ has a particular value

    assertElementPresentThis will assert if a particular U1 #lement is present in the page.

    Softsmith Infotech 31

  • 7/26/2019 Selenium Ide basic

    32/37

    Selenium WaitorCommands

    waitor/ageTo6oadThis command will ma&e the script to wait

    till the page loads.

    Synta$ is waitor/ageTo6oad*timeout-E Timeout is the ma$imum time the script will waitfor the page to load.

    Softsmith Infotech 32

  • 7/26/2019 Selenium Ide basic

    33/37

    )ther waitor Commands

    waitorAlertThis command will wait for the alert message toappear

    waitorTa%le

    This command will wait for the We% ta%le tocompletely load in the pagewaitorTitle

    This command will for the page Title to appear onthe %rowser.

    )ther waitor commandsSelenium has several other wait command li&ewaitorTe$t, waitor/opup and so on. Thesecommands are generically called Synchronizationcommands

    Softsmith Infotech 33

  • 7/26/2019 Selenium Ide basic

    34/37

    Store Commands

    Store command are used to fetch thevalues from the application and storeit in a varia%le. These varia%les can

    %e used latter for validation purpose.

    The Store command can %e used toretrieve the page title, te$t from the

    page and other attri%utes from theapplication.

    Softsmith Infotech 34

  • 7/26/2019 Selenium Ide basic

    35/37

    #cho Command

    #cho command isused to print thevalue in to theselenium 1:S log.

    When printing avaria%le use FGvarH

    There are some

    limitations for thismethods this has to%e used withcaution

    Softsmith Infotech 35

  • 7/26/2019 Selenium Ide basic

    36/37

    6imitations of Selenium 1:#

    Can run the test only on irefo$

  • 7/26/2019 Selenium Ide basic

    37/37