1. Create two inheritance classes under the same package: 2. The code implementation in the class is: Package org. codeinfo. Demo; Import java. util. Concurrent. timeunit; Import org. openqa. Selenium.;Import org. openqa. Selenium. WebDriver;Import org. openqa. Selenium. Firefox. firefoxdriver; Public class util
. without selenium, calling Phantomjs directly. See the method above). Native to invoke JS, here the Parser.js code such as the following:System = require (' system ') address = system.args[1];//Gets the command line the second parameter will then use the //console.log (' Loading a Web page '); var page = require (' webpage '). Create (); var url = address; Console.log (URL); Page.open (URL, function (status) { //page is loaded!
Selenium is very helpful for our web automation testing, if we want to carry out a wide range of test coverage, we can not only run on one or two machines, the same selenium-grid also provide us with such help, We can easily build a distributed test environment with Selenium-grid. Unlike some of the other common distributed programs "such as: Hudson",
Selenium is a tool that allows the browser to automate a series of tasks, often used for automated testing. However, it can also be used to give Web pages. Currently, it supports four client languages for Java, C #, Ruby, and Python. If you use Python, you only need to enter "sudo easy_install selenium" on the command line and return to install Selenium's Python
, directly call Phantomjs, see the above method), the native to invoke JS, here the Parser.js code is as follows:System = require (' system ') address = system.args[1];//Get command line the second parameter will then use the //console.log (' Loading a Web page '); var page = require (' webpage '). Create (); var url = address; Console.log (URL); Page.open (URL, function (status) { //page is loaded! if (Status!== ' success ') { console.log (' Unable to post! ');
调试十分困难。 Because the page may have a lazy load situation. Although the page has been rendered, there may be ajx lazy loading. Some elements need to wait until the AJAX call is complete before they can be displayed. At this point, you need to add a wait mechanism on the page./** * 用于等待某个元素出现,软等待 * @param by */public boolean wait(final By by){ new WebDriverWait(driver, 10).until(new ExpectedConditionFor example, you want to find an element that id=
example, a landing page, using the PO mode, will create a LoginPage class, the class will define the user name input box, password input box, login button webelenentFor the corresponding element to implement the corresponding method, the input box is used to input, you need to create a user name and enter the password method, so that the real page consistent, so the design concept is PO mode. The pagefactory belongs to the PO mode, which is used to i
()
Section 5th
The following common methods are described based on specific instances:
Get status
Action
Upload files
Execute JS
Browser window Switching
The following example shows how to use the preceding webdriver api when you log on to the Apsara stack console and modify your personal information.
Section 6th
An overview of the concept of automated architecture design the design purpose and purpose of specific classes, including:
BaseLib
Selen
Selenium IDE recording login operation, export Java/Junit 4/WebDriver, junitwebdriver
Selenium IDE can record simple browser operations and export the desired code.
Before using Selenium 2.46 to officially do some things, I plan to use IDE To record simple login operations, export them into
November 15, the concept of automated testing has a preliminary understanding, because the course is open class, so the environment needs us in advance at home, in the process of building the environment is indeed some difficulties, all kinds of Baidu debugging finally set up the environment, the following part of the content is reproduced, good not wordy, Directly on the selenium environment to build the steps.
Environment: win7+
The Selenium IDE can record simple browser operations and then export to the corresponding code you want.
Before I do something formal with selenium 2.46, I intend to record a simple login operation with the IDE, then export it as a Java code, and give myself an example of writing code directly behind.
"
, "size", "ten"); // Call the RemoveAttribute method to delete the Size property value in the text box //removeattribute (driver,textinputbox, "size"); //Add page Element property properties and modify the wrapping method of page element properties }privatevoidsetattribute (Webdriver driver2,webelementtEXTINPUTBOX,NBSP;STRINGNBSP;STRING,NBSP;STRINGNBSP;STRING2) {//todo auto-generatedmethodstubjavascriptexecutorjs= ( Javascriptexecutor) driver;Objectelement=null; ObjectattributeName= "AA"; object
choose another location method
2. Cssselector execution speed, recommended use
3. When positioning hyperlinks, you can consider Linktext or partiallinktext: But note that the text changes frequently, so it is not recommended
4. XPath is the most powerful. The execution was slow because it was necessary to find the entire DOM, so try to use less. When there's no way to use XPath
Find elements by ID: by.id ()
Finding elements through the ID of the page element is the most recommended way, an
The origin of this article, the two days to tidy up their regular use and very skilled projects, today suddenly think of missing one, fill up, but think of no corresponding blog, then write a simpleSome of the techniques I often use and are relatively skilled are as follows (I don't know if it counts as the spicy chicken in the eyes of the Gods):Traditional Web project testing, most of them rely on the test Department of Small Partners manual operation, time-consuming and easy to side-leakage '
SELENIUM2 (webdirver) Getting Started Environment Building (Java Edition)First, the development environment:1, JDK1.62. Eclipse:Version:Kepler Service Release 1,:http://www.eclipse.org/downloads/3, selenium:selenium-java-2.52.0.zip,:http://docs.seleniumhq.org/download/Unpack the Selenium-java package, which contains fo
you like to write a click or input script can be, we here for example click action. The second argument is: the element to be clicked.For example, I want to click the Search button Baidu search, you can write:((Javascriptexecutor) driver). Executescript ("Arguments[0].click ();", Driver.findelement (By.id ("su"));The core code is as follows: New firefoxdriver ();d river.get("https://www.baidu.com/"= "Argum
structure such as: 2. Add build path, project directory right click-->build path--> Config build Path-->java build Path-->libraries-->add JARsAdd all the jar packages under the Libs folder and add selenium-java-2.39.0 and Selenium-java-2.39.0-srcs 3, add after the directo
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.