Java 为 iOS 应用测试自动化设置 appium
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20730917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting up appium for iOS app test automation
提问by Ravi Gupta
Looking far and wide for a step-by-step guideto set-up iOS Test Automation using appium, with scripts in Java (no ruby and/or cucumber).
广泛寻找使用 appium 设置 iOS 测试自动化的分步指南,以及 Java 脚本(没有 ruby 和/或黄瓜)。
Note: The appium wiki is not helpful either.
注意:appium wiki 也没有帮助。
回答by Smriti
To run iOS tests, you can follow these steps :
要运行 iOS 测试,您可以按照以下步骤操作:
(Note: I am using Java language here in Eclipse IDE and using Appium app):
(注意:我在 Eclipse IDE 中使用 Java 语言并使用 Appium 应用程序):
- Create a new java project in Eclipse.
- Import jar files : Selenium Server (formerly the Selenium RC Server) version and required client driver (according to your language choice) which can be downloaded here. (To import : Right click on your project -> Properties -> Libraries -> Add External JARs. Add all three selenium jar files here.)
- DownloadAppium app and launch.
- You can run your test scripts either in simulator or on real device. To run scripts on real iOS device, you will need 'deviceName', 'platformVersion', 'UDID' (Device ID) and 'Bundle ID' (Application Bundle ID) and absolute path to the .ipa.
- To run scripts on iOS simulator , you will need 'deviceName', 'platformVersion', path to .app and 'Bundle ID' of your app.
- Choose capabilties in Appium app and mention the same in your script based on whether you are testing on simulator or on device.
- Launch Appium server and then run your script.
- 在 Eclipse 中创建一个新的 Java 项目。
- 导入 jar 文件:Selenium Server(以前称为 Selenium RC Server)版本和所需的客户端驱动程序(根据您的语言选择),可在此处下载。(导入:右键单击您的项目 -> 属性 -> 库 -> 添加外部 JAR。在此处添加所有三个 selenium jar 文件。)
- 下载Appium 应用程序并启动。
- 您可以在模拟器或真实设备上运行您的测试脚本。要在真实的 iOS 设备上运行脚本,您需要“deviceName”、“platformVersion”、“UDID”(设备 ID)和“Bundle ID”(应用程序包 ID)以及 .ipa 的绝对路径。
- 要在 iOS 模拟器上运行脚本,您将需要“deviceName”、“platformVersion”、应用程序的路径和“Bundle ID”。
- 在 Appium 应用程序中选择功能,并根据您是在模拟器上还是在设备上进行测试,在您的脚本中提及相同的功能。
- 启动 Appium 服务器,然后运行您的脚本。
All Appium server capabilities which can be used can be found here.
所有可以使用的 Appium 服务器功能都可以在这里找到。
You can refer to my blog post hereas well for more details to execute a sample basic script.
回答by Bob
I found this very helpful.
我发现这很有帮助。
http://seleniumworks.blogspot.co.uk/2013/12/appium-native-ios-app-testing-webdriver.html
http://seleniumworks.blogspot.co.uk/2013/12/appium-native-ios-app-testing-webdriver.html
Note you need to get the .app of your project for it to work - not the .ipa
请注意,您需要获取项目的 .app 才能使其工作 - 而不是 .ipa
Appium Native iOS App Testing | WebDriver Appium is an open source, cross-platform test automation tool for native, hybrid and mobile web apps. Appium tests can be written in your favorite Webdriver-compatible language.
Appium原生iOS应用测试| WebDriver Appium 是一个开源、跨平台的测试自动化工具,适用于原生、混合和移动 Web 应用程序。Appium 测试可以用您最喜欢的 Webdriver 兼容语言编写。
Requirements & installation
要求和安装
1| MAC OS X 10.7 (minimum version required) 2| Xcode updated version (prefer) 3| Node.js 4| Appium.app 5| Eclipse Kepler (prefer) 6| TestNG framework
1| MAC OS X 10.7(需要最低版本)2| Xcode 更新版本(首选)3| Node.js 4| Appium.app 5| Eclipse 开普勒(首选)6| 测试NG框架
Pre-Appium setup
Appium 前设置
iOS .app file is enough to inspect elements. In this example, I have used the project, 'InternationalMountains' from Apple DEV site.
iOS .app 文件足以检查元素。在此示例中,我使用了来自 Apple DEV 站点的项目“InternationalMountains”。
1| Download the project, 'InternationalMountains' 2| Double click and extract it 3| Import it into Xcode by opening the Xcode file 4| Run the project 5| Make sure that the simulator is opened with the application 6| Open Terminal and move to the project folder 7| Run the following command to build the .app file
1| 下载项目“国际山”2| 双击并提取它 3| 通过打开 Xcode 文件 4| 将其导入 Xcode 运行项目 5| 确保模拟器是用应用程序打开的 6| 打开终端并移动到项目文件夹 7| 运行以下命令来构建 .app 文件
`xcodebuild -sdk iphonesimulator6.1`
8| It will build the app and generate the file, 'InternationalMountains.app' under /InternationalMountains/Build/Products/Release-iphonesimulator/
8| 它将构建应用程序并在 /InternationalMountains/Build/Products/Release-iphonesimulator/ 下生成文件“InternationalMountains.app”
Appium iOS setup
Appium iOS 设置
1| Download & Install Node.js
// npm represents that Node.js Package Manager
$ sudo npm install wd
1| 下载并安装 Node.js // npm 代表 Node.js 包管理器
$ sudo npm install wd
2| Run the Appium server using node.js;
There are couple of ways to do so..
2| 使用运行 Appium 服务器node.js;
有几种方法可以做到这一点..
1 Using Node.js
1 使用 Node.js
//install Appium
$ npm install -g appium (or) $ sudo npm install appium -g
//start Appium server
$ appium &
//安装Appium
$ npm install -g appium (or) $ sudo npm install appium -g
//启动Appium服务器
$ appium &
2 Using the App
2 使用应用程序
Download Appium, install and Run it
下载 Appium,安装并运行它
3| Now, the Appium server gets started in the
3| 现在,Appium 服务器在
default port 4723 and IP Address 0.0.0.0
Appium inspector
Appium 检查员
Appium inspector is a record and playback tool just like Selenium IDE for web.
Appium Inspector 是一个记录和回放工具,就像 Selenium IDE for web 一样。
1| Open Appium
1| 打开 Appium
2| Change the default IP address to 127.0.0.1 and port 4725
2| 将默认 IP 地址更改为127.0.0.1 and port 4725
3| Now, enable the check box, 'App path' 4| Click on the 'Choose' button and locate the .app local directory. i.e., InternationalMountains.app
3| 现在,启用复选框,“应用程序路径” 4| 单击“选择”按钮并找到 .app 本地目录。即,InternationalMountains.app
5| Click on the 'Launch' button [Appium server launches now] 6| Now, a blue-colored icon found beside the 'Launch' button is enabled 7| Clicking blue-colored icon open up the Appium inspector with Simulator 8| Now, click the 'Record' button in Appium inspector 9| Every action will be generating a script at bottom of the Appium inspector
5| 单击“启动”按钮 [Appium 服务器现在启动] 6| 现在,启用了“启动”按钮旁边的蓝色图标 7| 单击蓝色图标打开带有模拟器 8 的 Appium 检查器| 现在,单击 Appium 检查器 9 中的“记录”按钮| 每个动作都会在 Appium 检查器底部生成一个脚本
Run the script in Eclipse IDE
在 Eclipse IDE 中运行脚本
package packagename;
import java.io.File;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class AppiumTest {
public WebDriver driver = null;
@BeforeMethod
public void setUp() throws Exception {
// set up appium
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
capabilities.setCapability(CapabilityType.VERSION, "6.1");
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
capabilities.setCapability("app","/Users/username/Downloads/InternationalMountains /build/Release-iphonesimulator/InternationalMountains.app");
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4725/wd/hub"), capabilities);
}
@AfterMethod
public void tearDown() throws Exception {
driver.quit();
}
@Test
public void test01() throws InterruptedException {
driver.findElement(By.xpath("//window[1]/tableview[1]/cell[2]")).click();
driver.findElement(By.xpath("//window[1]/navigationBar[1]/button[1]")).click();
driver.findElement(By.xpath("//window[1]/tableview[1]/cell[7]/text[1]")).click();
}
}
Note: 1| Currently, there is no Appium inspector support for Windows
注:1| 目前,没有对 Windows 的 Appium 检查器支持
回答by Jitendra kumar
I am getting error popup on step 6 -
我在第 6 步出现错误弹出窗口 -
Could not start a new session
无法开始新会话
Be sure the Appium server is running with an application opened by using the "App Path" parameter in Appium.app (along with package and activity for Android) or by connecting with selenium client and supplying this in the desired capabilities object.
通过使用 Appium.app 中的“App Path”参数(以及 Android 的包和活动)或通过与 selenium 客户端连接并在所需的功能对象中提供它,确保 Appium 服务器正在运行一个应用程序。
回答by Boobalan
I have uploaded the java eclipse project on github
我已经在github上上传了java eclipse项目
https://github.com/boobalaninfo/javaworkspace.git
https://github.com/boobalaninfo/javaworkspace.git
Requirement:
要求:
- Appium should up and running on Mac machine
- Eclipse to develop and run the java test cases
- Appium 应该在 Mac 机器上启动并运行
- Eclipse开发和运行java测试用例