我将为我的项目查看和测试appium,并完成了一个包含appium和黄瓜的新Maven项目,但是我遇到了以下问题: 当我运行Maven测试时,我看到零测试运行,而且我不明白问题出在哪里。
我的本地计算机上安装的JDK:JDK-15 jdk bin和maven bin的路径在我的Windows路径变量中
这是我的POM文件:https://github.com/silv3ri0/test-appium-java/blob/master/com.qa/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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>qa.mobile</groupId>
<artifactId>com.qa</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.version>3.6.0</maven.compiler.version>
<maven.compiler.source>7</maven.compiler.source>
<maven.compiler.target>7</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.6.0</version>
<scope>test</scope>
</dependency>
<!-- 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/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>6.5.0</version>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
<compilerArgument>-Werror</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>
MyRunnerTestClass:https://github.com/silv3ri0/test-appium-java/blob/master/com.qa/src/test/java/com/qa/runners/MyRunnerTest.java
package com.qa.runners;
import org.testng.annotations.Test;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.CucumberOptions.SnippetType;
//@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "html:target/cucumber", "summary"}
,features = {"src/test/resources"}
,glue = {"com.qa.stepdef"}/*tags = {"@appium"}*/)
@Test
public class MyRunnerTest {
}
package com.qa.stepdef;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import utility.Hook;
public class MissguidedStepDef {
private AppiumDriver driver;
public MissguidedStepDef() {
this.driver = (AppiumDriver) Hook.getDriver();
}
@Given("^i navigate the shop$")
public void iNavigateTheShop() {
// Write code here that turns the phrase above into concrete actions
Assert.assertTrue(driver.findElement(By.xpath("//*[@text='Accessibility']")).isDisplayed());
}
挂钩类:https://github.com/silv3ri0/test-appium-java/blob/master/com.qa/src/test/java/utility/Hook.java
package utility;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.cucumber.java.After;
import io.cucumber.java.Before;
public class Hook {
private static AppiumDriver driver;
@Before
public void setUpAppium() throws MalformedURLException
{
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformName", "Android");
desiredCapabilities.setCapability("platformVersion", "11");
desiredCapabilities.setCapability("deviceName", "any device name");
desiredCapabilities.setCapability("automationName", "UiAutomator2");
desiredCapabilities.setCapability("avd", "Pixel_3_API_30");
desiredCapabilities.setCapability("appPackage", "com.poqstudio.app.platform.missguided");
desiredCapabilities.setCapability("appActivity", "com.poqstudio.app.platform.presentation.countrySwitcher.view.CountrySwitcherSelectCountryActivity");
desiredCapabilities.setCapability("app", "C:\\projectappium/Missguided_v14.3.0.1_apkpure.com.apk");
URL url = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AndroidDriver(url, desiredCapabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@After
public void tearDown()
{
driver.quit();
}
public static WebDriver getDriver()
{
return driver;
}}
功能文件:https://github.com/silv3ri0/test-appium-java/blob/master/com.qa/src/test/resources/AddToBag.feature
Feature: Test add to bag
Scenario: Show register form after add to bag
Given i navigate the shop
And select clearence category
And select seven item from search result
And add to bag item
When go to the select pay
Then sign in is displayed
有人可以帮助我吗?对于我来说,现在至少要验证功能文件的第一步是否正常很重要。
当我说测试不运行时,是指当我单击pom文件上的maven测试时,我会在控制台中看到以下结果:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for qa.mobile:com.qa:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ line 77, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] --------------------------< qa.mobile:com.qa >--------------------------
[INFO] Building com.qa 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ com.qa ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ com.qa ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ com.qa ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ com.qa ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 3 source files to C:\Users\giancristofaros\eclipse-workspace\com.qa\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ com.qa ---
[INFO] Surefire report directory: C:\Users\giancristofaros\eclipse-workspace\com.qa\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.qa.runners.MyRunnerTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@1ae369b7
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.31 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.971 s
[INFO] Finished at: 2020-09-30T16:32:38+02:00
[INFO] ------------------------------------------------------------------------
对这个问题有任何想法吗?
预先感谢, Silverio
答案 0 :(得分:0)
Maven Surefire插件配置不正确
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/Tests*.java</include>
<include>**/**/*Tests.java</include>
</includes>
</configuration>
</plugin>
maven surefire获取文件名中包含Test或Tests的文件。您已经包括了测试课程,但是没有放在正确的位置。