Automated test configuration -selenium Deep inside the eclipse

Previous chapter talked about the eclipse installation configuration. The talk about how to configure WebDriver integrated into eclipse inside. Here to talk about the steps.

  1. Download Webdriver JAR file. Selenium open official website, download address: www.seleniumhq.org/download, after the download is complete, extract to a local.

  2. Start eclipse, create a new Java project, for example, Autotest, and then on the src directory of new construction right-click pop-up to select "New" - "" Package "enter the name in the name, place, for example," cn. autotest ", click Finish, Finish.

  3. In the current project, the first to create a test class, for example, named FirstAutotest, right-click the picture in the current project, the pop-up box select "Properties".

  4. In the dialog box, clicking "Java Bulid Path", and then select the "Librarise" tab, and then click the "Add External JARs" button, as shown below:

 

   5. In the dialog box and select the package path just extracted Selenium, selected from the following two JAR file shown in FIG. In the project "Libraries" you can see two new JAR files prove successful.

 

 6. Again click "Add External JARs" button, all the Libs folder file into eclipse, as shown below:

 

7. At this time, see "Librarise" tab bar all files newly added "libs" folder, as shown below:

 

 

 

At this point, WebDriver successfully integrated into the inside of the eclipse, we can start writing automated test scripts. Let us write the first automated script now!

In the first two chapters of the new project, enter the following code:

package cn.autotest;

 

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

 

public class FirstAutotest {

 

public static void main(String[] args) throws InterruptedException {

// TODO Auto-generated method stub

WebDriver wd;

String Url;

// set firefox installation path, as follows

System.setProperty("webdriver.firefox.bin", "C:\\Program Files\\Mozilla Firefox\\firefox.exe");

wd = new FirefoxDriver();

 

Url="http://www.baidu.com/";

 

// Open the Baidu page

 

wd.get(Url + "/");

 

// Pause three seconds

 

Thread.sleep(3000);

 

// Close the browser

 

wd.close();

 

 

}

 

}

After writing, typing the right page, select Run AS -> Java Application, you can run, is not it start automatically, then open Baidu it? You can start to prove the success of the first automated script to write it, congratulate yourself now.

It released the first time the public micro-channel number retrieve the attention brother king automated test or scan the following code

 

Guess you like

Origin www.cnblogs.com/king44/p/11607491.html