2017-04-04 131 views
0

我在做硒一个基本的测试,我想它从Maven的执行,我没有得到任何错误,但浏览器没有在测试中部分launched.and我得到Maven是不会启动浏览器硒

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

我的src /测试/ 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> 

执行的OUTPUT:

[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] ------------------------------------------------------------------------ 

如何将我的调用我的浏览器,并进行测试。

回答

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(); 
    } 
} 
+0

我已经更新了我的代码。现在我得到了与壁虎驱动程序有关的错误,但是我的代码中包含了它。之前它没有给出错误。 我的更新代码是: 错误是: java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.gecko.driver系统属性设置; \t \t @Test 公共静态无效的主要(字串[] args)抛出的Throwable { System.setProperty( “webdriver.gecko.driver”,“C:/用户/ swkv8851 /下载/ geckodriver-V0 .15.0-的win32/geckodriver.exe“); Open open = new Open(driver); open.Opengmail(); } } –

+0

请问您能否用新代码更新您的问题(保留旧代码并添加新代码)?你的@Test方法不能是静态的,也不能有任何参数 –

相关问题