Web Testing With Selenium and JUnit by Quontra Solutions
-
Upload
quontrasolutions -
Category
Documents
-
view
226 -
download
0
Transcript of Web Testing With Selenium and JUnit by Quontra Solutions
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
1/15
Locators In SeleniumPresented By
Quontra SolutionsOnline Training on all IT Courses
For Free Demo
Call Us:+1(404)-900-9988Email: [email protected]
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
2/15
What is Selenium?Selenium
Portable software testing framework for webapplications
Selenium IDE
Selenium Client Drivers
Selenium RC
Selenium Grid
2
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
3/15
Why use Selenium?Why automated testing? Speed
Repeatability
Reliability Cost
Requalification (security patches)
Verisimilitude (vs HTMLUnit)
3
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
4/15
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
5/15
Identifier
Works with the ID and name attributes of your html tags. Lets consider thefollowing example:
Valid locators for this snippet are : identifier=login identifier=username
submit
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
6/15
Id
The Id strategy looks for an element in the page having an id attributecorresponding to the specified pattern. will be matched by alocator like id=my_id or just my_idName
Like the Id strategy, but on the name attribute. You can also specify a filter torefine your locator. Currently, there are two filter types :Value : matches elements with a name attribute and where the value follows a
pattern. The following example illustrates the interest of filters :
Blueberry
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
7/15
Banana Strawberry
Link
This strategy is intended to select links only and selects the anchor elementcontaining the specified text: link=The text of the link
DOM
The DOM strategy works by locating elements that matches the javascript expressionrefering to an element in the DOM of the page. dom=document.div['pancakes'].button[0] document.div[0].button[2] dom=function foo() { return document.getElementById (pancakes); }; foo();
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
8/15
XPath
While DOM is the recognized standard for navigation through an HTMLelement tree, XPath is the standard navigation tool for XML; and an HTML
document is also an XML document (xHTML). XPath is used everywherewhere there is XML. Valid XPath locators can be:
xpath=//button[@value="Blueberry"]: matches the Blueberry button //div[@id="pancakes"]/button[0]: same thing
CSS
The CSS locator strategy uses CSS selectors to find the elements in thepage. Selenium supports CSS 1 through 3 selectors syntax excepted CSS3namespaces
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
9/15
Selenium RC
9
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
10/15
Selenium Challenges Web app latency can cause tests to fail waiting on
page events Tests tend to lock in web pages, slowing iterative
development
Selenium core is JavaScript based Not all browsers interpret the same way Can't perform cross-domain testing Testing secure connections is tricky, and often browser
specific
Execution is slow (compared to most unit tests) Formatting problems are untested
10
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
11/15
Handling Event LatencyExample: An event is triggered on the page when a user enters invalid data.
public static void waitForPageValidation(DefaultSelenium selenium,String id) throws InterruptedException {
for (int second = 0;; second++) {if (second >= 5) {
fail("timeout waiting for event);}try {
if (selenium.isVisible(id)) {break;
}}catch (Exception e) {}Thread.sleep(1000);
}}
06/21/11 11
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
12/15
Managing ChangeSeparate page content used in tests from actual test
logic. Most frequently used content:
Page titles
Field locators (ids, names)
12
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
13/15
Selenium13
Advantages Disadvantages
No Selenium RC installation No final version released(summer 2011)
Cross-domain testingcapabilities
Limited backwardscompatibility
Object-oriented API Smaller number of supportedbrowsers
Mobile browser testing
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
14/15
Speeding Up Selenium Avoid xpath; have id attributes for all tested fields
Reuse browser sessions (although this can causesubsequent tests to fail if the session fails)
Test local builds to reduce network latency
Avoid using multi-page test flows for atomic tests Use parameterized tests to test multiple browsers at
once
Parallelize tests to run multiple test classes at once
Use cloud-based testing services
14
-
8/12/2019 Web Testing With Selenium and JUnit by Quontra Solutions
15/15