51Testing软件测试论坛
标题:
有没有用maven project来运行webdriver的???
[打印本页]
作者:
showshow
时间:
2014-4-28 10:57
标题:
有没有用maven project来运行webdriver的???
我在eclipse里创建了一个maven project,然后创建了一个java文件,但是运行的时候,WebDriver driver = new InternetExplorerDriver();这句话怎么也运行不了,也没有任何报错,就是一直在运行,但是不出结果,换了FirefoxDriver也不行,这是怎么回事啊,有人遇到过吗??
作者:
showshow
时间:
2014-4-28 11:01
maven的pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd
">
<modelVersion>4.0.0</modelVersion>
<groupId>MySelenium</groupId>
<artifactId>MySelenium</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<includes>
<include>Test/DemoTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
作者:
showshow
时间:
2014-4-28 11:08
webdriver的代码:
public static void main(String[] args) {
System.setProperty("webdriver.ie.driver", "D:\\Selenium\\IEDriverServer\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com");
WebElement element =driver.findElement(By.name("q"));
element.sendKeys("Cheese!");
element.submit();
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().startsWith("cheese!");
}
});
Assert.assertEquals(driver.findElement(By.xpath("//div[@class='kno-rdesc']")).getText().substring(0, 21), "奶酪,又名干酪、乳酪,译称芝士、起司、起士");
driver.quit();
}
作者:
征途
时间:
2014-5-16 09:53
//D:\Program Files\Mozilla Firefox如果不是默认按照在C盘需要设置浏览器安装路径
System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();
我这样用完全没有问题的。
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2