In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
[updated at 9:00 on 2016-8-2]
Web Driver
Selenium 2.0 is a collection of WebDriver API.
Selenium-WebDriver is developed to better support dynamic web technology.
The goal of WebDriver is to provide a complete set of object-oriented API to provide better support for current web application testing.
If you don't do anything else, you can't be afraid of causing ambiguity.
Web Server
Whether you need to download Selenium Server depends on how you use Selenium-WebDriver.
Situations where Server is not needed
The browser used to execute the test case and test it is on the same machine.
Situations where Selenium Server is required
1: use Selenium-Grid to assign test sets to multiple machines or virtual machines for execution.
2: connect to a remote machine with a specific version of the browser.
3: instead of using Java bindings (that is, Python,C#,Ruby), use HtmlUnit Driver to set up a Selenium-WebDriver Project.
Java
[personal notes]
Now that we know that Selenium2.0 (that is, WebDriver) is a series of API that can be used in web applications, then we will use the language we master and write the test program by calling the corresponding API to carry out automated testing.
Selenium is used under Java, and only Maven is recommended in the document. There is one more tool to learn for entry rookies, which is really frustrating. But I have also seen the requirement to use project management tools in recruitment, so it is OK to take some time to familiarize myself with the basic operation of Maven. After searching for a long time, I found a video of getting started with Maven, links and some problems with the video posted in another article, "introduction to Maven and Notes", portal: http://maise.blog.51cto.com/11149607/1829580
[end]
The easiest way to create a Selenium 2.0 Java project is to use Maven. By setting up Maven's pom.xml file, Maven will create a project for you, download Java bindings (that is, Selenium 2.0 java client library) and all projects rely on JAR packages, and then you can import the project into your commonly used IDE, IntelliJ IDEA or Eclipse.
1. Create a new folder (for example, C:\ Maven).
two。 Create a new .txt file under "Maven" and rename it "pom.xml". Examples are as follows:
4.0.0 MySel20Proj MySel20Proj 1.0 org.seleniumhq.selenium selenium-java 2.53.1
The version information in the above content is the latest version information when editing this document. In practice, please give priority to the latest version information.
[personal notes]
People who have studied the video getting started with Maven (1) can get a general understanding of the example of pom.xml given by Selenium. The latest version information provided above refers to the version under "dependencies". To query the latest version, enter the text of the artifactId entry plus version on the search engine, and you can find the relevant website to query the latest version information.
Multiple "dependency" can be added under "dependencies". After saving, execute the command such as "mvn clean install", and Maven will download the corresponding JAR package for you.
[end]
3. Now you can enter the project folder through the command line window, CD, and enter the instruction: mvn clean install,Maven will automatically download Selenium and all project dependent JAR packages into the folder. Finally, import the project into IDE, and you can start programming.
[personal notes]
Set up a project practice step:
1. Install Maven and copy setting.xml to "C:\ Users\ Administrator\ .m2".
2. Cd to the path where you want to place the project, type: mvn archetype:generate-DgroupId=MySel20Proj-
DartifactId=MySel20Proj-Dversion=1.0. After Build succes, check whether the file under the path is established correctly.
3. Open the Maven under pom.xml,Dependencies and download the package for us that junit,junit is used in unit testing. Referenc
The example provided on the official website of Selenium adds dependency.
Notice that the language we use is Java:
Junit junit 4.12 test org.seleniumhq.selenium selenium-java 2.16.1
4. Execute mvn eclipse:clean under the path from cd to pom.xml (this step will delete the existing classpath and project files), and then execute mvn eclipse:eclipse. You can see that the classpath file is generated under all the paths of pom.xml. Then open eclipse,File- > Import- > Maven- > Existing Maven project- > Select the path, and you can see the new project-> Finish.
Introduce Selenium-WebDriver API through examples
After the new project, you can realize that WebDriver is just like other ordinary libraries: it is so perfect that you usually don't need to do any additional steps or installation before using it, which is much more convenient than Selenium-RC.
Note: additional actions are required to use ChromeDriver,Opera Driver,Android Driver or iOS Driver.
Now that you are ready to start programming, practice your hands with this example. This example uses Google to search for "Cheese" and print the title of the page.
Package MySel20Proj;import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.selenium.WebElement;import org.openqa.selenium.firefox.FirefoxDriver;import org.openqa.selenium.support.ui.ExpectedCondition;import org.openqa.selenium.support.ui.WebDriverWait Public class Selenium2Example {public static void main (String [] args) {/ / [personal notes] if the program reports an error, the path cannot be found: / / System.setProperty ("WebDriver.Firefox.bin", "find the installation path of Firefox.exe, copy path"); / / Syste.setProperty ("WebDriver.chromedriver.exe", "ditto") / / create an instance of Firefox driver / / Note that the following code depends on the interface (i.e. WebDriver) / / rather than the implementation (i.e. FirefoxDriver) / / Note: FirefoxDriver implements WebDriver WebDriver driver = new FirefoxDriver () / / visit Google [if you can't open Google, change Baidu] driver. Get ("http://www.google.com") / / you can also use the following statement to access the action / / driver.navigate () .to ("/ / locate the search box element [Baidu By.name (" wd ")] WebElement element = driver .findElement (By.name (" Q ")) through name; / / search cheese! Element .sendKeys ("Cheese!"); / / submit. WebDriver will perform the search action element. Submit () for us; / / confirm the page title System. Out .println ("Page title is:" + driver.getTitle ()) / / Google [Baidu] search uses JavaScript to dynamically render / / wait for the page to load Ten seconds countdown (new WebDriverWait (driver, 10)). Until (new ExpectedCondition () {public Boolean apply (WebDriver d) {return d. GetTitle (). ToLowerCase (). StartsWith ("cheese!") ) / / printout "" System. Out .println ("Page title is:" + driver.getTitle ()); / / close the browser driver .println ();}}
[personal notes]
I chose ChromeDriver to implement a piece of code. At run time, a line of text "Only local connections are allowed" always appears in the eclipse console window. What does this sentence mean? Check the API document for the definition of ChromeDriver:
1. A WebDriver implementation that controls a Chrome browser running on the local machine.
2. The control server which each instance communicates with will live and die with the instance.
In other words, ChromeDriver generates a server,server on the machine to listen through an open port of the machine, collect requests from the upper layer, and control the local chrome browser. That, of course, is "only local connections are allowed". According to the answer of stackoverflow's top vote, this sentence is just a suggestive message.
Http://stackoverflow.com/questions/25080500/when-run-webdriver-with-chrome-browser-getting-message-only-local-connection
Selenium-WebDriver API commands and actions
Read a web page
Driver.get ("http://www.google.com");"
WebDriver does not necessarily wait for the page to load, which is affected by several factors, including which operating system comes with which browser. In some cases, WebDriver may return control before the page is loaded, or even at the beginning of loading or during loading ([personal notes] currently understand the equivalent of Event to Java). In order to ensure the robustness ([personal notes]) of what? You need to use explicit / implicit wait to wait for element (s) to appear.
Locate the UI element
Positioning elements can be implemented through an instance of WebDriver or through WebElement. Each binding language (the language supported by Selenium) has "Find Element" and "Find Elements" methods. The previous method returns a WebElement object that matches the query and throws an exception if the element does not exist. The latter method returns a list with multiple WebElement, or an empty table if the query has no results.
The "Find" method needs to be used with "By".
To be continued.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.