前提条件:

===========================================

1.Xcode版本为Xcode10及以上
2.Appium版本必须为1.9及以上,因为Xcode为10.0

3.appium-desktop
4.安装所需依赖库,包括:

a.Homebrew

b.Git

c.node (brew install node

d.npm (brew install npm)
e.carthage (brew install carthage)
f.libimobiledevice(真机测试需要)(brew install libimobiledevice)
g.ios-deploy(真机测试需要)(brew install ios-deploy

5、WDA配置

===========================================

上面的环境配置具体参考:

【Mac + Appium学习(一)】之安装Appium环境前提准备

【Mac + Appium + Python3.6学习(三)】之IOS自动化测试环境配置

环境:

  • MacOS:10.13.6
  • Appium:1.9.1
  • Appium-desktop:1.7.1
  • Java:1.8
  • XCode:10.0

一、安装测试环境

1、配置上面都有就不一一描述了,下面来看一下IOS模拟器:

1)打开Xcode,选择如下图所示,打开模拟器:

会启动一个模拟器:

模拟器的版本可以自行选择,这里我选择iPhone7:

如果想关闭某个模拟器,则点击要关闭的窗口再关闭,如下图:

下面去appium官网下载IOS演示程序:

地址:https://github.com/appium/ios-uicatalog

项目clone到本地环境:

$ git clone https://github.com/appium/ios-uicatalog.git
Cloning into 'ios-uicatalog'...
remote: Enumerating objects: 294, done.
remote: Total 294 (delta 0), reused 0 (delta 0), pack-reused 294
Receiving objects: 100% (294/294), 6.63 MiB | 1.35 MiB/s, done.
Resolving deltas: 100% (159/159), done.

命令打开项目:

$ open UICatalog.xcodeproj/

2、模拟器上跑自动化

1)刚刚的项目在模拟器中进行编译:

点击红框

会自动启动模拟器:

2)然后拷贝项目app的xpath,来配置在参数中:

①拷贝到参数中

会报错:

Original error: '10.3.1' does not exist in the list of simctl SDKs. Only the following Simulator SDK versions are available on your system: 10.3, 12.0

意思是没有'10.3.1',只有'10.3、12.0'版本的SDK,所以手动修改:

又报错:

Original error: Could not create simulator with name 'appiumTest-iPhone7', device type id 'iPhone7' and runtime id '10.3.1'. Reason: 'simctl error running 'create': Invalid device type: iPhone7'

经过查询得知:

感谢:每天1990:《Appium1.6启动iOS真机》*很重要

解决方法:
Appium参数也必须设置udid,在启动的Desired Capabilities增加udid

②udid通过命令获取:

instruments -s devices

获取你打开的模拟器的id。

再运行session:

完整参数如下:

{
"platformName": "iOS",
"platformVersion": "10.3",
"deviceName": "iPhone7",
"automationName": "XCUITest",
"app": "/Users/xxx/Library/Developer/Xcode/DerivedData/UICatalog-hiixtcsjcynttngjfqlnzjjtpxkv/Build/Products/Debug-iphonesimulator/UICatalog.app",
"udid": "D3062BB8-5627-4867-8E97-AEDF6D953353"
}

3)并且输入地址:http://localhost:8100/inspector,也会有检查器显示。

4)设置log路径,如图:

①第一种在appium桌面程序设置log路径:

②第二种用命令行重新启动一个自己的appium(相当于新建一个appium服务5723)

输入命令:

$ appium -g /Users/xxx/Desktop/mine/Stu资料/Git/git—download/project/appium2.log -p 5723
[Appium] Welcome to Appium v1.9.1
[Appium] Non-default server args:
[Appium] port: 5723
[Appium] log: /Users/xxx/Desktop/mine/Stu资料/Git/git—download/project/appium2.log
[Appium] Appium REST http interface listener started on 0.0.0.0:5723

再设置参数启动:

同样可以启动app,并且生成appium2.log文件。

5)扩展:对Simulator控制

https://github.com/facebook/FBSimulatorControl/blob/master/fbsimctl/README.md

6)编写用例

利用IDEA编辑器,在之前《【Mac + Appium + Java1.8学习(一)】之Android自动化环境安装配置以及IDEA配置(附录扩展Selenium+Java自动化)》已经介绍如何使用配置IDEA。

