Skip to content

Instantly share code, notes, and snippets.

@maesiva
Created February 1, 2017 21:47
Show Gist options
  • Save maesiva/db47d4b9fccdabd43e406b08bcb55abe to your computer and use it in GitHub Desktop.
Save maesiva/db47d4b9fccdabd43e406b08bcb55abe to your computer and use it in GitHub Desktop.
iOS 10 Appium 1.6.3
Test Code:
===========
import io.appium.java_client.ios.IOSDriver;
import java.net.URL;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class iOSLogin {
private IOSDriver driver;
@BeforeClass
public void setUpClass() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("app", "/Users/myUser/mobile_app/myApp.app");
capabilities.setCapability("device", "iPad");
capabilities.setCapability("udid", "myUDID");
capabilities.setCapability("deviceName", "iPad Air 2");
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "10.0.2");
capabilities.setCapability("automationName", "XCUITest");
// capabilities.setCapability("orientation", "LANDSCAPE");
// capabilities.setCapability("autoWebView", "true");
capabilities.setCapability("fullReset", "false");
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(8000);
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println("contextName: " + contextName);
if (contextName.contains("WEBVIEW")) {
driver.context(contextName);
System.out.println("set context: " + contextName);
}
}
Thread.sleep(5000);
//Login
driver.findElement(By.id("loginid")).sendKeys("user22");
driver.findElement(By.id("password")).sendKeys("pwd22");
driver.findElement(By.id("btnlogin")).click();
Thread.sleep(4000);
// System.out.println("\n\n" + driver.getPageSource() + "\n\n");
System.out.println("iOSLogin.setUpClass().. exit");
}
@AfterClass
public void tearDownClass() throws Exception {
System.out.println("iOSLogin.tearDownClass()... quit driver...");
// driver.quit();
}
}
Appium server logs:
===============
rbcmyMac:~ myUser$
carbcmyMac:~ myUser$ appium --address 127.0.0.1
[Appium] Welcome to Appium v1.6.3
[Appium] Non-default server args:
[Appium] address: '127.0.0.1'
[Appium] Appium REST http interface listener started on 127.0.0.1:4723
[HTTP] --> POST /wd/hub/session {"capabilities":{"desiredCapabilities":{"app":"/Users/myUser/mobile_app/myApp.app","platformVersion":"10.0.2","automationName":"XCUITest","udid":"myUDID","platformName":"iOS","device":"iPad","deviceName":"iPad Air 2","fullReset":"false"},"requiredCapabilities":{}},"desiredCapabilities":{"app":"/Users/myUser/mobile_app/myApp.app","platformVersion":"10.0.2","automationName":"XCUITest","udid":"myUDID","platformName":"iOS","device":"iPad","deviceName":"iPad Air 2","fullReset":"false"},"requiredCapabilities":{}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"app":"/Users/myUser/mobile_app/myApp.app","platformVersion":"10.0.2","automationName":"XCUITest","udid":"myUDID","platformName":"iOS","device":"iPad","deviceName":"iPad Air 2","fullReset":"false"},{},{"desiredCapabilities":{"app":"/Users/myUser/mobile_app/myApp.app","platformVersion":"10.0.2","automationName":"XCUITest","udid":"myUDID","platformName":"iOS","device":"iPad","deviceName":"iPad Air 2","fullReset":"false"},"requiredCapabilities":{}},null,null]
[Appium] Creating new XCUITestDriver session
[Appium] Capabilities:
[Appium] app: '/Users/myUser/mobile_app/myApp.app'
[Appium] platformVersion: '10.0.2'
[Appium] automationName: 'XCUITest'
[Appium] udid: 'myUDID'
[Appium] platformName: 'iOS'
[Appium] device: 'iPad'
[Appium] deviceName: 'iPad Air 2'
[Appium] fullReset: 'false'
[debug] [XCUITest] XCUITestDriver version: 2.6.0
[BaseDriver] Capability 'fullReset' changed from string to boolean. This may cause unexpected behavior
[BaseDriver] The following capabilities were provided, but are not recognized by appium: device.
[BaseDriver] Session created with session id: 9f2d5daa-98d3-429f-a694-3fe47c7bcc82
[debug] [XCUITest] Xcode version set to '8.0'
[debug] [XCUITest] iOS SDK Version set to '10.0'
[debug] [XCUITest] Available devices: myUDID
[debug] [XCUITest] Creating iDevice object with udid myUDID
[XCUITest] Determining device to run tests on: udid: 'myUDID', real device: true
[BaseDriver] Using local app '/Users/myUser/mobile_app/myApp.app'
[debug] [XCUITest] Checking whether app '/Users/myUser/mobile_app/myApp.app' is actually present on file system
[debug] [XCUITest] App is present
[debug] [iOS] Getting bundle ID from app '/Users/myUser/mobile_app/myApp.app': 'com.company.myService'
[debug] [iOSLog] Attempting iOS device log capture via libimobiledevice idevicesyslog
[debug] [iOSLog] Found idevicesyslog: '/usr/local/bin/idevicesyslog'
[XCUITest] Setting up real device
[debug] [XCUITest] App is already installed.
[debug] [XCUITest] Full reset not requested. No need to install.
[XCUITest] Using WDA path: '/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent'
[XCUITest] Using WDA agent: '/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj'
[XCUITest] Launching WebDriverAgent on the device
[debug] [XCUITest] Carthage found: '/usr/local/bin/carthage'
[debug] [XCUITest] Killing hanging processes
[debug] [XCUITest] Beginning test with command 'xcodebuild build-for-testing test-without-building -project /usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent/WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination id=myUDID -configuration Debug' in directory '/usr/local/lib/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent'
[debug] [XCUITest] Starting iproxy to forward traffic from local port 8100 to device port 8100 over USB
[debug] [XCUITest] Waiting up to 60000ms for WebDriverAgent to start
[debug] [XCUITest] WebDriverAgent successfully started after 2368ms
[debug] [XCUITest] Sending createSession command to WDA
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8100/session] with body: {"desiredCapabilities":{"bundleId":"com.company.myService","arguments":[],"environment":{},"shouldWaitForQuiescence":true}}
[debug] [XCUITest] Log file for xcodebuild test: /Users/myUser/Library/Developer/Xcode/DerivedData/WebDriverAgent-brdadhpuduowllgivnnvuygpwhzy/Logs/Test/F5C474C4-15D5-4F6F-956C-C8CFD1A95FFF/Session-WebDriverAgentRunner-2017-02-01_132118-PwkQsN.log
[debug] [XCUITest] Failed to create session. Retrying...
[debug] [XCUITest] Sending createSession command to WDA
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8100/session] with body: {"desiredCapabilities":{"bundleId":"com.company.myService","arguments":[],"environment":{},"shouldWaitForQuiescence":true}}
[debug] [XCUITest] Failed to create session. Retrying...
[debug] [XCUITest] Sending createSession command to WDA
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8100/session] with body: {"desiredCapabilities":{"bundleId":"com.company.myService","arguments":[],"environment":{},"shouldWaitForQuiescence":true}}
[debug] [XCUITest] Failed to create session. Retrying...
[debug] [XCUITest] Sending createSession command to WDA
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8100/session] with body: {"desiredCapabilities":{"bundleId":"com.company.myService","arguments":[],"environment":{},"shouldWaitForQuiescence":true}}
[debug] [XCUITest] Failed to create session. Retrying...
[debug] [XCUITest] Sending createSession command to WDA
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8100/session] with body: {"desiredCapabilities":{"bundleId":"com.company.myService","arguments":[],"environment":{},"shouldWaitForQuiescence":true}}
[debug] [XCUITest] Failed to create session. Retrying...
[debug] [XCUITest] Sending createSession command to WDA
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8100/session] with body: {"desiredCapabilities":{"bundleId":"com.company.myService","arguments":[],"environment":{},"shouldWaitForQuiescence":true}}
[debug] [XCUITest] Failed to create session. Retrying...
[debug] [XCUITest] Sending createSession command to WDA
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8100/session] with body: {"desiredCapabilities":{"bundleId":"com.company.myService","arguments":[],"environment":{},"shouldWaitForQuiescence":true}}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{"sessionId":"C17675F0-41F8-4D64-8F18-8315065FBBAF","capabilities":{"device":"ipad","browserName":"Mobile 2016","sdkVersion":"10.0.2","CFBundleIdentifier":"com.company.myService"}},"sessionId":"C17675F0-41F8-4D64-8F18-8315065FBBAF","status":0}
[debug] [XCUITest] Setting initial orientation to 'PORTRAIT'
[debug] [JSONWP Proxy] Proxying [POST /orientation] to [POST http://localhost:8100/session/C17675F0-41F8-4D64-8F18-8315065FBBAF/orientation] with body: {"orientation":"PORTRAIT"}
[debug] [JSONWP Proxy] Got response with status 200: {"value":{},"sessionId":"C17675F0-41F8-4D64-8F18-8315065FBBAF","status":0}
[Appium] New XCUITestDriver session created successfully, session 9f2d5daa-98d3-429f-a694-3fe47c7bcc82 added to master session list
[debug] [MJSONWP] Responding to client with driver.createSession() result: {"webStorageEnabled":false,"locationContextEnabled":false,"browserName":"","platform":"MAC","javascriptEnabled":true,"databaseEnabled":false,"takesScreenshot":true,"networkConnectionEnabled":false,"app":"/Users/myUser/mobile_app/myApp.app","platformVersion":"10.0.2","automationName":"XCUITest","udid":"myUDID","platformName":"iOS","device":"iPad","deviceName":"iPad Air 2","fullReset":"false"}
[HTTP] <-- POST /wd/hub/session 200 18110 ms - 514
[HTTP] --> GET /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/contexts {}
[debug] [MJSONWP] Calling AppiumDriver.getContexts() with args: ["9f2d5daa-98d3-429f-a694-3fe47c7bcc82"]
[debug] [XCUITest] Executing command 'getContexts'
[debug] [iOS] Getting list of available contexts
[debug] [iOS] Retrieving contexts and views
[debug] [iOS] Selecting by url: false
[debug] [RemoteDebugger] Getting WebKitRemoteDebugger pageArray: localhost, 27753
[debug] [RemoteDebugger] Sending request to: http://localhost:27753/json
[debug] [RemoteDebugger] Page element JSON: [{"devtoolsFrontendUrl":"/devtools/devtools.html?ws=localhost:27753/devtools/page/1","faviconUrl":"","thumbnailUrl":"/thumb/file:///var/containers/Bundle/Application/9BEFE40A-9004-4463-9AE7-011CCC564373/myApp.app/www/index.html","title":"mobile","url":"file:///var/containers/Bundle/Application/9BEFE40A-9004-4463-9AE7-011CCC564373/myApp.app/www/index.html","webSocketDebuggerUrl":"ws://localhost:27753/devtools/page/1","appId":"PID:2818"},{"devtoolsFrontendUrl":"/devtools/devtools.html?ws=localhost:27753/devtools/page/2","faviconUrl":"","thumbnailUrl":"/thumb/","title":"JSContext","url":"","webSocketDebuggerUrl":"ws://localhost:27753/devtools/page/2","appId":"PID:2818"}]
[debug] [MJSONWP] Responding to client with driver.getContexts() result: ["NATIVE_APP","WEBVIEW_1"]
[HTTP] <-- GET /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/contexts 200 18 ms - 98
[HTTP] --> POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/context {"name":"WEBVIEW_1"}
[debug] [MJSONWP] Calling AppiumDriver.setContext() with args: ["WEBVIEW_1","9f2d5daa-98d3-429f-a694-3fe47c7bcc82"]
[debug] [XCUITest] Executing command 'setContext'
[debug] [iOS] Attempting to set context to 'WEBVIEW_1'
[debug] [RemoteDebugger] WebKit debugger web socket connected to url: ws://localhost:27753/devtools/page/1
[debug] [MJSONWP] Responding to client with driver.setContext() result: null
[HTTP] <-- POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/context 200 16 ms - 76
[HTTP] --> POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element {"using":"id","value":"loginid"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["id","loginid","9f2d5daa-98d3-429f-a694-3fe47c7bcc82"]
[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, accessibility id
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [RemoteDebugger] Executing 'find_element' atom in default context
[debug] [RemoteDebugger] Sending javascript command (function(){return function(){var aa="function"...
[debug] [RemoteDebugger] Sending WebKit data: {"method":"Runtime.evaluate...
[debug] [RemoteDebugger] Receiving WebKit data: {"result":{"result":{"type"...
[debug] [RemoteDebugger] Found handler for message '1'
[debug] [RemoteDebugger] Received result for atom 'find_element' execution: {"ELEMENT":":wdc:1485984053439"}
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"5000"}
[HTTP] <-- POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element 200 95 ms - 90
[HTTP] --> POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element/5000/value {"id":"5000","value":["user22"]}
[debug] [MJSONWP] Calling AppiumDriver.setValue() with args: [["user22"],"5000","9f2d5daa-98d3-429f-a694-3fe47c7bcc82"]
[debug] [XCUITest] Executing command 'setValue'
[debug] [RemoteDebugger] Executing 'click' atom in default context
[debug] [RemoteDebugger] Sending javascript command (function(){return function(){var k,aa="functio...
[debug] [RemoteDebugger] Sending WebKit data: {"method":"Runtime.evaluate...
[debug] [RemoteDebugger] Receiving WebKit data: {"result":{"result":{"type"...
[debug] [RemoteDebugger] Found handler for message '2'
[debug] [RemoteDebugger] Received result for atom 'click' execution: null
[debug] [RemoteDebugger] Executing 'type' atom in default context
[debug] [RemoteDebugger] Sending javascript command (function(){return function(){var h,aa="functio...
[debug] [RemoteDebugger] Sending WebKit data: {"method":"Runtime.evaluate...
[debug] [RemoteDebugger] Receiving WebKit data: {"result":{"result":{"type"...
[debug] [RemoteDebugger] Found handler for message '3'
[debug] [RemoteDebugger] Received result for atom 'type' execution: null
[debug] [MJSONWP] Responding to client with driver.setValue() result: null
[HTTP] <-- POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element/5000/value 200 160 ms - 76
[HTTP] --> POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element {"using":"id","value":"password"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["id","password","9f2d5daa-98d3-429f-a694-3fe47c7bcc82"]
[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, accessibility id
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [RemoteDebugger] Executing 'find_element' atom in default context
[debug] [RemoteDebugger] Sending javascript command (function(){return function(){var aa="function"...
[debug] [RemoteDebugger] Sending WebKit data: {"method":"Runtime.evaluate...
[debug] [RemoteDebugger] Receiving WebKit data: {"result":{"result":{"type"...
[debug] [RemoteDebugger] Found handler for message '4'
[debug] [RemoteDebugger] Received result for atom 'find_element' execution: {"ELEMENT":":wdc:1485984053440"}
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"5001"}
[HTTP] <-- POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element 200 33 ms - 90
[HTTP] --> POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element/5001/value {"id":"5001","value":["pwd22"]}
[debug] [MJSONWP] Calling AppiumDriver.setValue() with args: [["pwd22"],"5001","9f2d5daa-98d3-429f-a694-3fe47c7bcc82"]
[debug] [XCUITest] Executing command 'setValue'
[debug] [RemoteDebugger] Executing 'click' atom in default context
[debug] [RemoteDebugger] Sending javascript command (function(){return function(){var k,aa="functio...
[debug] [RemoteDebugger] Sending WebKit data: {"method":"Runtime.evaluate...
[debug] [RemoteDebugger] Receiving WebKit data: {"result":{"result":{"type"...
[debug] [RemoteDebugger] Found handler for message '5'
[debug] [RemoteDebugger] Received result for atom 'click' execution: null
[debug] [RemoteDebugger] Executing 'type' atom in default context
[debug] [RemoteDebugger] Sending javascript command (function(){return function(){var h,aa="functio...
[debug] [RemoteDebugger] Sending WebKit data: {"method":"Runtime.evaluate...
[debug] [RemoteDebugger] Receiving WebKit data: {"result":{"result":{"type"...
[debug] [RemoteDebugger] Found handler for message '6'
[debug] [RemoteDebugger] Received result for atom 'type' execution: null
[debug] [MJSONWP] Responding to client with driver.setValue() result: null
[HTTP] <-- POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element/5001/value 200 101 ms - 76
[HTTP] --> POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element {"using":"id","value":"btnlogin"}
[debug] [MJSONWP] Calling AppiumDriver.findElement() with args: ["id","btnlogin","9f2d5daa-98d3-429f-a694-3fe47c7bcc82"]
[debug] [XCUITest] Executing command 'findElement'
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, accessibility id
[debug] [BaseDriver] Waiting up to 0 ms for condition
[debug] [RemoteDebugger] Executing 'find_element' atom in default context
[debug] [RemoteDebugger] Sending javascript command (function(){return function(){var aa="function"...
[debug] [RemoteDebugger] Sending WebKit data: {"method":"Runtime.evaluate...
[debug] [RemoteDebugger] Receiving WebKit data: {"result":{"result":{"type"...
[debug] [RemoteDebugger] Found handler for message '7'
[debug] [RemoteDebugger] Received result for atom 'find_element' execution: {"ELEMENT":":wdc:1485984053441"}
[debug] [MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"5002"}
[HTTP] <-- POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element 200 34 ms - 90
[HTTP] --> POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element/5002/click {"id":"5002"}
[debug] [MJSONWP] Calling AppiumDriver.click() with args: ["5002","9f2d5daa-98d3-429f-a694-3fe47c7bcc82"]
[debug] [XCUITest] Executing command 'click'
[debug] [RemoteDebugger] Executing 'click' atom in default context
[debug] [RemoteDebugger] Sending javascript command (function(){return function(){var k,aa="functio...
[debug] [RemoteDebugger] Sending WebKit data: {"method":"Runtime.evaluate...
[debug] [RemoteDebugger] Receiving WebKit data: {"result":{"result":{"type"...
[debug] [RemoteDebugger] Found handler for message '8'
[debug] [RemoteDebugger] Received result for atom 'click' execution: null
[debug] [MJSONWP] Responding to client with driver.click() result: null
[HTTP] <-- POST /wd/hub/session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82/element/5002/click 200 44 ms - 76
[debug] [XCUITest] Connection to WDA timed out
[debug] [iProxy] recv failed: Operation not permitted
[BaseDriver] Shutting down because we waited 60 seconds for a command
[debug] [JSONWP Proxy] Proxying [DELETE /session/9f2d5daa-98d3-429f-a694-3fe47c7bcc82] to [DELETE http://localhost:8100/session/C17675F0-41F8-4D64-8F18-8315065FBBAF] with no body
[Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability'
[Appium] Removing session 9f2d5daa-98d3-429f-a694-3fe47c7bcc82 from our master session list
[debug] [JSONWP Proxy] Got response with status 200: "{\n \"value\" : {\n\n },\n \"sessionId\" : \"4E59E98D-3053-445B-81F4-351332BA39B8\",\n \"status\" : 0\n}"
[XCUITest] Shutting down sub-processes
[XCUITest] Shutting down xcodebuild process (pid 2142)
[XCUITest] xcodebuild exited with code 'null' and signal 'SIGTERM'
[XCUITest] Shutting down iproxy process (pid 2140)
[debug] [XCUITest] iproxy exited with code 'null'
[debug] [XCUITest] In a web session. Removing remote debugger
[debug] [RemoteDebugger] Disconnecting from WebKit remote debugger
[debug] [XCUITest] Running ios real device reset flow
[debug] [iOSLog] Stopping iOS log capture
[debug] [RemoteDebugger] WebKit remote debugger socket disconnected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment