MAC+appium自动化测试

 

参考地址:https://www.cnblogs.com/we8fans/p/7384291.html

Mac+appiumhttps://blog.csdn.net/u011517841/article/details/54923872

 

Mac os虚拟:https://jingyan.baidu.com/article/c74d6000b3ca190f6a595d37.html

 

Mac上搭建appiumhttps://testerhome.com/topics/6962

https://blog.csdn.net/u010742414/article/details/76439147    严格按步骤安装

 

搭建ios WebDriverAgent及 启动虚拟机:https://testerhome.com/topics/7861

 

设置成nat模式:https://jingyan.baidu.com/article/e8cdb32b4217e737052baddb.html

 

Appium+java+testng+Mac环境搭建:https://www.jianshu.com/p/dcf446c2d616

 

Mac os下载:https://support.apple.com/zh_CN/downloads/macos

 

ISOappium inspector定位元素:

 

选择Automatic Server或者Custom Server进行如下配置,均可以实现定位配置

{

"platformName":"iOS",

"platformVersion":"11.2",

"deviceName":"iPhone 7",

"bundleId":"com.tc.HelloWorld",

"automationName":"XCUITest"

}

指定系统,版本,设备,app或者是AppbundleId之后,即可开始定位元素

Appium iOS 简易配置  https://testerhome.com/topics/3805

通过以上链接提供的方法找到 appPath之后,就可以建立会话了,会话建立成功后可以进行定位

1.创建手机模拟器

Xcode中运行一个应用,会自动创建手机模拟器,如下图就是自己实现一个简单的app,运行得到模拟器

 

定位元素如上图,可以找到要操作的元素的id,或是name或是xpath进行定位,找到要操作的内容

 

编写测试脚本,如下例:

 

package testIos;

 

import java.io.File;

import java.net.MalformedURLException;

import java.net.URL;

import java.util.concurrent.TimeUnit;

 

import org.openqa.selenium.By;

import org.openqa.selenium.remote.DesiredCapabilities;

 

import io.appium.java_client.AppiumDriver;

import io.appium.java_client.ios.IOSDriver;

 

public class TestIOS {

private static IOSDriver driver = null;

 

public static void main(String[] args) {

//                File classpathRoot = new File(System.getProperty("user.dir"));

File classpathRoot = new File ("/Users/macos/Library/Developer/Xcode/DerivedData/HelloWorld-dvviwzyynfqossaphbzqkbjdmcjk/Build/Products/Debug-iphonesimulator/HelloWorld.app");

//                File appDir = new File(classpathRoot, "apps");

 

//                File app = new File(classpathRoot);

 

///Users/sks/Library/Developer/Xcode/DerivedData/YCMath345-iOS-gswmmorclgkffeevdytydhjkdhjk/Build/Products/Debug-iphonesimulator/YCMath345-iOS.app

 

System.out.println("设置路径完毕");

 

//设置自动化相关参数

 

DesiredCapabilities capabilities = new DesiredCapabilities();

 

capabilities.setCapability("appium-version", "1.6.3");

 

capabilities.setCapability("platformVersion", "11.2");

 

capabilities.setCapability("platformName", "iOS");

 

capabilities.setCapability("deviceName", "iPhone 8 Plus");

 

capabilities.setCapability("budnleId", "com.tc.HelloWorld");

 

capabilities.setCapability("automationName", "XCUITest");

 

System.out.println("设置自动化相关参数");

 

//设置apk路径

capabilities.setCapability("app", classpathRoot.getAbsolutePath());

try {

driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

} catch (MalformedURLException e) {

e.printStackTrace();

}

//设置等待秒数

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

 

System.out.println("初始化 AppiumDriver");

//String button = "XCUIElementTypeButton[@name='Set Default Label Text']";

////XCUIElementTypeApplication[@name="HelloWorld"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField/XCUIElementTypeTextField

String button = "XCUIElementTypeApplication[@name=\"HelloWorld\"]/XCUIElementTypeWindow[1]/XCUIElementTypeOther/XCUIElementTypeOther/XCUIElementTypeTextField/XCUIElementTypeTextField";

driver.findElementByXPath(button).click();

 

System.out.println("设置了线程休眠20秒....");

 

//线程睡眠,ms

 

try {

Thread.sleep(20000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

 

//driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

 

System.out.println("视频播放20秒后");

 

// driver.wait(10);

 

System.out.println("Session One-First case-End!");

driver.quit();

 

}

}

 

 

  1. 操作过程:

1.app store下载 app,导入Xcode编译, 记得修改 Bundle ID为唯一

会将App编译安装到 手机模拟器上,同时启动手机模拟器

2.设置appium inspector 如上图,启动会话,会话启动成功后 可定位元素

以键值对的形式,设置模拟器,平台,版本,待测App包路径等

3.eclipse中实现测试代码,引入java-client和selenium jar包

3.本地与虚拟机之间传递文件

 

 

 

 

 

展开阅读全文

没有更多推荐了,返回首页