【发布时间】:2021-01-16 08:06:45
【问题描述】:
我会为我的项目查看并测试 appium,然后我用 appium 和 cucumber 完成了一个新的 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] ------------------------------------------------------------------------
对这个问题有任何想法吗?
提前致谢, 西尔弗利奥
【问题讨论】:
-
欢迎来到 StackOverflow!链接到大量文件可能会导致人们跳过您的问题。最好在您发布的文本中包含小代码 sn-ps(所需的最少数量!)。您可以在代码编辑器中使用格式,使其在您的问题中整齐地显示。此外,请说明“测试不运行”的含义。 (例如,它们无法启动是因为找不到它们,或者因为它们崩溃,或者某些特定错误等)
-
您好@KenVanHoeylandt 感谢您的反馈,我解决了所有问题。
标签: java android maven testing appium