菜鸟的第一个selenium程序

从开始转做测试后差不多有2个多月,我们公司产品慢慢进入稳定状态然后团队老大要求重复性比较多的东西进行自动化测试,然后我就开始了学习自动化测试,我选择的工具是selenium,之所以选择selenium,只要基于几点

1.我们公司产品主要侧重于IE平台,selenium2对IE的支持比较好。

2.selenium2中是面向对象的设计方式,我大学学习的是java,上手起来会比较快。

今天照着书做了第一个简单程序(打开IE浏览器进入www.baidu.com)
代码:

 1 package Project1;
 2 import org.openqa.selenium.*;
 3 import org.openqa.selenium.WebDriver.*;
 4 import org.openqa.selenium.ie.*;
 5 
 6 public class Project1Class {
 7 
 8 public static void main(String[] args) {
 9 // TODO Auto-generated method stub
10 System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\IEDriverServer.exe");
11 WebDriver driver=new InternetExplorerDriver();
12 Navigation navigation=driver.navigate();
13 navigation.to("http://www.baidu.com");
14 
15 }
16 }

 

上面的是成功代码,中间出现问题
1.The path to the driver executable must be set by the webdriver.ie.driver system property;
for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver.
The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
这个出现的原因,从英文理解是IE浏览器的启动是需要通过webdriver.ie.driver来启动的,我在原来的代码中加入了

1 System.setProperty("webdriver.ie.bin","C:\\Program Files\\Internet Explorer\\iexplore.exe");

这个是我从书中依样画葫芦出来的,还是一样的出现上面的错误,百度了后发现是

1 System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\iexplorer.exe");

接下来还是出现问题百度了下,在http://bbs.51testing.com/thread-924175-1-1.html中找到了答案
原因是:因为selenium无法直接启动IE,所以需要借助IEDriver,chrome浏览器也是这样,而firefox不用。那个网址中的下载地址
已经无法使用(Google已废)我找到了CSDN上的资源http://download.csdn.net/detail/u012720226/8253299 最终代码修改为上面。最后IE浏览器中的安全模式(即设置->安全 四个域中的“启用保护模式”勾选都去掉)才能成功启动。我下载的IEDriverServer.exe版本不知道有没有关系但是能成功启动。

起步成功,一步步深入,努力吧~

posted @ 2015-08-12 22:23  ray110  阅读(545)  评论(0)    收藏  举报