Mac自动化环境

1. JDK安装

  •  下载JDK for Mac 我这里使用的是  jdk-7u79-macosx-x64.dmg
  •  验证安装open Terminal 
     java -version
    java version "1.7.0_79"
    Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode 

2. xcode安装

  •  下载xcode  需要 Apple 开发者账号 
  • 注意 Mac的 OS的版本和对应Xcode要匹配 
  •  创建iOS simulater ,如果这样说明iOS设备准备完毕
    复制代码
    Youngs-Mac:~ root# instruments -s devices
    Known Devices:
    Young’s Mac [564D792F-BB12-9F15-EF80-A723B921B505]
    Resizable iPad (8.4 Simulator) [B477C6F2-F8A9-4CE1-9889-C7BB1518D0B9]
    Resizable iPhone (8.4 Simulator) [56007C43-7BAB-4C7A-BA5B-E42DEE41C4B4]
    iPad 2 (8.4 Simulator) [D69DF503-8F09-47EB-AC67-385FFACC01D1]
    iPad Air (8.4 Simulator) [D9E1F7CE-A110-4167-B6C8-F50EA83B8CDC]
    iPad Retina (8.4 Simulator) [C704AFE0-BC72-4AAF-8B51-7CEE0D021355]
    iPhone 4s (8.4 Simulator) [D03258C7-8619-4BA2-8EAB-6D88EAFE641C]
    iPhone 5 (8.4 Simulator) [2C39AE81-2B7D-48FC-B6C9-52203A53A560]
    iPhone 5s (8.4 Simulator) [A66F0F82-AB4C-4BAC-B466-9BF44FC7B03C]
    iPhone 6 (8.4 Simulator) [C8395C58-5164-406B-9DF8-47BAE209EC25]
    iPhone 6 Plus (8.4 Simulator) [51C387A1-B77E-4BE4-99E0-BBA1F95E9789]
    复制代码

     

3. NodeJS安装

4. Appium 安装

 

5. 设置环境变量

vi ~/.bash_profile,将环境变量设置如下:

 

1
2
3
4
5
6
export PATH="/Applications/Appium.app/Contents/Resources/node/bin/":$PATH
export PATH="/Applications/Appium.app/Contents/Resources/node_modules/appium/bin/":$PATH
export ANDROID_HOME="/Users/young/Library/Android/sdk"
export PATH="/Users/young/Library/Android/sdk/platform-tools":$PATH
export PATH="/Users/young/Library/Android/sdk/tools":$PATH
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home"

 

  设置完毕保存,别忘了source该文件使其立即生效

 

6. 使用Appium example demo

 

7. 创建测试用例

  •  打开eclipse,添加如下代码:

  

复制代码
package com.dbyl.core;


import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import io.appium.java_client.ios.IOSDriver;

import java.io.File;

import java.net.URL;

import java.util.concurrent.TimeUnit;

public class iOSTest {
    private IOSDriver driver;
    private boolean isInstall = true;

     
    @BeforeClass(alwaysRun = true)
    public void setUp() throws Exception {
        // set up appium

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
        capabilities.setCapability("platformName", "Mac");
        capabilities.setCapability("deviceName", "iPhone 6");
        capabilities.setCapability("platformVersion", "8.4");
        // if no need install don't add this
        if (isInstall) {
            File classpathRoot = new File(System.getProperty("user.dir"));
            File appDir = new File(classpathRoot, "apps");
            File app = new File(appDir, "TestApp.app");
            System.out.println("---->"+app.getAbsolutePath());
            capabilities.setCapability("app", app.getAbsolutePath());
        }

        // support Chinese
        capabilities.setCapability("unicodeKeyboard", "True");
        capabilities.setCapability("resetKeyboard", "True");
    
        driver = new IOSDriver (new URL("http://127.0.0.1:4723/wd/hub"),
                capabilities);
         
    }

    @Test
    public void login() {

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

        // find login userName and password editText
        WebElement inputbox1 =driver.findElementByName("TextField1");
        inputbox1.sendKeys("12");
        
        WebElement inputbox2 =driver.findElementByName("TextField2");
        inputbox2.sendKeys("65");
        
        WebElement calcButton=driver.findElementByXPath("//UIAApplication[1]/UIAWindow[2]/UIAButton[1]");
        
        calcButton.click();
        WebElement result=driver.findElementByXPath("//UIAApplication[1]/UIAWindow[2]/UIAStaticText[1]");
        Assert.assertEquals(result.getAttribute("value"), "77");
    }
 

    @AfterClass(alwaysRun = true)
    public void tearDown() throws Exception {
        driver.quit();
    }
 
}
复制代码

 

8. 相关资料

视频教程:https://www.youtube.com/watch?v=BULjgsTpw2c

代码:https://github.com/tobecrazy/appiumDemo

posted @ 2019-01-23 16:52  汉魂县令  阅读(297)  评论(0编辑  收藏  举报