[英]How to accept user input on cucumber
My Greetings, Setups: - Selenium Java, Cucumber, Appium, Driver (Android Driver).我的问候,设置: - Selenium Java、Cucumber、Appium、驱动程序(Android 驱动程序)。 Problem: I need the user to use the command line after the application start to input the Phone number & the OTP Code.问题:我需要用户在应用程序启动后使用命令行输入电话号码和 OTP 代码。 (Their is no API for returning the OTP code - Security Reasons). (他们没有用于返回 OTP 代码的 API - 安全原因)。 The user can't input in thing when I use Scanner(System.In) as there is no Main method.当我使用 Scanner(System.In) 时,用户无法输入内容,因为没有 Main 方法。
Code example that I am using.我正在使用的代码示例。
TestRunner测试运行器
package runners;
import io.appium.java_client.android.AndroidDriver;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebElement;
import stepDefinition.Hooks;
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/main/java"},
glue = {"stepDefinition"},
tags = "@sanity",
monochrome = true,
stepNotifications = true,
plugin = {"pretty", "html:src/test/java/reports/sanity-report.html",
"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"}
)
public class RegRunner {
}
StepDef步骤定义
@Given("User at loginPage")
public void user_start_smile_application() {
System.out.println("Application is starting in the background...");
ErrorHandler.mambaErrorScreen(); // This Method Handle internet discount issue
loginPage.skipSplashScreen(); // This Method used to skip login if user is already logged
System.out.println("Enter the phone number..");
Scanner scanner = new Scanner(System.in);
MobileNo = scanner.nextLine();
System.out.println("Enter the OTP code..");
OtpCode = scanner.nextLine()
}
I Don't know to implement the main method using cucumber as it will be ignored in cucmber with the code that I wrote.我不知道使用黄瓜实现主要方法,因为它会在我编写的代码的黄瓜中被忽略。
Thanks.谢谢。
Required: When I run the code after the application getting launched I have to enter the phone number and the OTP code before the automation start, and this saved value are passed to the required field and the automation process start.必需:当我在应用程序启动后运行代码时,我必须在自动化开始之前输入电话号码和 OTP 代码,并将此保存的值传递到必填字段并启动自动化过程。
Solved by adding main method to test runner using cucumber.core.cli.Main通过使用 cucumber.core.cli.Main 将 main 方法添加到测试运行器来解决
public class TestRunner {
public static void main(String[] args) throws Throwable {
final String[] arguments = new String[]{
"--glue", "stepDefinition",
"--tags", "@G",
"src/main/java" // This will look for the classpath inside the jar file
};
Main.main(arguments);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.