首页 > 学院 > 开发设计 > 正文

selenium使用testNG测试框架编写webdriver脚本_05

2019-11-06 09:48:40
字体:
来源:转载
供稿:网友

selenium使用testNG测试框架编写webdriver脚本_05

关键字:testNG,maven,selenium版本,Firefox版本

遇到的问题:a.运行时报The JAR file selenium-2.44.0/jcommander-1.29.jarhas no source attachment错误->使用maven项目形式

                        b.运行时报The path to the driver executable must beset by the webdriver.gecko.driver system PRoperty; for more information错误->selenium与firefox版本不兼容造成的,需要引用selenium2.44.0的包(selenium3.0以下版本)

=============================================

1.eclipse中引入testNG插件

2.新建一个java项目并转换成maven项目

3.在pom.xml文件中引入以下内容

 <dependencies>

    <dependency>

     <groupId>org.seleniumhq.selenium</groupId>

      <artifactId>selenium-java</artifactId>

      <version>2.44.0</version>

    </dependency>

  </dependencies>

4.项目中引入TestNG插件

5.新建testNG类并编辑以下内容:

public class demo03 {

  WebDriver driver;

  @Test

  public void f() {

      driver.get("https://www.sogou.com/");

      driver.findElement(By.id("query")).sendKeys("测试");

      driver.findElement(By.id("stb")).click();

  }

  @BeforeMethod

  public voidbeforeMethod() {

      System.setProperty("webdriver.firefox.bin","D://firefox//firefox.exe");

      driver=newFirefoxDriver();

  }

  @AfterMethod

  public voidafterMethod() {

     driver.quit();

  }

}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表