【发布时间】:2019-05-06 01:50:19
【问题描述】:
我是 IntelliJ IDEA 的新手,我想通过终端线路运行我的测试。
我已经使用“运行”按钮运行了我的测试,并且我的测试全部通过了。现在,我在项目中的要求是使用命令行/终端运行。我真的不知道该怎么做。
我使用 Appium 作为我的移动自动化工具。
这就是我的测试所在的所有位置,C:\Users\ereyne\IdeaProjects\ioappium\src\test\java\io
我已经在谷歌上看过,但都是高水平的,谁能提供我一步一步的过程? Test java classes
这是我的 POM:
<?xml version="1.0" encoding="UTF-8"?>
<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>io.appium</groupId>
<artifactId>io.appium</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</project>
这是我在 IntelliJ 中的代码:
//package io;//package appium;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.MobileElement;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.net.URL;
import java.net.MalformedURLException;
public class appium {
public AndroidDriver<MobileElement> driver;
public WebDriverWait wait;
DesiredCapabilities dc = new DesiredCapabilities();
int CustomerNumber = 10088214;
int AccessCode = 44445555;
String SignIn = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[1]/android.view.View/android.view.View/android.view.View/android.view.View[2]/android.widget.Button[3]";
String MakeaPayment = "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.webkit.WebView/android.webkit.WebView/android.view.View/android.view.View/android.view.View[1]/android.view.View/android.view.View/android.view.View[2]/android.view.View[2]/android.widget.Button[4]";
@BeforeMethod
public void setUp() throws MalformedURLException {
dc.setCapability("deviceName", "Pixel XL API 28");
dc.setCapability("udid", "ce041714789604830d"); //DeviceId from "adb devices" command //Tab S3-674ce8f9 S8-ce041714789604830d
dc.setCapability("platformName", "Android");
dc.setCapability("platformVersion", "9.0");
dc.setCapability("skipUnlock","true");
dc.setCapability("appPackage", "com.loans.smartmoney");
dc.setCapability("appActivity","com.loans.smartmoney.MainActivity");
dc.setCapability("noReset","true");
dc.setCapability("automationName", "UiAutomator2");
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"),dc);
wait = new WebDriverWait(driver, 30);
}
@Test
public void testLoginTest() {
//Login
wait.until(ExpectedConditions.visibilityOfElementLocated
(By.xpath(SignIn)));
driver.findElement(By.xpath(SignIn)).click();
driver.findElement(By.className("android.view.View")).click();
driver.findElement(By.className("android.widget.EditText")).sendKeys(String.valueOf(CustomerNumber));
driver.findElements(By.className("android.widget.EditText")).get(1).click();
driver.findElements(By.className("android.widget.EditText")).get(1).sendKeys(String.valueOf(AccessCode));
driver.findElements(By.className("android.widget.Button")).get(1).click();
wait.until(ExpectedConditions.visibilityOfElementLocated
(By.xpath(MakeaPayment)));
}
@AfterMethod
public void tearDown() {
driver.quit();
}
}
我运行的是终端:C:\Users\ereyne\IdeaProjects\ioappium>mvn appium.java
错误:[错误] 未知的生命周期阶段“appium.java”。您必须以 : 或 :[:]: 格式指定有效的生命周期阶段或目标。可用的生命周期阶段是:验证、初始化、生成电子源、流程源、生成资源、流程资源、编译、流程类、生成测试源、流程测试源、生成测试资源、过程测试资源、测试编译、过程测试类、测试、准备包、包、预集成测试、集成测试、集成后测试、验证、安装、部署、预清理、清理、清理后、站点前、站点、站点后、站点部署。 -> [Help 1] [ERROR] [ERROR] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。 [错误] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。 [ERROR] [ERROR] 有关错误和可能的解决方案的更多信息,请阅读以下文章:
我也尝试在我的终端中运行它:C:\Users\ereyne\IdeaProjects\ioappium\src\test\java\io>javac appium.java
结果是一切都不存在,只是下面的一个示例错误。
appium.java:2: 错误:包 io.appium.java_client 不存在 import io.appium.java_client.MobileBy;
【问题讨论】:
-
在idea中打开一个shell/终端工具窗口,运行mvn test。您可能需要安装 bash 插件。
-
嗨@bmargulies,是的,已经看到那个终端了,但我不知道在上面写什么。因为我是手动测试员,所以我不是真正的编码员类型。
-
如果是maven项目,进入终端(
Alt+F12in intellij)调用mvn test。这是假设您已经添加了测试文件。 -
@Sachin - 添加我的测试文件是什么意思?我尝试了“mvn 测试”,它说它不是被识别为内部或外部命令。我也试过 'java
但没有用。 -
C:\Users\ereyne\IdeaProjects\ioappium\src\test\java\io>java appium 错误:无法找到或加载主类 appium C:\Users\ereyne\IdeaProjects\ioappium\ src\test\java\io>mvn test 'mvn' 不是内部或外部命令、可运行程序或批处理文件。
标签: maven intellij-idea