[英]How can I make Appium and the app launch automatically before every test in Java for iOS with heels classes?
Now that I am able to open Appium and then running a script launching the app on a simulator, How can I launch Appium and the app before every test? 现在,我能够打开Appium,然后运行脚本以在模拟器上启动该应用程序,如何在每次测试之前启动Appium和该应用程序? How can this be made with helper classes that are called on the test scripts?
如何通过在测试脚本上调用的帮助程序类来做到这一点?
Not much familiar with java but there is @beforeTest @beforeSuite annotations in Testng, which might be worth to look on. 对Java不太熟悉,但是Testng中有@beforeTest @beforeSuite批注,可能值得一看。 Here is a helping link
这是一个帮助链接
https://examples.javacodegeeks.com/enterprise-java/testng/testng-beforesuite-example/ https://examples.javacodegeeks.com/enterprise-java/testng/testng-beforesuite-example/
Write one base class and write your code to launch the app inside the constructor of base class. 编写一个基类并编写代码以在基类的构造函数中启动应用程序。
And then extend the base class to all your test classes. 然后将基类扩展到所有测试类。 The base class constructor will be called automatically before the child class is executed.
在执行子类之前,将自动调用基类的构造函数。
Hope this helps :) 希望这可以帮助 :)
You have to create your appium server with --override-session flag. 您必须使用--override-session标志创建您的appium服务器。
node main.js --override-session
And then for each session you have to creare a new driver... 然后,对于每个会话,您都必须创建一个新的驱动程序...
driver = new AndroidDriver<WebElement>(new URL("http://192.168.1.50:4723/wd/hub"), capabilities);
//1. start doing things here...
//1. end
//Launch app again
driver = new AndroidDriver<WebElement>(new URL("http://192.168.1.50:4723/wd/hub"), capabilities);
//2. start doing things here...
//2. end
...
Ok so I've searched separately for the 2 things I needed here. 好的,所以我在这里分别搜索了我需要的两件事。 one is the launching of the Appium with Java code and found this:
一种是使用Java代码启动Appium,并发现了这一点:
@Before public void setup() throws Exception { @在公共void setup()抛出异常之前,{
service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()
.usingDriverExecutable(new File("/usr/local/bin/node"))
.withAppiumJS(
new File("/usr/local/bin/appium"))
.withIPAddress("127.0.0.1").usingPort(4723));
service.start();
Works great. 效果很好。 The second thing I wanted to do is automatically launch Appium and even the app.
我想做的第二件事是自动启动Appium甚至是应用程序。 and this can be done as I've searched tried and saw by @BeforeClass annotation on a separate class, creating static methods with the launch functions and then extending that separate class on the test class.
这可以通过在单独的类上通过@BeforeClass注释搜索尝试并看到的方法来完成,使用启动函数创建静态方法,然后在测试类上扩展该单独的类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.