【问题标题】:Maven is not launching the browser for seleniumMaven 没有为 selenium 启动浏览器
【发布时间】:2017-08-29 13:01:28
【问题描述】:

我正在 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();
}

}

我的 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] ------------------------------------------------------------------------

我怎样才能调用我的浏览器并执行测试。

【问题讨论】:

    标签: maven selenium-webdriver junit maven-2


    【解决方案1】:

    Selenium Version >3.0 需要 GeckoDriver 运行 Firefox 找到 @https://github.com/mozilla/geckodriver/releases

    【讨论】:

      【解决方案2】:

      你的代码中没有测试(没有@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();
          }
      }
      

      【讨论】:

      • 我已经更新了我的代码。现在我收到了与壁虎驱动程序相关的错误,但我的代码中有它。以前它没有给出错误。我更新的代码是:错误是:java.lang.IllegalStateException:驱动程序可执行文件的路径必须由 webdriver.gecko.driver 系统属性设置; @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.Opengmail(); } }
      • 拜托,你能用新代码更新你的问题吗(保留旧代码并添加新代码)?你的@Test 方法不能是静态的,不能有任何参数
      猜你喜欢
      • 1970-01-01
      • 2011-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-18
      • 2010-11-27
      相关资源
      最近更新 更多