Junit与maven程序无法正常工作

时间:2017-12-08 01:27:44

标签: java maven selenium junit

当我运行这个时,我收到了初始化错误,并且没有控制台错误。 我附上了junit测试代码和pom.xml代码。请帮我解决这个问题。它是一个Maven项目。

Junit计划:

import static org.junit.Assert.*;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class JunitTest {

    @Test
    public void test() {
        // fail("Not yet implemented");
        System.out.println("Junit code");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.amazon.in/");
        Select s = new Select(driver.findElement(By.id("searchDropdownBox")));
        s.selectByVisibleText("Books");
        driver.findElement(By.id("twotabsearchtextbox")).sendKeys("harry potter");
    }

}

Pom.xml:

<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>com.testmaven</groupId>
  <artifactId>mavenDemo</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
 <!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>3.5.2</version>
</dependency>
  </dependencies>
</project>

1 个答案:

答案 0 :(得分:0)

您需要在POM中定义构建阶段以进行集成单元测试的编译。

pom.xml 中添加此代码段以运行测试类。

angleSide.toString()

您可以在以下网址找到更多相关信息:

http://maven.apache.org/surefire/maven-failsafe-plugin/usage.html