Automated test Selenium Webdriver (JAVA) Learning Summary

Source: Internet
Author: User
Tags xpath

Summary of--selenium Learning in automated testing

First, the concept and significance of automated testing:

1. What is automated testing:

Generally refers to the automation of software testing, software testing is to run the system or application under the preset conditions, evaluate the results of the operation, pre-conditions should include normal conditions and abnormal conditions.

2. Meaning:

Make testing more efficient, take advantage of more free time, and reduce human resources.

Second, selenium tools

I'm using the Java language, so the next examples and methods are Java-based.

1. Environment configuration

(1) The configuration of the JDK;

I'm using a 1.7 jdk, which is all the same, create a new java_home and copy the path of the JDK you've installed.

In creating a new classpath, the variable value is filled in:.; %java_home%\lib\dt.jar;%java_home%\lib\tools.jar;

Then find path, do not create a new, in the variable Value added:%java_home%\bin;%java_home%\jre\bin;

(like if there is content in the variable value, precede it with ";" to separate it)

Finally verify that the JDK is installed correctly, enter win+r, open cmd, enter java-version, Get the installation success:

(2) Eclipse or MyEclipse tools;

Download three files: Selenium-java-2.48.2.jar

Selenium-java-2.48.2-srcs.jar

Selenium-server-standalone-2.46.0.jar

These three files are to be placed in the Lib of the project.

2. Browser:

Support ie,firefox,Google.

Second, the small test skill

1. Open the browser:

Firefox browser (i use firefox, the following example is also the use of Firefox, error less, easy to use)

A. If your Firefox browser is installed by default:

B. to customize the installation, you need to specify the path:

Google Browser (need to download a google driverserver)

IE Browser (need to download an ie driverserver)

2. Open the URL (the context of WD is my own name and can change it myself)

3. The complete example:

Third, the more specific use

1. Find page elements

query element by ID,name,text

Wd.findelement (By.id (""));

Wd.findelement (By.name (""));

Wd.findelement (By.linktext (""));

There are generally no specific requirements of the page element many do not have ID and name This time we are going to use a powerful query statement Byxpath

For example, we want to locate the image, that is, the icon, we use XPath to locate:

Wd.findelement (By.xpath ("//img[contains (@src, ' themes/auman/images/logo.png ')"));

2. Page operation

Analog mouse click:

Wd.click ();

To close a webpage:

Wd.close();

Empty the contents of the input box:

Wd.clear();

Enter the contents in the Input box:

Wd.sendkeys("");

Get the contents of the input box:

Wd.gettext();

Select the element in the drop-down box:

Select select = New Select (Wd.findelement (By.id ("select"));

Switch to a frame:

Driver.switchto (). FRAME ("");

Switch from one frame to another frame:

Driver.switchto (). FRAME ("");

Switch to a window:

Driver.switchto (). Window ("Windowname");

Returns the parent iframe: ( This statement is usually written before the jump frame )

Driver.switchto (). Defaultcontent ();

Refresh page:

Wd.navigate (). Refresh ();

Page forward back:

Wd.navigate (). Forward ();

Wd.navigate (). back ();

Hover Mouse:

Hover the mouse may you think why you need this operation, I have been the example of the case, like this column under each model has multiple elements, want to find elements, this time need to simulate the mouse hover so that the hidden js Let us can find:

Before hover:

After hover:

Instance:

4. Set the wait Time:

Force stop: ( 1son behalf of)

Thread.Sleep(+);

Global Wait: (unit:s)

Wd.manage (). Timeouts (). implicitlywait (Timeunit.seconds);

5. Get the URLof the current page:

Wd.getcurrenturl ();

6. Determine if the page jumps correctly

Assertequals ("http://mall.aumantruck.com/goods_list/2915/66/add_time/desc/page-1.html", Wd.getcurrenturl ());

There are a variety of verification methods, but if you can prove the characteristics of the line, to avoid errors! You can verify that the URL is what you expect, or that some of the page elements are expected.

Automated test Selenium Webdriver (JAVA) Learning Summary

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.