Selenium+webdriver Environment Building and Learning Basics (Java environment)

Source: Internet
Author: User
Tags xpath testng

Since the launch of the Selenium+webdriver, the learning UI level of automated testing has a lot of convenience, learning curve and difficulty are reduced, at least the introduction is relatively simple, basically understand the point of Java development, the HTML structure to understand the people should be relatively easy to get started.

Talk less, start now. Whether it is learning or practical, the first step must be to take the environment first.

What the environment needs to use is as follows:

1, development tools, such as Eclipse, MyEclipse and so on, the installation process and configuration of self-search;

2, need to introduce the main package: Selenium-java-2.42.2.jar

3, test drive to use, such as JUnit or TESTNG package, the following many places do not have special instructions, the use of the method is testng way to test drive;

4, browser tools, mainly use Firefox browser, must be installed on the firebugs and check XPath these two components or tools;

In fact, a test development environment is ready.

After that, give an example of the approximate use of a business system login box in a native browser test as an example:

First, to initialize a browser driver, this part can be placed in the @beforclass code.

Private Webdriver Webdriver; @BeforClass public void SetUp () {webdriver = new firefoxdriver ();//Initialize a Firefox browser webdriver.manage (). Window ( ). Maximize (); Maximize browser webdriver.get (URL); The URL for the test login box address} @Test public void Testlogin () {webdriver.findelement (By.xpath (XPath)). SendKeys (Keystosend); XPath locates an input box and then enters the contents of a string keystosend. Webelement button=webdriver.findelement (By.xpath ("//input[@type = ' button ')");//Gets the location of the login button Button.Click (); Click the login button and submit}

Such a testng test case is written, and after that, the project can be optimized by adding data drivers, encapsulating new methods, and so on. In the follow-up, this will continue to be said.

The next step is to talk about the XPath language, which is more important than using the tool.
In the previous "//input[@type = ' button ']", this paragraph is using the XPath language to locate. That is, the element that is the type of the button is found in all input. Therefore, it must be guaranteed that the property is unique on the current page. For front-end frames such as ExtJS, try not to use IDs to locate them.


This article is from the "testing of the Rhythm" blog, please be sure to keep this source http://fociceo.blog.51cto.com/2480/1612318

Selenium+webdriver Environment Building and Learning Basics (Java environment)

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.