之前在appium-desktop中可以自动生成代码,把它复制到IDEA中,如图:

但是,从现在开始先暂时不用appium-desktop,用XCode自带的查看元素工具。

如图步骤:

上代码:

解释=>findElementByAccessibilityId,如果包含name属性则可以使用。

参考官网:http://appium.io/docs/en/writing-running-appium/finding-elements/

package IOS_Simulator;

import io.appium.java_client.ios.IOSDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities; import java.net.MalformedURLException;
import java.net.URL; public class DemoTest { private IOSDriver driver; @Before
public void setUp() throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformName", "iOS");
desiredCapabilities.setCapability("platformVersion", "10.3");
desiredCapabilities.setCapability("deviceName", "iPhone7");
desiredCapabilities.setCapability("automationName", "XCUITest");
desiredCapabilities.setCapability("app", "/Users/xxx/Library/Developer/Xcode/DerivedData/UICatalog-hiixtcsjcynttngjfqlnzjjtpxkv/Build/Products/Debug-iphonesimulator/UICatalog.app");
desiredCapabilities.setCapability("udid", "D3062BB8-5627-4867-8E97-AEDF6D953353"); URL remoteUrl = new URL("http://127.0.0.1:4723/wd/hub"); driver = new IOSDriver(remoteUrl, desiredCapabilities);
} @Test
public void sampleTest() {
// MobileElement el1 = (MobileElement) driver.findElementByXPath("//XCUIElementTypeApplication[@name=\"UICatalog\"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTable/XCUIElementTypeCell[4]");
// el1.click();
// MobileElement el2 = (MobileElement) driver.findElementByXPath("(//XCUIElementTypeButton[@name=\"Button\"])[2]");
// el2.click();
driver.findElementByAccessibilityId("Buttons").click();
// driver.getPageSource().sout ===> System.out.println(driver.getPageSource());
System.out.println(driver.getPageSource());
driver.findElementByXPath("//*[@label='Button']").click();
driver.findElementByAccessibilityId("UICatalog").click();
} @After
public void tearDown() {
// driver.quit();
}
}

运行结果:

3、真机上跑自动化

真机官网地址说明:http://appium.io/docs/en/drivers/ios-xcuitest-real-devices/

1)配置参数

为了入门学习,还是要启动appium-desktop,完整参数:app参数有坑

{
"platformName": "iOS",
"platformVersion": "10.3",
"deviceName": "iPhone5s",
"automationName": "XCUITest",
"app": "/Users/xxx/Library/Developer/Xcode/DerivedData/UICatalog-hiixtcsjcynttngjfqlnzjjtpxkv/Build/Products/Debug-iphonesimulator/UICatalog.app",
"udid": "42ebab931b6b2d6a140b1a4f5bd55305dbfe2ff0"
}

启动session,报错:

Original error: Could not install app: 'Command 'ios-deploy --id 42ebab931b6b2d6a140b1a4f5bd55305dbfe2ff0 --bundle /Users/zhangc/Library/Developer/Xcode/DerivedData/UICatalog-hiixtcsjcynttngjfqlnzjjtpxkv/Build/Products/Debug-iphonesimulator/UICatalog.app' exited with code 253'

因为这个app当时是在模拟器进行的配置,所以我们还要配置真机,如下:

但是报错:

Signing for "UICatalog" requires a development team. Select a development team in the project editor. (in target 'UICatalog')

如图修改就不报错了:

再一次运行,真机配置安装app成功:

复制app的Path到appium-desktop的参数中:

启动session后,可以加载app,如图:

2)编写自动化脚本

(1)WebView自动化

需要安装以下几个命令:

①安装依赖库:libimobiledevice

brew install libimobiledevice --HEAD 

②安装ios-webkit-debug-proxy:

官网为:

https://github.com/google/ios-webkit-debug-proxy

http://appium.io/docs/en/writing-running-appium/web/ios-webkit-debug-proxy/

# 调试转换
brew install ios-webkit-debug-proxy

并且IOS手机设置一下Web检查器:设置->safari浏览器->高级->Web检查器->打开

# 扩展:手机截图
idevicescreenshot

安装完成后,进行appium-desktop参数配置:

{
"platformName": "iOS",
"platformVersion": "10.3",
"deviceName": "iPhone5s",
"automationName": "XCUITest",
"udid": "auto",  # 默认第一台连接设备
"startIWDP": true,
"browserName": "Safari"
}

