51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1857|回复: 3
打印 上一主题 下一主题

有没有用maven project来运行webdriver的???

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2014-4-28 10:57:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我在eclipse里创建了一个maven project,然后创建了一个java文件,但是运行的时候,WebDriver driver = new InternetExplorerDriver();这句话怎么也运行不了,也没有任何报错,就是一直在运行,但是不出结果,换了FirefoxDriver也不行,这是怎么回事啊,有人遇到过吗??
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2014-4-28 11:01:26 | 只看该作者
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>
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2014-4-28 11:08:14 | 只看该作者
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();
    }
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2014-5-16 09:53:17 | 只看该作者
//D:\Program Files\Mozilla Firefox如果不是默认按照在C盘需要设置浏览器安装路径
System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe");               
WebDriver driver = new FirefoxDriver();

我这样用完全没有问题的。
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-6 20:01 , Processed in 0.082477 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表