1, Web automated testing Introduction
automation infrastructure: automation use cases written, Selenium advantages and principles of automation environment to build
Selenium foundation: common 8 big element positioning (form), the common element processing, drop-down box element processing, different window switch elements advanced, elements waiting for
demand to frame
requirements analysis - use Case design - basic scripts - logon / Shopping reconstruction script - read the package configuration file - data-driven - to listen Screenshot - Code stratification - framework to achieve - the log collection - report generation - continuous integration
2, the difference between functional testing and automated testing
What are the functional test:
to meet the needs looking BUG
what is automated testing:
writing code, scripts allow the program to run automatically; reduce labor input, improve work efficiency; regression testing; system monitoring
3, automated testing process
common testing process
analysis and testing requirements - options - to develop test plans - environment - ready to use case - coding - analysis
4, automate manual test cases and test the difference between
hand-use Case
ID module prerequisite steps expected actual results to
automated test case
ID module premise conditions steps expected results Actual results
but the accuracy is not the same two step
5, why do automation?
Reduce labor costs
to complete a lot of repetitive work
to improve the efficiency of the test
to ensure the consistency of the work, increase confidence
You can not complete the manual work done by
6, if suitable for automation?
Time
personnel
system
leading
7, do automation under what circumstances?
unit test? Integration Testing? Interface Test? UI testing?
8, what kind of projects needs to be done automated testing?
The demand for change slow
cycle length
scripts can be reused
9, Selenium Introduction
Selenium
10, Selenium advantage and works
Selenium advantages: Open Source (free), multi-browser, multi-platform, complete API, run inside the browser
works of Selenium
first, it is the client that is the script, the script will start beginning to generate a driver, then starts to generate a Server that browser, our browser bound to a port, the script this time we can send some session is send some requests to the Server, and then let him do some things, to send the request to the browser, the browser will automatically parse the request client to send over, will conduct the appropriate action after parsing finished, after the execution will be based on the implementation of As a result, this thing back to our script, if successful response success, failure would have failed, returned to the client, you can see the results of a
11 common browser start
Firefox browsers (Firefox in there comes a drive webdriver)
Import org.openqa.selenium *.;
org.openqa.selenium.firefox * Import;
WebDriver Driver;
System.setProperty ( "webdriver.firefox.bin", "detailed the path of Firefox"); // browser does not need to install this line in the default path
driver = new FirefoxDriver (); // instantiate an object Firefox
String testUrl = "http://www.baidu.com";
driver.ger (testUrl);
driver.quit ();
Chrome promoter (Chrome not webdriver drive comes)
org.openqa.selenium * Import;.
Import org.openqa.selenium.chrome *;
WebDriver Driver;
System.setProperty ( "webdriver.chrome.driver", "Chrome detailed path"); // browser is not installed by default this requires the path line when
driver = new ChromeDriver (); // instantiate an object
String testUrl = "http://www.baidu.com";
driver.ger (testURL);
driver.quit ();
IE promoter
Import org.openqa.selenium *;.
Import org.openqa.selenium.InternetExplorerDriver *;
the WebDriver Driver;
System.setProperty ( "webdriver.ie.driver", "IE, detailed paths"); // browser installed in the default path is not needed for this line
driver = new InternetExplorerDriver (); // instantiate an object
String testUrl = "http://www.baidu.com";
driver.ger (testUrl);
Driver. quit ();
12 is, the positioning element
10 is positioned method
By.id By.name By.tagName By.className By.linkText By.partialLinkText By.xpath By.cssSelector positioning table level location
driver.findElement (By.id ( "kw . ")) sendKeys (" the Selenium ");
driver.findElement (By.name ("wd")).sendKeys("selenium");
. driver.findElement (By.classname ( "s_ipt")) sendKeys ( "Selenium");
. driver.findElement (By.xpath ( ".//*[@ ID = 'kW']")) sendKeys ( "Selenium ");
driver.findElement (By.cssSelector (" # kw ").) sendKeys (" the Selenium ");
there are many elements of time it will take the first
driver.findElement (By.linkText (" News ")) .click ();
driver.findElement (By.partialLinkText ( "new")) the Click ();.
findElement is a method of locating a single element, positioning a set of methods we need findElements, findElements is to get an array of
table positioning :
String = STR "second row, first column";
WebElement = driver.findElement the Table (By.tagname ( "Table"))
List <WebElement> = Table.findElements rows (By.tagName ( "TR"));
for (WebElement row:rows){
List<WebElement> tds= row.findElements(By.tagName("td"));
for (TD WebElement: TDS) {
String value = td.getText ();
IF (value.equals (STR)) {
System.out.pringln (value + "\ n-");
} the else {
System.out.pringln ( " error "+" \ n-");
}
}
}
common automation framework: keyword driven, data-driven, the hybrid drive
13, common API
to open the URL manner
Driver.get ()
Driver.navigate.to ()
operator browser API
driver .navigate (). refresh () // refresh the page
Driver.navigate (). forward () // forward
Driver.navigate (). back () // Back
Driver.getTitle ()
Driver.getCurrentUrl () // get the current URL
Driver.manage (). Window (). Maximize () // window is maximized
Driver.quite () // browser is closed, not fully closed, the process still the
Driver.close () // Close the browser
scroll bar operation
operation browser cookie
input box operation API
SendKeys ()
the Clear ()
getText ()
the click ()
check box processing
radio buttons
box
drop-down box
special window operations
Iframe window handle
pop processing
JS operations
Js positioning
Js click the element
page the processing element
waits for loading
acquires the value of the element according to the attributes
acquired object css attributes
get the object status
page is displayed isdisplay ()
element exists find_element
Whether the element is selected isSelected ()
is in the ashing state isEnabled ()
special operations explain
when an error screen shots saved
simulate a right mouse
hovers
upload
date control handles the
browser scroll bar operation
14, the common element processing
1. Enter the box
sendKeys
the Clear
getAttribute
2 single box
the Click
clear // clear
isSelected // check whether
3. checkbox
the Click
clear
isSelected
isEnabled // determines whether the enable state
4. button
the Click
isEnabled // determines whether the enable state
5. form
Submit
6. The upload
sendKeys
15, drop-down box - an element selected
drop-down box positioning Select list = new Select (locator) ;
drop-down box to select the corresponding operation Text Value Index elements
not corresponding to the selected elements deselectAll deselectByvalue deselectByVisibleText
get the value getAllSelectdOptions selection item () getFirstSelectedOption () .getText
16, the operating element advanced
left-click:
the Actions the Actions Action new new = (Driver);
Action.click () Perform ();.
right click:
the Actions the Actions Action new new = (Driver);
Action.contextClick (). Perform ();
mouse double:
the Actions the Actions Action new new = (Driver);
. Action.doubleClick () Perform ();
hover:
Action new new = the Actions the Actions (Driver);
Action.moveToElement () Perform ();.
. 17, a special window switching
Iframe process
SWITCHTO ()
pop process
SWITCHTO ()
getWindowHandles ()
18,3 classified by kinds waiting
forced to wait Thread.sleep ()
If you call to wait forever
show waiting
new new WebDriverWait (Driver, 15) .until (
ExpectedConditions.presenceOfElementLocated (By.cssSelector ( "CSS Locator"))
);
if the element found within the specified time will continue, if not found it being given
implicit wait
Driver.manager () timeouts.implicitlyWait (10, TimeUnit.SECONDS );.
global, every 10 seconds or less as the number of seconds to find, it is found the next step
19, automated testing
automation purposes:
reduce labor costs
To complete a lot of duplication of work
to improve the efficiency of the test
to ensure the consistency of the work
completed by hand can not complete the work
20, the use of Maven
Maven Introduction
Maven is a project management tool that provides a complete set of building lifecycle framework for
the role of Maven
build, document generation, report, dependence
21, reconstruction
reconstruction is by adjusting the code, but does not alter the functional characteristics of the program, to improve software quality, performance, architecture and design patterns to make the program more reasonable, easier to understand and improve software scalability and maintainability.
---------------- Disclaimer: This article is the original article CSDN bloggers "Sunshicy", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. . Original link: https: //blog.csdn.net/sunshicy/article/details/80305750