ITAG – Selenium WebDriver
Phuong H H Nguyen
Principal QC Engineer
June, 2016
CSC Proprietary and Confidential
Course Objectives
• In this course, you will learn how to:
– Recognize object
– Create your tests
– Enhance your tests
– Develop user defined function in Visual Studio
– Run your tests
– Analyze test result
CSC Proprietary and Confidential June 2, 2016 2
Agenda
• Introduction
• Selenium WebDriver
– Introduction
– Selenium IDE
– Firebug and Firepath
– Cross-Browser Testing
– Locating Web Element
– Find multiple elements
– Click nth link with exact same label
– Attributes
– Execute script on another windows
– Click a button via JavaScript
– Set a value to a read-only or disable text field
CSC Proprietary and Confidential June 2, 2016 3
Agenda (cont.)
– Select List
– Navigation and Browser
– Assertion
– Pop-up
– Advanced User Interactions
– Page Object
• ITAG (Intelligent Test Automation Generator)
• User defined functions
• Practice
CSC Proprietary and Confidential June 2, 2016 4
Course Audience and Prerequisite
• Audience: Senior QCs, QCs
• Prerequisites:
– Over 1 year knowledge about .Net language
– Over 1 year knowledge about manual test
– Basic concept about test automation
CSC Proprietary and Confidential June 2, 2016 5
Assessment Disciplines
• Class Participation: 100%
• Practice: 75%
CSC Proprietary and Confidential June 2, 2016 6
Duration and Course Timetable
• Course Duration: 15 hrs
• Course Timetable:
– Day 1 (3 hrs):
• Introduction
• Selenium WebDriver
– Day 2 (3 hrs):
• ITAG
• User-defined function
– Day 3 (3 hrs):
• Q&A
• Practice
– Day 4 (3 hrs):
• Practice
– Day 5 (3 hrs):
• Final test
– Break 15 minutes for each session
CSC Proprietary and Confidential June 2, 2016 7
Course Administration
• In order to complete the course you must:
– Sign in the Class Attendance List
– Participate in the course
– Provide your feedback in the End of Course Evaluation
CSC Proprietary and Confidential June 2, 2016 8
Introduction
CSC Proprietary and Confidential
Introduction
• Test automation is the use of special software to control the
execution of tests and the comparison of actual value with
expected value.
• Test automation can automate some repetitive
• Benefits of automation testing:
– Reduction of repetitive work
– Greater consistency
CSC Proprietary and Confidential June 2, 2016 10
Introduction (cont.)
• Various framework/scripting techniques are generally used:
– Linear
– Modular
– Data driven
– Keyword driven
– Hybrid (two or more of the patterns above are used)
CSC Proprietary and Confidential June 2, 2016 11
Introduction (cont.)
• ITAG = Intelligent Test Automation Generator
• This is a hybrid automation framework.
• A framework can be a wrapper around some complex internal
architecture which makes it easier for the end user.
CSC Proprietary and Confidential June 2, 2016 12
Introduction (cont.)
• ITAG’s feature highlight:
– Test Suites/Test Cases are reusable.
– Easy to develop and maintain automation scripts.
– GUI is friendly and easy to use to run tests and view reports.
– Less effort for test cases/ test suites execution report.
– Drag and drop object from third party tool.
– Copy and paste test cases between other projects.
– Run list of test cases passed/failed/not run/all.
– Execute test suite/cases from Jenkin or Cruise Control .Net
CSC Proprietary and Confidential June 2, 2016 13
Selenium WebDriver
CSC Proprietary and Confidential
Introduction
• Selenium is a test tool for web applications. Selenium tests run
directly in a browser, just as real users do.
• There are included:
– Selenium IDE (*)
– Selenium Remote Control
– Selenium WebDriver (*)
– Selenium Grid
• Support language:
– Java
– .NET
– PHP
– Perl
– Python
– Ruby
CSC Proprietary and Confidential June 2, 2016 15
Introduction (cont.)
• Platforms supported by Selenium
Browser Selenium IDE Selenium Remote
Control
Firefox Record and playback Start browser, run tests
tests
IE not supported Start browser, run tests
Safari not supported Start browser, run tests
Chrome not supported Start browser, run tests
Edge not supported Start browser, run tests
CSC Proprietary and Confidential June 2, 2016 16
Introduction (cont.)
• Operating Systems
OS Selenium IDE Selenium Remote
Control
Windows Works in FireFox 2+ Start browser, run tests
OS X Works in FireFox 2+ Start browser, run tests
Linux Works in FireFox 2+ Start browser, run tests
Solaris Works in FireFox 2+ Start browser, run tests
Others Works in FireFox 2+ Partial support possible*
CSC Proprietary and Confidential June 2, 2016 17
Introduction (cont.)
• Programming Languages
Language Selenium IDE Selenium Remote
Control
C# Generate code Library ("driver") support
Java Generate code Library ("driver") support
Perl Generate code Library ("driver") support
PHP Generate code Library ("driver") support
Python Generate code Library ("driver") support
Ruby Generate code Library ("driver") support
CSC Proprietary and Confidential June 2, 2016 18
Selenium IDE
• An integrated development
environment for Selenium tests.
• Implemented as a Firefox
extension, and allows you to
record, edit, and debug tests.
CSC Proprietary and Confidential June 2, 2016 19
Selenium IDE (cont.)
• Features:
– Easy record and playback
– Intelligent field selection will use IDs, names, or XPath as
needed
– Auto complete for all common Selenium commands
– Walk through tests
– Debug and set breakpoints
– Save tests as HTML, Ruby scripts, or any other format
– Support for Selenium user-extensions.js file
– Option to automatically assert the title of every page
CSC Proprietary and Confidential June 2, 2016 20
Firebug and FirePath
• These are add-ins of Firefox browser using to get Xpath of
object
CSC Proprietary and Confidential June 2, 2016 21
Cross-Browser Testing
• The biggest advantage of Selenium over other web test frameworks.
• It supports all major web browsers:
– Firefox:
• IWebDriver driver = new FirefoxDriver();
– Chrome:
• IWebDriver driver = new ChromeDriver();
– Internet Explorer:
• IWebDriver driver = new InternetExplorerDriver();
– Edge:
• IWebDriver driver = new EdgeDriver();
CSC Proprietary and Confidential June 2, 2016 22
Locating Web Element
• There are eight locators in Selenium:
Locator Example
ID FindElement(By.Id("user"))
Name FindElement(By.Name("username"))
Link Text FindElement(By.LinkText("Login"))
Partial Link Text FindElement(By.PartialLinkText("Next"))
XPath FindElement(By.Xpath("//div[@id="login"]/input"))
Tag Name FindElement(By.TagName("body"))
Class Name FindElement(By.ClassName("table"))
CSS FindElement(By.CssSelector, "#login >
input[type="text"]"))
CSC Proprietary and Confidential June 2, 2016 23
Locating Web Element (cont.)
• Find element by ID:
– Using IDs is the easiest and the safest way to locate an element in a page.
– The IDs should be unique and identified in web controls.
• driver.FindElement(By.Id("submit_btn")).Click(); // Button
• driver.FindElement(By.Id("username")).SendKeys(“Phuong Nguyen"); // Textfield
• Find element by Name:
– The name attributes are used in form controls such as text fields and radio
buttons.
• driver.FindElement(By.Name("comment")).SendKeys(“Phuong comment");
• Find element by Link Text:
– For hyperlinks only, using a link’s text is probably the most direct way to
click a link, as it is what we see on the page
• driver.FindElement(By.LinkText("Cancel")).Click();
CSC Proprietary and Confidential June 2, 2016 24
Locating Web Element (cont.)
• Find element by Partial Link Text:
– Using in case the text is dynamically generated. In other words, the text on
one web page might be different on your next visit.
• driver.FindElement(By.PartialLinkText("ance")).Click();
• Find element by XPath:
– Xpath is a query language for selecting nodes from an XML document.
• driver.FindElement(By.XPath("//*[@id='div2']/input[@type='checkbox']")).Click();
• Find element by Tag Name:
– Many elements share the same tag names on a web page. We normally
don’t use the tag_name locator
• driver.FindElement(By.TagName("body")).Text;
CSC Proprietary and Confidential June 2, 2016 25
Locating Web Element (cont.)
• Find element by Class:
– The class attribute of an HTML element is used for styling. It can also be
used for identifying elements.
• driver.FindElement(By.ClassName("btn-primary")).Click(); // Submit button
• Find element by CSS Selector:
– You can also use CSS Path to locate a web element.
• driver.FindElement(By.CssSelector("#div2 > input[type='checkbox']")).Click();
CSC Proprietary and Confidential June 2, 2016 26
Find multiple elements
• Returns a list of matched elements.
• The test statements below will find two check boxes under div#container
and click the second one
– ReadOnlyCollection<IWebElement> checkbox_elems =
driver.FindElements(By.XPath("//div[@id='container']//input[@type='checkbox']"));
– System.Console.WriteLine(checkbox_elems); // => 2
– checkbox_elems[1].Click();
CSC Proprietary and Confidential June 2, 2016 27
Click nth link with exact same label
• To click the second one, use the following code.
– Assert.IsTrue(driver.FindElements(By.LinkText("Show Answer")).Count == 2);
– ReadOnlyCollection<IWebElement> links =
driver.FindElements(By.LinkText("Show Answer"));
– links[1].Click(); // click the second one
– Assert.IsTrue(driver.PageSource.Contains("second link page")); // second link
CSC Proprietary and Confidential June 2, 2016 28
Attributes
• Get value of web element.
– Assert.AreEqual("recommend_selenium_link",
driver.FindElement(By.LinkText("Recommend Selenium")).GetAttribute("id"));
– Assert.AreEqual("Recommend Selenium",
driver.FindElement(By.Id("recommend_selenium_link")).Text);
CSC Proprietary and Confidential June 2, 2016 29
Execute script on another windows
• Click on the link will open the linked URL in a new browser window or tab.
– driver.FindElement(By.LinkText("Open new window")).Click();
– driver.SwitchTo().Window(driver.WindowHandles[1]); # change window
– driver.FindElement(By.Name("name")).SendKeys("on new window");
– driver.Close();
– driver.SwitchTo().Window(driver.WindowHandles[0]); // back
– driver.FindElement(By.LinkText("Recommend Selenium")).Click();
CSC Proprietary and Confidential June 2, 2016 30
Click a button via JavaScript
• Sometimes we didn’t click a button reliably on Firefox, but this JavaScript
method worked well.
– IWebElement aBtn = driver.FindElement(By.Id("choose_selenium_btn"));
– ((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].click();", aBtn);
CSC Proprietary and Confidential June 2, 2016 31
Set a value to a read-only or disable text field
• Read-only and disabled text fields are not editable and are shown
differently in the browser (typically grayed out).
– ((IJavaScriptExecutor)driver).ExecuteScript("$('#readonly_text').val('bypass');");
Assert.AreEqual("bypass",
driver.FindElement(By.Id("readonly_text")).GetAttribute("value"));
– ((IJavaScriptExecutor)driver).ExecuteScript("$('#disabled_text').val('anyuse');");
CSC Proprietary and Confidential June 2, 2016 32
Select List
• A select list is also known as a drop-down list or combo box.
– IWebElement elem = driver.FindElement(By.Name("car_make"));
– SelectElement select = new SelectElement(elem);
– select.SelectByText("Volvo (Sweden)");
• A complex way to select an option in a select list.
– IWebElement selectElem = driver.FindElement(By.Id("car_make_select"));
– foreach (IWebElement option in electElem.FindElements(By.TagName("option")))
{
if (option.Text.Equals("Volvo (Sweden)"))
{ option.Click(); }
}
CSC Proprietary and Confidential June 2, 2016 33
Select List (cont.)
• Assert the value of a select list.
– IWebElement elem = driver.FindElement(By.Id("car_make_select"));
– SelectElement select = new SelectElement(elem);
– select.SelectByText("Volvo (Sweden)");
– Assert.AreEqual("volvo", select.SelectedOption.GetAttribute("value"));
CSC Proprietary and Confidential June 2, 2016 34
Navigation and Browser
• Go to a URL
– driver.Navigate().GoToUrl("https://google.com");
• Some other actions
– driver.Navigate().Back();
– driver.Navigate().Refresh();
– driver.Navigate().Forward();
– driver.Manage().Window.Maximize();
• Remember current web page URL and return to it later
– url = driver.Url;
–…
– driver.Navigate().GotoUrl(url);
CSC Proprietary and Confidential June 2, 2016 35
Assertion
• Assert page title
– Assert.AreEqual(“ITAG training", driver.Title);
• Assert checkbox selected
– Assert.IsTrue(driver.FindElement(By.Name("is_vip")).Selected);
• Assert button enabled
– Assert.IsTrue(driver.FindElement(By.Id("continue_btn")).Enabled);
• Assert label text
– Assert.AreEqual("First Label", driver.FindElement(By.Id("label_1")).Text);
• Assert image present
– Assert.IsTrue(driver.FindElement(By.Id("next_go")).Displayed);
CSC Proprietary and Confidential June 2, 2016 36
Pop-up
• File upload
• HTML source
– <input type="file" name="document[file]" id="files" size="60"/>
• Test script
– String filePath = @"c:\work\testdata\users.csv";
– driver.FindElement(By.Name("document[file]")).SendKeys(filePath);
CSC Proprietary and Confidential June 2, 2016 37
Pop-up (cont.)
• JavaScript pop-ups
– IAlert a = driver.SwitchTo().Alert();
– a.Accept();
CSC Proprietary and Confidential June 2, 2016 38
Advanced User Interactions
• Double click a control
– IWebElement elem = driver.FindElement(By.Id("pass"));
– Actions builder = new Actions(driver);
– builder.DoubleClick(elem).Perform();
• Click and hold: select multiple items
– ReadOnlyCollection<IWebElement> listItems =
driver.FindElements(By.XPath("//ol[@id='selectable']/li"));
– Actions builder = new Actions(driver);
– builder.ClickAndHold(listItems[1]).ClickAndHold(listItems[3]).Click().Perform();
CSC Proprietary and Confidential June 2, 2016 39
Advanced User Interactions (cont.)
• Context click: right click a control
– IWebElement elem = driver.FindElement(By.Id("pass"));
– Actions builder = new Actions(driver);
– builder.ContextClick(elem)
• .SendKeys(Keys.Down)
• .SendKeys(Keys.Down)
• .SendKeys(Keys.Down)
• .SendKeys(Keys.Down)
• .SendKeys(Keys.Return)
• .Perform();
CSC Proprietary and Confidential June 2, 2016 40
Page Object
• A class or object that represents a web page in your application.
• Hides the technical details about how you interact with a web page behind
a more readable and business-focused facade.
CSC Proprietary and Confidential June 2, 2016 41
ITAG – Intelligent Test Automation
Generator
CSC Proprietary and Confidential
Agenda
• ITAG Model
• System requirements
• Folder structure
• Test Case
• Test Suite
• Report
CSC Proprietary and Confidential June 2, 2016 43
ITAG Model
Automation
Test Enter data for Test Suite
Engineer and Test Case
Common Libraries
Capture object Selenium Web Driver
Function to call test suite to execute
Log File
(Log.txt)
Report File
(Test_Report.xls)
CSC Proprietary and Confidential June 2, 2016 44
System requirements
System Requirements:
- Intel Core i
Software Requirements: - 4GB RAM
- Windows OS - IE 5.5 to 11.0
-.NET Framework 4.6 - FireFox 2 to 45
- Crystal Report Runtime - Chrome 2 to 46
-ITAG - 10GB disk free space
CSC Proprietary and Confidential June 2, 2016 45
Folder Structure
• ITAG
– Data: when running ITAG, data files will be generate to this folder
– Help: contains help files
– ThirdParty: contains the library file
– Tools: contains the executable file to launch ITAG GUI
CSC Proprietary and Confidential June 2, 2016 46
Test Case
• Test Case is a set of instructions that will be performed on the system
under test to test that the system functions as expected.
CSC Proprietary and Confidential June 2, 2016 47
Test Case (cont.)
• The template has 6 columns:
– Status: can be 1 in 3 values below
• Passed/Failed: will be set automatically when test case execution
is completed.
• Locked: ITAG will not run rows marked as “Locked”
– Keyword: can be 1 in 4 values below
• Action
• Function
• Module
• Comment: description for steps in test case. ITAG will skip rows
marked “Comment”
– 2 columns Object and Method function differently according to the
keyword selected
CSC Proprietary and Confidential June 2, 2016 48
Test Case (cont.)
– If keyword Action is selected
• Key in object or select object list from Object column.
• Key in Method name or select method from Method list. Method list in Method
column will be filtered and shown only available methods for the chosen
object.
• Step Parameters area: key in value or environment variable (wrapped by [ ])
CSC Proprietary and Confidential June 2, 2016 49
Test Case (cont.)
– If keyword Function is selected
• Key in function name or select function from function list in Object column.
• Method column: blank
• Step Parameters area: if function does not have any parameter, leave it blank.
Otherwise, key in value or environment variable
CSC Proprietary and Confidential June 2, 2016 50
Test Case (cont.)
– If keyword Module is selected
• Key in module name or select module from module list in Object column.
• Method column: blank
• Step Parameters area: if module does not have any parameter, leave it blank.
Otherwise, key in value or environment variable
CSC Proprietary and Confidential June 2, 2016 51
Test Suite
• Test Suite is a collection of test cases that are intended to be used
to test a software program to show that it has some specified set of
behaviors.
CSC Proprietary and Confidential June 2, 2016 52
Test Suite (cont.)
• Test Suite template has 3 columns
– Status: can be 1 in 3 values below
• Passed/Failed: will be set automatically when test case execution is
completed
• Locked: ITAG will not run test cases marked as “Locked”
– Case Name: select test case by click Add button on the toolbar
– Data Record Name: execute test case with data record
CSC Proprietary and Confidential June 2, 2016 53
Module
• Module template consists of repetitive actions used in the test case.
CSC Proprietary and Confidential June 2, 2016 54
Module (cont.)
• Module template has 4 columns
– Status: can be 1 in 3 values below
• Passed/Failed: will be set automatically when test case execution is completed
• Locked: ITAG will not run rows marked as “Locked”
– Keyword:
• Action
• Function
• Comment: description for the module. ITAG will skip rows marked as “Comment”
– Object: depends on Keyword column
– Method:
• Contains available methods for the chosen object if keyword Action is selected
• Contains function list if keyword Function is selected
@Step Parameters area: specifies parameters or values needed for the current
step
@Module Variables area: contains variables of module
CSC Proprietary and Confidential June 2, 2016 55
Report
– This is a general report
• Green color: passed case
• Red color: failed case
• Gray color: locked case
– Execute duration, case name passed/failed/locked,…
User defined functions
CSC Proprietary and Confidential June 2, 2016 56
Report (cont.)
– This is a detail report
• Red color: failed step
User defined functions
CSC Proprietary and Confidential June 2, 2016 57
Report (cont.)
– Log file
CSC Proprietary and Confidential June 2, 2016 58
ITAG GUI
CSC Proprietary and Confidential
ITAG – Main Screen
CSC Proprietary and Confidential June 2, 2016 60
New\Open project
• Create new project by click New on the toolbar or click File\New
menu
• Open project by click Open on the toolbar or click File\Open menu
CSC Proprietary and Confidential June 2, 2016 61
Setting
• Select File\Setting menu
CSC Proprietary and Confidential June 2, 2016 62
Project Information
• Select File\Project Information menu
• Enter data for Test Product, Version and Build Number
CSC Proprietary and Confidential June 2, 2016 63
Import
• Select Tools\Import menu
• Import Test Case\Module\Project Variable from project A to
project B
CSC Proprietary and Confidential June 2, 2016 64
Method Management
• Select Tools\Method Management menu
• Add or Delete user method, enter parameters for method.
Therefore, functions will happen in the dropdown on the Test
Case template
CSC Proprietary and Confidential June 2, 2016 65
Object Management
• Select Tools\Object Management menu
CSC Proprietary and Confidential June 2, 2016 66
User defined functions
CSC Proprietary and Confidential
Function Template
• Open SeleniumUserDefined.sln from Installation Folder \ ITAG \
ITAG_PROJECT \ ThirdParty \ Selenium WebDriver \
SeleniumUserDefined \ SeleniumUserDefined
• You will write your script below ‘Write your code here
CSC Proprietary and Confidential June 2, 2016 68
Add user-defined functions to ITAG
• Select Tools\Method Management menu
• Add or Delete user method, enter parameters for method.
Therefore, functions will happen in the dropdown on the Test
Case template
CSC Proprietary and Confidential June 2, 2016 69
Practice
• Define object
• Create test case
• Create module
• Create test suite
• Run test script
• View report
CSC Proprietary and Confidential June 2, 2016 70
Q&A
CSC Proprietary and Confidential
Thank You.
CSC Proprietary and Confidential
Revision History
Date Version Description Updated by Reviewed and Approved By
Jun 2016 1.0 ITAG – Selenium WebDriver Phuong Nguyen Mai Nguyen, Quang To
CSC Proprietary and Confidential June 2, 2016 73
CSC Proprietary and Confidential June 2, 2016 74