Maven没有推出selenium浏览器

时间:2017-04-04 11:01:40

标签: maven selenium-webdriver junit maven-2

我正在Selenium进行基本测试,我希望它从maven执行我没有收到任何错误但浏览器没有启动。在TESTS部分我得到了

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

我的src / Test / java / Test.java是

public class Test {

public static void main(String[] args) throws Throwable {
        System.setProperty("webdriver.gecko.driver","C:/Users/swkv8851/Downloads/geckodriver-v0.15.0-win32/geckodriver.exe");

 Open open=new Open();
 open.Opengmail();
}
}

我的src / main / java.Open.java是:

import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Open {

    WebDriver driver=new FirefoxDriver();

public void Opengmail() throws Exception{   

driver.get("http://google.com");

driver.findElement(By.linkText("Gmail")).click();
Thread.sleep(5000);
driver.findElement(By.name("Email")).sendKeys ("somevalues");
String st=driver.findElement(By.xpath("//a[@class='need-help']")).getText();
System.out.println(st);
Assert.assertEquals("Find my account", st);
driver.findElement(By.id("next")).click();
Thread.sleep(2000);
driver.findElement(By.name("Passwd")).sendKeys ("some string");
driver.findElement(By.id("signIn")).click();
}

}

MY POM档案:

<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>SeleniumTestWithMaven</groupId>
  <artifactId>SeleniumTestWithMaven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>SeleniumTestWithMaven</name>

  <dependencies>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-firefox-driver</artifactId>
    <version>3.3.1</version>
</dependency>
</dependencies>
</project>

执行输出:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building SeleniumTestWithMaven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ SeleniumTestWithMaven ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ SeleniumTestWithMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ SeleniumTestWithMaven ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ SeleniumTestWithMaven ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ SeleniumTestWithMaven ---
[INFO] Surefire report directory: C:\Personal\learn_selenium\workspace\SeleniumTestWithMaven\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.294 s
[INFO] Finished at: 2017-04-04T16:23:45+05:30
[INFO] Final Memory: 9M/114M
[INFO] ------------------------------------------------------------------------

我如何调用浏览器并执行测试。

2 个答案:

答案 0 :(得分:0)

Selenium Version&gt; 3.0要求GeckoDriver运行Firefox @ https://github.com/mozilla/geckodriver/releases

答案 1 :(得分:0)

您的代码中没有测试(没有@Test注释) 你需要这样的东西:

public class Test {

    @Test
    public void myTest() {
        System.setProperty("webdriver.gecko.driver","C:/Users/swkv8851/Downloads/geckodriver-v0.15.0-win32/geckodriver.exe");

        Open open=new Open();
        open.Opengmail();
    }
}