我在Maven上运行我的testNG测试遇到了问题,问题是我认为我的测试既不是并行执行也不是正确的顺序,我这样说是因为每次我执行调用{{1}使用我的测试我得到错误:
mvn test
显然是在我的测试类测试之前尝试执行Running com.pruebas.seleniumGridTestNG.dataDrivenParallelXML.TestLanzadorIdealistaTestNG
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@4ba33d48
Tests run: 3, Failures: 1, Errors: 0, Skipped: 2, Time elapsed: 0.484 sec <<< FAILURE!
tearDown(com.pruebas.seleniumGridTestNG.dataDrivenParallelXML.TestLanzadorIdealistaTestNG) Time elapsed: 0.348 sec <<< FAILURE!
java.lang.NullPointerException
at com.pruebas.seleniumGridTestNG.dataDrivenParallelXML.TestLanzadorIdealistaTestNG.tearDown(TestLanzadorIdealistaTestNG.java:118)
方法,这就是我得到NULL异常的原因。
@AfterClass
这是我的pom.xml文件:
public class TestLanzadorIdealistaTestNG {
private RemoteWebDriver driver;
@Parameters({ "browser","platformBrowser","versionBrowser","URL_NODE_HUB" })
@Test
public void generoDriver(String browser, String platformBrowser,String versionBrowser,String URL_NODE_HUB) throws InterruptedException, MalformedURLException{
DesiredCapabilities cap = null;
Platform plataform = null;
/**
* - INICIO - Controlamos la plataforma en la que se va a lanzar el test
*/
if (platformBrowser.equals("MAC")){
plataform = Platform.MAC;
}
if (platformBrowser.equals("WINDOWS"))
{
plataform = Platform.WINDOWS;
}
if (platformBrowser.equals("LINUX")){
plataform = Platform.LINUX;
}
if (platformBrowser.equals("")) // caso por defecto
{
plataform = Platform.ANY;
}
/**
* -FIN- Controlamos la plataforma en la que se va a lanzar el test
*/
/**
* - INICIO - logica para lanzar segun version del navegador
*/
if (browser.equals("firefox"))
{
cap = DesiredCapabilities.firefox();
cap.setPlatform(plataform);
cap.setBrowserName(browser);
cap.setVersion(versionBrowser);
}else if (browser.equals("chrome")) {
cap = DesiredCapabilities.chrome();
cap.setPlatform(plataform);
cap.setBrowserName(browser);
cap.setVersion(versionBrowser);
} else if(browser.equals("internet explorer")){
cap = DesiredCapabilities.internetExplorer();
cap.setPlatform(plataform);
cap.setBrowserName(browser);
cap.setVersion(versionBrowser);
} else if (browser.equals("safari")){
cap = DesiredCapabilities.safari();
cap.setPlatform(plataform);
cap.setBrowserName(browser);
/**
* - INICIO - Controlamos el caso en que no pusimos version de navegador alguna
*/
if (versionBrowser.equals("")){
cap.setVersion("");
}
else
{
cap.setVersion(versionBrowser);
}
/**
* - FIN - Controlamos el caso en que no pusimos version de navegador alguna
*/
}
/**
* - FIN - logica para lanzar segun version del navegador
*/
cap.setJavascriptEnabled(true);
driver = new RemoteWebDriver(new URL(URL_NODE_HUB), cap);
}
/**
* Test en el cual vamos a chequear que al seleccionar comprar como tipo de operacion
* habitacion y vacacional es desactivado y no posible de seleccionar en el area
* @throws InterruptedException
* @throws MalformedURLException
*/
@Test (dependsOnMethods={"generoDriver"})
public void ComprarDeactivateHabitacionVacacional() throws InterruptedException, MalformedURLException{
com.pruebas.seleniumGridTestNG.dataDrivenParallelXML.ManejadorPrograma manejador = new com.pruebas.seleniumGridTestNG.dataDrivenParallelXML.ManejadorPrograma(driver);
manejador.logicaPrograma();
}
@AfterTest
public void tearDown(){
driver.quit();
}
这是我的test-properties.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>EjemploSeleniumGridMavenTestNG</groupId>
<artifactId>EjemploSeleniumGridMavenTestNG</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.42.2</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.8</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
</dependencies>
</project>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/test-properties.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
有人可以帮我一把吗?
答案 0 :(得分:0)
<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>groupidhere</groupId>
<artifactId>artifactidhere</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>artifactidhere</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.2</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/test-properties.xml</suiteXmlFile>
</suiteXmlFiles>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!-- TestNG-xslt configuracion -->
<plugin>
<groupId>org.reportyng</groupId>
<artifactId>reporty-ng</artifactId>
<version>1.2</version>
<configuration>
<!-- Directorio de salida para los reportes en xslt de testng -->
<outputdir>/target/testng-xslt-report</outputdir>
<sorttestcaselinks>true</sorttestcaselinks>
<testdetailsfilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testdetailsfilter>
<showruntimetotals>true</showruntimetotals>
</configuration>
</plugin>
</plugins>
</reporting>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.42.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.42.2</version>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>reporty-ng</id>
<url>https://github.com/cosminaru/reporty-ng/raw/master/dist/maven</url>
</pluginRepository>
</pluginRepositories>
</project>