启动session后,成功:

③编写脚本

package IOS.Real;

import io.appium.java_client.ios.IOSDriver;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities; import java.net.MalformedURLException;
import java.net.URL; public class DemoTest_WebView { private IOSDriver driver; @Before
public void setUp() throws MalformedURLException {
DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("platformName", "iOS");
// desiredCapabilities.setCapability("platformVersion", "10.3");
desiredCapabilities.setCapability("deviceName", "auto");
desiredCapabilities.setCapability("automationName", "XCUITest");
desiredCapabilities.setCapability("udid", "auto");
desiredCapabilities.setCapability("startIWDP", true);
desiredCapabilities.setCapability("browserName", "Safari");
// 42ebab931b6b2d6a140b1a4f5bd55305dbfe2ff0
URL remoteUrl = new URL("http://localhost:4723/wd/hub"); driver = new IOSDriver(remoteUrl, desiredCapabilities);
} @Test
public void web(){
driver.get("https://testerhome.com");
driver.findElementByXPath("//*[contains(@title,'北京管理沙龙')]").click();
// driver.get("https://appium.io/");
// driver.findElementByXPath("(//XCUIElementTypeOther[@name=\"导航\"])[1]").click();
} @After
public void tearDown() {
// driver.quit();
}
}

运行代码后一直报错,后来经过痛苦的查询得知:

参考解决地址:《AppiumDriver driver = new AppiumDriver 的AppiumDriver报错问题解决

WebDriverException: An unknown server-side error occurred while processing the command. Original error: Unhandled endpoint 

错误日志:org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Unhandled endpoint: /session/763C2E9E-9078-4931-BDF3-A05C2E3AF2E5/wda/screen -- http://localhost:8100/ with parameters {
wildcards = (
"session/763C2E9E-9078-4931-BDF3-A05C2E3AF2E5/wda/screen"
);
}

代码执行到这里就报错:

driver = new IOSDriver(remoteUrl, desiredCapabilities);

因为使用的appium-client版本太高导致的,后来在Maven中由6.1.0版本降到5.0.4版本再运行就好了

p.p1 { margin: 0 0 0 12px; text-indent: -12px; font: 11px Menlo; color: rgba(0, 0, 0, 0.85); min-height: 13px }
p.p2 { margin: 0 0 0 12px; text-indent: -12px; font: 11px Menlo; color: rgba(0, 0, 0, 0.85) }

【Mac + Appium + Java1.8(三)】之IOS自动化环境安装配置以及简单测试用例编写(模拟器、真机)的更多相关文章

  1. 解决MAC Appium设备连不上IOS的的问题'idevice_id' program is not installed

    解决MAC Appium设备连不上IOS的的问题 错误的: [XCUITest] The 'idevice_id' program is not installed. If you are runni ...

  2. iOS自动化环境搭建——macaca

    macaca-java for ios 自动化环境搭建 基础原理解析:https://testerhome.com/topics/6608 一.环境搭建 1.安装eclipse; -----Java开 ...

  3. iOS 11开发教程(九)iOS11数据线连接真机测试

    iOS 11开发教程(九)iOS11数据线连接真机测试 在Xcode 7.0之后,苹果公司在开发许可权限上做了很多的改变,在测试App方面取消了一些限制.在Xcode7.0之前的版本,苹果公司只向注册 ...

  4. python-web自动化环境安装

    web自动化环境安装 1.安装selenium 命令行使用以下命令安装selenium:pip install -U selenium 2.安装chrome浏览器 3.chromedriver的下载  ...

  5. C#实现多级子目录Zip压缩解压实例 NET4.6下的UTC时间转换 [译]ASP.NET Core Web API 中使用Oracle数据库和Dapper看这篇就够了 asp.Net Core免费开源分布式异常日志收集框架Exceptionless安装配置以及简单使用图文教程 asp.net core异步进行新增操作并且需要判断某些字段是否重复的三种解决方案 .NET Core开发日志

    C#实现多级子目录Zip压缩解压实例 参考 https://blog.csdn.net/lki_suidongdong/article/details/20942977 重点: 实现多级子目录的压缩, ...

  6. iOS自动化环境搭建(超详细)

    1.macOS相关库安装 libimobiledevice > brew install libimobiledevice 使用本机与苹果iOS设备的服务进行通信的库. ideviceinsta ...

  7. appium 使用环境安装配置记录

    一.安装配置Java (cmd输入java,回车,没有出现“不是内部或外部命令,也不是可运行的程序或批处理文件”,即为成功) 二.安装node.js (cmd输入node -v,显示版本号即为成功) ...

  8. Delphi IOS开发环境安装

    RAD Delphi XE/10 Seattle 安装IOS.OSX环境安装,IOS模拟器,MAC X 真机可以调试 http://community.embarcadero.com/blogs/en ...

  9. iOS系列 基础篇 01 构建HelloWorld,剖析并真机测试

    iOS基础 01 构建HelloWorld,剖析并真机测试 前言: 从控制台输出HelloWorld是我们学习各种语言的第一步,也是我们人生中非常重要的一步. 多年之后,我希望我们仍能怀有学习上进的心 ...

  10. iOS - MySQL 的安装配置

    前言 提前下载好相关软件,且安装目录最好安装在全英文路径下.如果路径有中文名,那么可能会出现一些莫名其妙的问题. 提前准备好的软件: mysql-5.7.17-macos10.12-x86_64.dm ...

