提问人:emnznlg 提问时间:11/13/2023 更新时间:11/13/2023 访问量:7
如何在执行第一个场景之前以编程方式启动 Appium 服务器?(使用 Cucumber 和 JUnit)
How to start Appium server programmatically before the first scenario executed? (Using Cucumber and JUnit)
问:
我想在第一个场景之前启动 Appium 服务器,然后在执行最后一个场景之后,我想关闭它。
但我做不到......
目前,它会在每个场景之前启动服务器,这让我的测试需要更长的时间......
这是我的代码:
- 这是我的 appiumServer 类:
package appiumserver;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;
import java.io.File;
public class AppiumServer {
static AppiumDriverLocalService server;
static String mainJSpath = "C:/Users/emin/AppData/Roaming/npm/node_modules/appium/build/lib/main.js";
public static void start() {
if (server == null) {
AppiumServiceBuilder builder = new AppiumServiceBuilder();
builder.withIPAddress("127.0.0.1")
.usingPort(4723)
.withAppiumJS(new File(mainJSpath))
.usingDriverExecutable(new File("C:/Program Files/nodejs/node.exe"));
server = AppiumDriverLocalService.buildService(builder);
server.start();
}
}
public static void stop() {
if (server.isRunning()) {
server.stop();
server = null;
}
}
}
- 这是我的 Hooks 类: (我在这里调用start()方法...
package hooks;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import utilities.Driver;
import static appiumserver.AppiumServer.start;
public class Hooks {
@Before
public void setUp() throws Exception {
//This will start the Appium Server...
start();
}
@After
public void tearDown(Scenario scenario) {
if (scenario.isFailed()) {
final byte[] failedScreenshot = ((TakesScreenshot) Driver.getDriver()).getScreenshotAs(OutputType.BYTES);
scenario.attach(failedScreenshot, "image/png", "failed-scenario-" + scenario.getName());
}
Driver.closeDriver();
//stop();
}
}
我尝试了@BeforeAll和@AfterAll注释,但没有用......
答: 暂无答案
评论
@BeforeAll
@AfterAll