[英]Steps to run web application automation using Appium
I am having a lot of trouble trying to get my automated tests to run through a physical Android device using appium. 尝试让我的自动化测试在使用appium的物理Android设备上运行时遇到很多麻烦。 I am not so good with using cmd and configuring and there are very little tutorials on setting it up to run web apps.
我对使用cmd和配置不太满意,关于将其设置为运行Web应用程序的教程很少。 Heres what i have
这是我所拥有的
I think I have most everything I need, but I dont know the steps to take or how to alter the desired capabilities to run it through my phone! 我想我拥有所需的大部分东西,但是我不知道要采取的步骤或如何更改所需的功能以通过手机运行它! Please, I know this is a broad question but if someone can shed some insight as to how to make this happen I would be forever grateful.
拜托,我知道这是一个广泛的问题,但是如果有人可以就如何实现这一目标提供一些见解,我将永远感激不已。 Thanks!
谢谢! Below is an example of how I have my tests set up in the xml file.
以下是如何在xml文件中设置测试的示例。
<test name="Standard Ad Regression">
<parameter name="browserName" value="Android"/>
<parameter name="device" value="Samsung Galaxy S5"/>
<parameter name="emulator" value="true"/>
<parameter name="browser_version" value=""/>
<parameter name="platform" value="ANDROID"/>
<parameter name="local" value="true"/>
<parameter name="baseUrl" value="https://mywebsite.com/"/>
<parameter name="os" value="os"/>
<parameter name="os_version" value="4.4"/>
<parameter name="resolution" value="1024x768"/>
<parameter name="bsAccount" value="http://myusername:BcB9786AAvEoa45Fj@hub.browserstack.com/wd/hub"/>
<classes>
<class name="com.testsuites.regression.TestThis"/>
</classes>
</test>
This is a pretty general question, but I have done pretty much exactly what you are attempting to do. 这是一个非常笼统的问题,但我所做的几乎就是您要尝试做的事情。
I'm using a separate method to get the driver. 我正在使用一种单独的方法来获取驱动程序。 The reason I did this is so when I expanded my testing to run in parallel I did not need to redesign.
我这样做的原因是,当我将测试扩展到可以并行运行时,不需要重新设计。
public static AndroidDriver getDriver(String udid) throws MalformedURLException{
String URL = "XXXX";
ThreadLocal<AndroidDriver> driver = null;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("device", udid);
capabilities.setCapability("deviceName", udid);
capabilities.setCapability("udid", udid);
capabilities.setPlatform(Platform.ANDROID);
capabilities.setCapability("browserName", "Chrome");
try {
driver = new ThreadLocal<AndroidDriver>();
driver.set(new AndroidDriver(new URL(URL),
capabilities));
} catch (MalformedURLException e) {
System.out.println("Tackle Issue with RemoteDriverSetup");
}
driver.get().manage().timeouts()
.pageLoadTimeout(20L, TimeUnit.SECONDS);
driver.get().manage().timeouts()
.implicitlyWait(20L, TimeUnit.SECONDS);
return driver.get();
}
I am only passing the device's UDID through this file, I see you are using multiple parameters which is also fine. 我只是通过该文件传递设备的UDID,我看到您正在使用多个参数,这也很好。
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Nexus 7">
<parameter name="udid" value="XXXX" />
<classes>
<class name="testNG.TestOne"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Using the GUI you just need to press the button, make sure the URL used is the same one used to initialise the AndroidDriver. 使用GUI,您只需按一下按钮,确保使用的URL与用于初始化AndroidDriver的URL相同。
If you have any problems, run Appium doctor and make sure everything is installed correctly. 如果您有任何问题,请运行Appium doctor并确保一切均已正确安装。
Hope this helps, 希望这可以帮助,
Liam 利亚姆
// Switch to WebView
Set<String> contextNames = driver.getContextHandles();
System.out.println(contextNames.size());
for (String contextName : contextNames) {
System.out.println(contextName);
if (contextName.contains("WEBVIEW")){
driver.context(contextName);
}
}
Then once you switched to webview you can use appium APIs in the same way but now those will interact with webviews. 然后,一旦您切换到Webview,就可以以相同的方式使用appium API,但是现在这些API将与Webview交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.