Appium,IOS 模拟器,Java工程搭建
首先进入sample code Test App 有TestApp.xcodeproj文件的工程目录下 下编译出TestApp.app文件
1.新建 java 工程
2.import需要的包
新建class
package com.saucelabs.appium; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileBy;
import io.appium.java_client.ios.IOSDriver; import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Random; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities; /**
* Simple <a href="https://github.com/appium/appium">Appium</a> test which runs against a local Appium instance deployed
* with the 'TestApp' iPhone project which is included in the Appium source distribution.
*
* @author Ross Rowe
*/
@SuppressWarnings("deprecation")
public class SimpleTest { private AppiumDriver driver; private List<Integer> values; private static final int MINIMUM = ;
private static final int MAXIMUM = ; @Before
public void setUp() throws Exception {
// set up appium
File appDir = new File("/Users/huangxiaoshi/Downloads/sample-code-master/sample-code/apps/TestApp/build/release-iphonesimulator");
File app = new File(appDir, "TestApp.app");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformVersion", "6.1");
capabilities.setCapability("deviceName", "iPhone Simulator");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
values = new ArrayList<Integer>();
} @After
public void tearDown() throws Exception {
driver.quit();
} private void populate() {
//populate text fields with two random number
List<WebElement> elems = driver.findElements(By.className("UIATextField"));
Random random = new Random();
for (WebElement elem : elems) {
//为两个UIATextField控件生成两个随机数
int rndNum = random.nextInt(MAXIMUM - MINIMUM + ) + MINIMUM;
elem.sendKeys(String.valueOf(rndNum));
//并记录到数组中
values.add(rndNum);
}
}
//得到控件的中间位置
private Point getCenter(WebElement element) { Point upperLeft = element.getLocation();
Dimension dimensions = element.getSize();
return new Point(upperLeft.getX() + dimensions.getWidth()/, upperLeft.getY() + dimensions.getHeight()/);
} @Test
public void testUIComputation() throws Exception {
// populate text fields with values
populate();
// trigger computation by using the button
//点击控件计算两个数的和
WebElement button = driver.findElement(By.className("UIAButton"));
button.click();
// is sum equal ?
//判断得到的数是否和正确的和相等
WebElement texts = driver.findElement(By.className("UIAStaticText"));
assertEquals(String.valueOf(values.get() + values.get()), texts.getText());
} @Test
public void testActive() throws Exception {
//判断该控件是否展示
WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));
assertTrue(text.isDisplayed());
//判断该控件是否展示
WebElement button = driver.findElement(By.xpath("//UIAButton[1]"));
assertTrue(button.isDisplayed());
} @Test
public void testBasicAlert() throws Exception {
//点击alert控件,弹出提示框
driver.findElement(By.xpath("//UIAButton[2]")).click();
Alert alert = driver.switchTo().alert();
//check if title of alert is correct
//验证提示框文字是否正确
assertEquals("Cool title this alert is so cool.", alert.getText());
alert.accept();
} @Test
public void testBasicButton() throws Exception {
// 验证求和 button文字显示是否正确
WebElement button = driver.findElement(By.xpath("//UIAButton[1]"));
assertEquals("Compute Sum", button.getText());
} @Test
public void testClear() throws Exception {
//验证编辑框输入清空后编辑框内容是否为空
WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));
text.sendKeys("");
text.clear(); assertEquals("", text.getText());
} @Test
public void testHideKeyboard() throws Exception {
//编辑框输入文字
driver.findElement(By.xpath("//UIATextField[1]")).sendKeys("");
//确认键盘是否弹出
WebElement button = driver.findElement(MobileBy.AccessibilityId("Done"));
assertTrue(button.isDisplayed());
//点击隐藏键盘
button.click();
} @Test
public void testFindElementByClassName() throws Exception {
Random random = new Random();
//通过classname定位控件测试
WebElement text = driver.findElementByClassName("UIATextField");
int number = random.nextInt(MAXIMUM - MINIMUM + ) + MINIMUM;
text.sendKeys(String.valueOf(number)); driver.findElementByClassName("UIAButton").click(); // is sum equal ?
//验证是否相等
WebElement sumLabel = driver.findElementByClassName("UIAStaticText");
assertEquals(String.valueOf(number), sumLabel.getText());
} @Test
public void testFindElementsByClassName() throws Exception {
Random random = new Random();
//通过classname定位控件测试
WebElement text = (WebElement) driver.findElementsByClassName("UIATextField").get();
int number = random.nextInt(MAXIMUM - MINIMUM + ) + MINIMUM;
text.sendKeys(String.valueOf(number)); driver.findElementByClassName("UIAButton").click(); // is sum equal ?
WebElement sumLabel = (WebElement) driver.findElementsByClassName("UIAStaticText").get();
assertEquals(String.valueOf(number), sumLabel.getText());
} @Test
public void testAttribute() throws Exception {
Random random = new Random(); WebElement text = driver.findElement(By.xpath("//UIATextField[1]"));
//编辑框输入文字
int number = random.nextInt(MAXIMUM - MINIMUM + ) + MINIMUM;
text.sendKeys(String.valueOf(number));
//验证控件的name,label,value等属性是否和设定的相同,name为IntegerA
assertEquals("IntegerA", text.getAttribute("name"));
assertEquals("TextField1", text.getAttribute("label"));
assertEquals(String.valueOf(number), text.getAttribute("value"));
} @Test
public void testSlider() throws Exception {
//get the slider
//进度条控件
WebElement slider = driver.findElement(By.xpath("//UIASlider[1]"));
// 查看初始数据是否为50%
assertEquals("50%", slider.getAttribute("value"));
Point sliderLocation = getCenter(slider);
//拖动控件,从中心拖到初始位置
driver.swipe(sliderLocation.getX(), sliderLocation.getY(), sliderLocation.getX()-, sliderLocation.getY(), );
//验证控件是否归0,不归0?
assertEquals("0%", slider.getAttribute("value"));
} @Test
public void testLocation() throws Exception {
//验证控件的位置是否为94,122?
WebElement button = driver.findElement(By.xpath("//UIAButton[1]")); Point location = button.getLocation(); assertEquals(, location.getX());
assertEquals(, location.getY());
} @Test
public void testSessions() throws Exception {
// ?
HttpGet request = new HttpGet("http://localhost:4723/wd/hub/sessions");
@SuppressWarnings("resource")
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
JSONObject jsonObject = (JSONObject) new JSONParser().parse(EntityUtils.toString(entity)); String sessionId = driver.getSessionId().toString();
assertEquals(jsonObject.get("sessionId"), sessionId);
} @Test
public void testSize() {
//验证两个编辑框控件大小是否一致
Dimension text1 = driver.findElement(By.xpath("//UIATextField[1]")).getSize();
Dimension text2 = driver.findElement(By.xpath("//UIATextField[2]")).getSize();
assertEquals(text1.getWidth(), text2.getWidth());
assertEquals(text1.getHeight(), text2.getHeight());
}
}
下载并安装Appium.dmg
配置IOS部分:
配置完成后launch ,稍后启动Inspector:
显示界面如下
便可以看到UI的属性等情况
Appium,IOS 模拟器,Java工程搭建的更多相关文章
- Appium+iOS真机环境搭建
安装目录 1.macOS系统 10.12.6 2.xcode 9.0 3.appium Desktop 1.12.1 4.node.js node -v npm 5.cnpm npm insta ...
- Appium 从 0 到 1 搭建移动 App 功能自动化测试平台 (1):模拟器中运行 iOS 应用
转载:https://testerhome.com/topics/4960 在上一篇文章中,我对本系列教程的项目背景进行了介绍,并对自动化测试平台的建设进行了规划. 在本文中,我将在已准备就绪的iOS ...
- Appium+python自动化16-appium1.6在mac上环境搭建启动ios模拟器上Safari浏览器
前言 在mac上搭建appium踩了不少坑,先是版本低了,启动后无限重启模拟器.后来全部升级最新版本,就稳稳的了. 环境准备: 1.OS版本号10.12 2.xcode版本号8.3.2 3.appiu ...
- Appium robotframework-appium (ios 客户端测试)环境搭建
一. 简介 1.1摘要 本人测试新人,最近在搞ios客户端的自动化,准备采用robotframework-appium来实现自动化测试,一边学习一边总结,此安装说明文档是基于mac系统10.11版本, ...
- Mac下搭建Appnium+Python+Ios模拟器环境
转载:https://www.jianshu.com/p/f7cf077d9444 https://blog.csdn.net/a158123/article/details/79684499 htt ...
- appium ios真机自动化环境搭建&运行(送源码)
appium ios真机自动化环境搭建&运行(送源码) 原创: f i n 测试开发社区 6天前 Appium测试环境的搭建相对比较烦琐,不少初学者在此走过不少弯路 首先是熟悉Mac的使用 ...
- appium ios真机自动化环境搭建&运行(送源码)
appium ios真机自动化环境搭建&运行(送源码) 原创: f i n 测试开发社区 6天前 Appium测试环境的搭建相对比较烦琐,不少初学者在此走过不少弯路 首先是熟悉Mac的使用 ...
- Appium+python自动化17-启动iOS模拟器APP源码案例
前言 上一篇已经可以启动iOS模拟器上的safari浏览器了,启动app比启动浏览器要复杂一点,本篇以github上的源码为案例详细介绍如何启动iOS模拟器的app 一.clone源码 1.githu ...
- appium ios 真机自动化环境搭建
近期由于工作需要,本小菜在弄appium+ios+iphone真机的移动自动化,在网上找寻各种资料,发现针对IOS方面的资料少之又少,公司其它部门的弄过的同事也寥寥无几,即使有,也是安卓方面的.本次书 ...
随机推荐
- mysql replication常见错误整理
这篇文章旨在记录MySQL Replication的常见错误,包括自己工作中遇到的与网友在工作中遇到的,方面自己及别人以后进行查找.每个案例都是通过Last_IO_Errno/Last_IO_Erro ...
- [android开发篇]java环境配置
http://www.runoob.com/java/java-environment-setup.html Java 开发环境配置 在本章节中我们将为大家介绍如何搭建Java开发环境. window ...
- 【Android】SharedPreference存储数据
SharedPreference存储数据 使用SharedPreference保存数据 putString(key,value) 使用SharedPreference读取数据 getString( ...
- USACO Hamming Codes
题目大意:求n个两两hamming距离大于等于d的序列,每个元素是一个b bit的数 思路:仍然暴力大法好 /*{ ID:a4298442 PROB:hamming LANG:C++ } */ #in ...
- 洛谷P3758 - [TJOI2017]可乐
Portal Description 给出一张\(n(n\leq30)\)个点\(m(m\leq100)\)条边的无向图.初始时有一个可乐机器人在点\(1\),这个机器人每秒会做出以下三种行为之一:原 ...
- Snmp的学习总结——Snmp的基本概念
摘自:http://www.cnblogs.com/xdp-gacl/p/3978825.html 一.SNMP简单概述 1.1.什么是Snmp SNMP是英文"Simple Network ...
- P3147 [USACO16OPEN]262144 (贪心)
题目描述 给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-262,144),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. 这道题的思路: ...
- Spoj-ODDDIV Odd Numbers of Divisors
Given a positive odd integer K and two positive integers low and high, determine how many integers b ...
- Resin Thread Dump
[2015/08/25 20:50:13.254] {ThreadLauncher2[ThreadPool[system]]-1} Thread Dump generated Tue Aug 25 2 ...
- 关于FileZilla Server的安装问题
网上很多FileZilla Server教程到最后一步在本机上测试访问成功就没了,实际上还是不完整的,一般情况下外网还是访问不了,外网访问同样很重要. 可能有点童鞋会说安装的时候防火墙提示的时候我也点 ...