Export the recorded script to the Java format first
Edit and run test in eclipse
2.1 Create a new Java Project:file-new-java project
2.2 Right-click on the project name that you built in the previous step, tap build Path-add External Archives ..., Selenium-java-2.21.0.jar (client) and selenium- will be downloaded server-standalone- 2.21.0.jar (server) Add in
2.3 Start selenium server. Go to cmd and run "Java-jar Selenium-server-standalone-2.21.0.jar"--to ensure that the jar package can be found. The information is as follows:
[Java]View Plaincopy
- Information: launching a standalone server
- :21.484 Info-java:sun Microsystems Inc. 17.1-b03
- :21.500 info-os:windows XP 5.1 x86
- :21.515 info-v2. 21.0, with Core v2. 21.0. Built from revision 16552
- 21.859:info-remotewebdriver instances should connect To:http://127.0.0.
- 1:4444/wd/hub
- :21.875 info-version jetty/5.1.x
- :21.875 info-started httpcontext[/selenium-server/driver,/selenium-server
- /driver]
- :21.875 info-started httpcontext[/selenium-server,/selenium-server]
- :21.875 info-started httpcontext[/,/]
- :22.062 info-started org.openqa.jetty.jetty.servlet.ServletHandler@5d173
- :22.062 info-started httpcontext[/wd,/wd]
- :22.093 info-started socketlistener on 0.0. 0.0:4444
- :22.093 info-started org.openqa.jetty.jetty.Server@32fb4f
2.4 Code Testing
[Java]View Plaincopy
- Import Com.thoughtworks.selenium.DefaultSelenium;
- Public class SeleniumDemo01
- {
- public static void Main (string[] args)
- {
- String host = "localhost";
- int port = 4444;
- String url = "http://www.baidu.com/";
- String BrowserType = "*firefox";
- String keywordslocator = "document.getElementById (' kw ')";
- String search = "document.getElementById (' su ')";
- Defaultselenium Selenium = new Defaultselenium (Host,port,browsertype,url);
- Selenium.start ();
- Selenium.open (URL);
- Selenium.type (Keywordslocator,"Java Selenium");
- Selenium.click (search);
- Selenium.waitforpagetoload ("50000");
- Selenium.stop ();
- }
- }
- Operation Result:
- 1.firefox Browser Expectations
- 2. Open Baidu homepage
- 3. Type "Java Selenium" in the search box
- 4. Click on "Baidu button"
- 5. Page load 50s
- 6. Close the browser
- Excerpted from http://blog.csdn.net/test_me/article/details/7471364
Java Selenium Start