MindMap Gallery Automation Testing
Automation testing is a Software testing technique to test and compare the actual outcome with the expected outcome.
Edited at 2020-10-10 07:17:11Automation Testing
Java
Starting with Java language and OOP concept
Overview abount Java
http://www.tutorialspoint.com/java/index.htm
http://android.vn/threads/mien-phi-khoa-hoc-lap-trinh-java.25642/
Installing
\\192.168.176.122\apps\Developer\Development\Eclipse
c:\Program Files\java\jdk directory:
Right-click on 'My Computer' and select 'Properties'.
Click on the 'Environment variables' button under the 'Advanced' tab.
'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin
Basic Syntax
convention
ClassName.java
ClassName
class MyFirstClass
methodName
public void myMethodName()
Start a program in public static void main(String args[])
Objects and Classes
Contructor
Variable Types
Basic Operators
Java Strings
Khởi tạo
String str1 = new String();str1 = "Chuỗi";
String str1 = new String ("Chuối");
String str1 = "Chuoi";
Java Array
Java methods
Create a simple project
How to create a package
How to create a class
How to implement an object
Exception concept
Practice
Create a java project for calculating 2 integer variables
Create a package, named: pack
Create a class that provide 4 methods: minus, plus, multi, divide. 2 parameters will be passed from contructor of class. With each method, it will pass parameters and calculate result, then print out console
Create a package, named: test
Create a main class to test.
From Me
Overvỉew
Java is
Object Oriented
Class
class
interface
abstract class
Constructor
Hàm khởi tạo các thuộc tính
Selenium
Plan
Selenium overview
Introduction
Hướng dẫn bằng Tiếng Việt
http://www.tutorialspoint.com/selenium/selenium_webdriver.htm
http://www.guru99.com/selenium-tutorial.html
Ghi lại hành động trên web và thưc thi kịch bản
Working With Selenium IDE
Installing
Firefox
www.seleniumhq.org/download/
cài Add on Selenum IDE
Chọn đúng ver Firefox và Selenium
Selenium IDE Basics
Recording a Test
https://www.youtube.com/watch?v=PpeQB0T89uY&list=PLpTCO0Fa9GR16Y11kfMynOl80YHVrkSrS&index=3
Create Scenario
open URL
Record the steps
verify result
Perform on Browser
Running the Test
Run on Selenium IDE of browser
verifyTest Message
Selenese
Looking at Commands
waitForElement
Chờ element hiển thị
deleteAllVariableCookie
Xóa biến cookie (sản phẩm giỏ hàng)
Creating Commands
insert comment for steps
Điền tạm vào field sau đó sưa mục values
Diểm đừng add breakpoint
Pause breakpoint at each scenario
Set Start Point
chạy thẳng từ point đc set
step
chạy từng step
Actions - directly interacts with page elements
action
click
action+AndWait
acction dùng khi page đc tải lại từ server
waitFor...
dùng khi biến đổi về giao diện với Javascipt
ListBox ComboBox và CheckBox
select
multiple select
addSelection
removếlection
checkbox
click
action check <=> uncheck
check
always check
verifyCheck
Subtopic 1
uncheck
always uncheck
verifyNotCheck
Accessors - "reads" an element property and stores it in a variable
khai báo biến
store
echo - kiểm tra kết quả trả ra ntn
target =${biến}
target
giá trị
values
x
storeText
khai baó text nằm giữa 2 thẻ html
//p
//div
storeValue
khai báo giá trị của thẻ có thuộc tính Value
//input
storeAttribute
khai báo cho các thuộc tính trong thẻ HTML
//div@align
//input@value
~ storeValue
Assertions - compares an actual value with an expected one
Verifications
target =${biến}
verifyText
dùng cho đối tượng có chứa Text
verifyValue
dùng cho thuộc tính value của thẻ HTML đối tươngj chứa Values
verifyAttribute
dùng cho các thuộc tính của thẻ HTML
verifyElementPresent
kiểm tra xem tồn tại trong source code hay không
verifyVisible
check element ẩn hiện khi expand
addon screenshot on failed
Using Assert and Verify
verifyTest Message
verify failed thì vẫn tiếp tục những cái dưới
dùng để kiểm tra nhưng thứ ko ảnh hưởng đến bước theo
asset gặp failed dừng lại luôn
output liên quan đến logic cho những bước dưới
Creating Test Suites
Creat test case
save as testsuit
save as html
Exporting
File/Export Testcase As...
Summary
Practice
Practice with Selenium IDE
http://newtours.demoaut.com/
Go to url
Verify the title of page
Verify the element present
Verify link texts are correct
Verify text is correct
Input user name
Input password
Click to sign in
Verify the title of page appeared
Assert the sign-on link present
Review the exercise of trainee
SE_Prac01.html
Working with Selenium WebDriver
Introduction
http://www.vntesters.com/gioi-thieu-selenium-webdriver/
What is WebDriver?
WebDriver is a web automation framework that allows you to execute your tests against different browsers,
cho phép chúng ta sử dụng các ngôn ngữ lập trình để thiết kế test case.
Java
.Net
PHP
Python
Perl
Ruby
ưu điểm
FASTER than Selenium RC because of its simpler architecture.
làm việc ở mức OS
DIRECT talks to the browser while Selenium RC needs RC Server
API is CONCISE than Selenium RC's
xác định đôi tượng trc rồi mới đến hành động
Support HtmlUnit
nhanh vì không lòa element
Limitations
Cannot readily support new browsers, but Selenium RC can.
No a built-in command for automatic generation of test results.
Setting up Java, Eclipse, Junit
Eclipse
Setting up WebDriver
Install Java
Install Eclipse IDE
Download the Selenium Java Client Driver
Project_Properties/Java Build Path_Libraries/Add External JARs_Add JAR files in/out the "libs" folder
Other Browsers
Each other browser has its own driver server
A Simple Script
Importing Packages
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
Instantiation of objects/variables
WebDriver driver = new FirefoxDriver();
String baseUrl = "http://newtours.demoaut.com";
String expectedTitle = "Welcome: Mercury Tours";
String actualTitle = "";
launch Firefox and direct it to the Base URL
driver.get(baseUrl);
get the actual value of the title
actualTitle = driver.getTitle();
compare the actual title of the page witht the expected one and print * the result as "Passed" or "Failed"
if (actualTitle.contentEquals(expectedTitle)){
System.out.println("Test Passed!");
} else {
System.out.println("Test Failed");
}
close Firefox
driver.close();
exit the program explicitly
System.exit(0);
common command
Get Commands
get()
getTitle()
getPageSource()
getCurrentUrl()
getText()
Navigate commands
navigate().to()
navigate().refresh()
navigate().back()
navigate().forward()
Closing and Quitting Browser Windows
close()
quit()
Switching Between Frames
switchTo().frame("classFrame")
Finding Elements
Web Element Identification Techniques
Locate Web Elements
By
ID
ID attribute of a HTML Tag
Target: id=id_of_the_element
driver.findElement(By.id(<element ID>))
Name
ID attribute of a HTML Tag
Target: name=name_of_the_element
value=value_of_filter
driver.findElement(By.name(<element name>))
Link Text
Target: link=link_text
ex: link=ABOUT
driver.findElement(By.linkText(<linktext>))
driver.findElement(By.partialLinkText(<linktext>))
CSS Selector
Tag and ID
css=tag#id
css=input#email
Tag & Class
css=tag.class
css=div.wrapper
only first element in source code is recognized
Tag & Attribute
css=tag[attribute=value]
css=input[name=lastName]
only first element in source code is recognized
Tag, Class & Attribute
css=tag.class[attribute=value]
css=input.inputtext[tabindex=2]
Inner Text
css=tag:contains("inner_text")
css=font:contains("Passwords:")
inditify label on webpage
driver.findElement(By.cssSelector(<css selector>))
driver.findElement(By.tagName(<htmltagname>))
driver.findElement(By.className(<element class>))
XPath
driver.findElement(By.xpath(<xpath>))
Using Firebug or FirePAth
//html/body/div/div[2]/div[2]/div[1]/form/div[1
How To Locate Dynamic Elements By Xpath
tìm vị trí tương đương
xpath=//input[@id='f1_google']
find a paragraph element
xpath=//p[contains(text(),'aaaa']
xpath=//p[starts-with(text(),'aaa')]
xpath=//p[ends-with(text(),'aaa')]
DOM (Document Object Model)
getElementById
Target: document.getElementById("id_of_the_elements")
document.getElementById("input")
getElementsByName
Target: document.getElementByName("name")[index]
document.getElementByName("servClass")[1]
dom:name
document.forms["name_of_the_form"].elements["name_of_the_element"]
document.forms["home"].elements["userName"]
dom:index
document.forms[index_of_form].elements[index_of_element]
Practice
Practice with locating web elements
Review the exercise of trainee
Page Elements
A More Complex Script
Assert and Verify
Waits
Implicit wait
Explicit Waits
Import these two packages
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
Declare a WebDriverWait variable
myWaitVar.until(ExpectedConditions.visibilityOfElementLocated(By.id("username")));
driver.findElement(By.id("username")).sendKeys("tutorial");
How to work with Excel file (reading and writing)
reading form file
import POI
create workbook
create sheet
cell
write to file
Practice
Practice with Selenium WebDriver
Write a test script
Write a script using reading/writing from Excel file
Review the exercise of trainee
Hybrid framework (basic)
Introduction
Setting up Civica framework
How to create a test case
Run the test suite
Reporting
Practice with Hybrid framework (basic)
Review the exercise of trainee
Hybrid framework (Advanced)
How to create new keyword
How to run with multibrowser
Practice with Hybrid framework (advanced)
Review the exercise of trainee
Practice
Go to url: http://newtours.demoaut.com/
Verify the title of page
Verify the element present