by: Software Testing Forum
******************** Video 1 Notes ********************
To test xpath you can use firebug or chrome (press F12 then ESC key)
$x -> for xpath commands
$$ -> CSS Locator
Sample page or test page: http://www.wikipedia.org/
Experiment selection for input field of search and language selection dropdown
// -> signifies or shows DOM properties (read further)
select -> html tags
@ -> is used to call the properties inside the tag
For more xpath functions: http://www.w3schools.com/xpath/xpath_functions.asp
Below are xpath samples:
If the ID is static and you want to select the input field with its id
$x("//input[@id='searchInput']")
This example below shows you that id and name can be used to identifiy the input field
$x("//input[@id='searchInput'][@name='search']")
If you are only sure of the start and other data keeps on changing
or you want to select those that starts-with, below is an example
$x("//input[starts-with(@id, 'search')]")
Here's how to use a substring if you want to base your selection on the portion of the
field's name or id or other tags
$x("//input[substring(@id, 2)='earchInput']")
Here's another example on how to use a substring with ending
$x("//input[substring(@id, 2, 5)='earch']")
If you simply want to select the field with certain pattern and can't be captured
by starts-with and substring, there is also contains function
$x("//input[contains(@id, 'npu')]")
Using following-sibling function will help you select what's beside the item you
just selected if there's no id or name you can use to select it
$x("//input[contains(@id, 'npu')]/following-sibling::select")
If you want to select the parrent it belongs to you can use /parent or /..
If you've noticed for .. it's like the command line in windows, y
$x("//input[contains(@id, 'npu')]/parent::fieldset")
$x("//input[contains(@id, 'npu')]/../..")
$x("//input[contains(@id, 'npu')]/../../../following-sibling::div")
$x("//input[contains(@id, 'npu')]/../../../following-sibling::div[3]")
$x("//select[@id='searchLanguage']/preceding-sibling::input")
Below are some samples of CSS Locator
$$ ("input[id='searchInput']")
$$ ("input[id='searchInput'][name='search']")
Not all xpath codes will work if you simply remove the \\ and @ sign
you wil still have to check the proper syntx for css selector.
Above example just quickly shows you the main difference between xpath codes.
******************** Video 2 Notes ********************
Will list all span under label (we use single / because span is direct child of label)
$x("//label[@for='langsearch-input']/span")
CSS Locator
$$("div[class='langlist langlist-large']>span")
>span is what you add if you want to list down all direct span child of label
Will return the first span child in hierarchy
$$("div[class='langlist langlist-large']>span:nth-child(1)")
works same like nth-child but just ignores the hierarchy
$$("div[class='langlist langlist-large']>span:nth-of-type(1)")
If you want to select the ID you can also use # instead of typing ID
$$("#searchInput")
If it's not a direct childd and you want to select it
(from wikepedia selenium software search result)
$$(".mw-search-results li:nth-of-type(1) a")
Download TestNG framework : http://testng.org/doc/download.html
TestNG allows panel execution of test
TestNG allows execution of failed test which is not in JUnit
testing.xml
<suite name="Wikipedia Test" verbose="3" parallel="tests">
parallel
- methods : if you want to execute per method
- tests : if you want both executed at the same time
driver.close - will free the memory
driver.quit - will quit the browser
******************** Video 5 Notes ********************
Javascript methods in test - never use it unless it's really necessary
Document Object Model (DOM)
-You can use to navigate to each elements
-returns value with same element name in an array
--document.getElementsByName('firstName')
-this is how you get the first value of an array
--document.getElementsByName('firstName')[0]
-while this will put value to your DOM
--document.getElementsByName('firstName')[0].value='selenium'
-below casts the driver to JavascriptExecutor
--((JavascriptExecutor)driver).executeScript("document.getElementsByName('firstName')[0].value='123'");
-and to pause the execution
--Thread.sleep(5000) //5 seconds
dependsOnGroup="regTest"
-- if you want your test executed and dependent on a group of methods
-- it is also included inside @Test(..., @dependsOnGroup="regTest")
-- then the method, to be part of the group should have groups="regTest" inside @Test
if you want to know the time executed per method you can use new GregorianCalendar().getTime();
you can add this before you execute anything in your method, and add it at the end of all the lines
No comments:
Post a Comment