随机推荐

  1. 动环监控方案,为什么推荐79元全志T113-i国产平台?

    什么是动环监控系统? 通信电源及机房环境监控系统(简称"动环监控系统"),是对分布在各机房的电源柜.UPS.空调.蓄电池等多种动力设备,及门磁.红外.窗破.水浸.温湿度.烟感等机房 ...

  2. SpringCloud学习篇

    什么是SpringCloud Spring cloud 流应用程序启动器是基于 Spring Boot 的 Spring 集成应用程序,提供与外部系统的集成.Spring cloud Task,一个生 ...

  3. Oracle 触发器 before insert update

    场景,往A表插入数据时,A表和B表是同一类型的状态下,A表中累计的值,不能超过B表中的值(注:往数据库插入时,不能批量执行事务!),利用触发器before insert update,监控状态,若超过 ...

  4. WPF/C#:在WPF中如何实现依赖注入

    前言 本文通过 WPF Gallery 这个项目学习依赖注入的相关概念与如何在WPF中进行依赖注入. 什么是依赖注入 依赖注入(Dependency Injection,简称DI)是一种设计模式,用于 ...

  5. 3.1 Y86-64指令集体系结构

    程序员可见的状态 这里的程序员即可以是用汇编代码写程序的人,也可以是产生机器级代码的编译器.程序员可见的状态如下,有15个程序寄存器(%rax,%rbx等),三个一位的条件(ZF,OF,SF) ,程序 ...

  6. [oeasy]python0048_注释_comment_设置默认编码格式

    注释Comment 回忆上次内容 使用了版本控制 git 制作备份 进行回滚   尝试了 嵌套的控制结构 层层 控制   不过 除非 到不得以 尽量不要 太多层次的嵌套   这样 从顶到底 含义 明确 ...

  7. [oeasy]python0128_unicode_字符集_character_set_八卦_星座

    unicode 回忆上次内容 中国的简体和繁体汉字 字符数量都超级大 彼此还认对方为乱码   如果有一种编码所有的字符都能编进去就好了 中日韩(CJK) 欧洲拼音 梵文 阿拉伯文 卢恩字符 等等等都包 ...

  8. 企业级环境部署:在 Linux 服务器上如何搭建和部署 Python 环境?

    在大部分企业里,自动化测试框架落地都肯定会集成到Jenkins服务器上做持续集成测试,自动构建以及发送结果到邮箱,实现真正的无人值守测试. 不过Jenkins搭建一般都会部署在公司的服务器上,不会在私 ...

  9. 浅谈:HTTP 和 HTTPS 通信原理

    1.HTTP基本概念 1.1 HTTP是什么?  HTTP (超文本传输协议)协议被用于在 Web 浏览器和网站服务器之间传递信息, HTTP 协议以明文方式发送内容,不提供任何方式的数据加密,如果攻 ...

  10. 阅读翻译Mathematics for Machine Learning之2.5 Linear Independence

    阅读翻译Mathematics for Machine Learning之2.5 Linear Independence 关于: 首次发表日期:2024-07-18 Mathematics for M ...