Guides

Appium Beginner Tutorial 16 | How to create iOS automation testing project in java



FREE courses – https://automationstepbystep.com/online-courses/
1. IDE (Eclipse)
2. Appium java library
3. Selenium java library
4. Desired Capabilities
5. iOS device or simulator
by: Raghav Pal

Step 1 : Open IDE (eclipse)

Step 2 : Create a new maven project or use any existing maven project

Step 3 : Add maven dependencies
appium java client
selenium java

Step 4 : Create a class and add desired capabilities for automation for iOS

http://appium.io/docs/en/writing-running-appium/caps/
deviceName
platformName
platformVersion
app

DesiredCapabilities cap = new DesiredCapabilities();

cap.setCapability(“platformName”, “iOS”);
cap.setCapability(“platformVersion”, “11.4”);
cap.setCapability(“deviceName”, “iPhone 8”);
cap.setCapability(CapabilityType.BROWSER_NAME, “safari”);
cap.setCapability(“app”, “location of .app or .ipa file“);

URL url = new URL(“http://127.0.0.1:4723/wd/hub”);

IOSDriver driver = new IOSDriver(url, cap);

/Users/raghav/Library/Developer/Xcode/DerivedData/WebDriverAgent-brdadhpuduowllgivnnvuygpwhzy/Build/Products/Debug-iphonesimulator/IntegrationApp.app

To get device id
npm install -g ios-deploy
ios-deploy -c
OR
instruments -s devices

Step 5 : Run and test

#AppiumBeginnerTutorials
http://bit.ly/2W9pNeb

FREE Courses – https://automationstepbystep.com/online-courses/
Udemy – https://www.udemy.com/user/raghav-pal-3/
Training by Raghav at your venue – raghav.qna@gmail.com
Training schedule – https://automationstepbystep.com/trainings-2/
———— UI TESTING ————
Selenium Beginners – https://bit.ly/2MGRS8K
Selenium Java Framework from Scratch – https://bit.ly/2N9xvR6
Selenium Python – https://bit.ly/2oyMp5x
Selenium Tips – https://bit.ly/2owxc50
Selenium Builder – https://bit.ly/2MKNtlq
Katalon Studio – https://bit.ly/2wARFdi
Robot Framework with RIDE- https://bit.ly/2Px6Ue9
Robot Framework with Eclipse – http://bit.ly/2N8DZxb

———— API TESTING ————
Web Services (API) – https://bit.ly/2MGafL7
SoapUI – https://bit.ly/2MGahmd
Postman – https://bit.ly/2wz8LrW
General – https://bit.ly/2PYdwmV
Katalon Studio API Testing – https://bit.ly/2BwuCTN

———— MOBILE TESTING ————
Appium – https://bit.ly/2ZHFSGX
Mobile Playlist – https://bit.ly/2PxpeUv

———— CI | CD | DEVOPS ————
Jenkins Beginner – https://bit.ly/2MIn8EC
Jenkins Tips & Trick – https://bit.ly/2LRt6xC
Docker – https://bit.ly/2MInnzx

———— VERSION CONTROL SYSTEM ————
Git & GitHub – https://bit.ly/2Q1pagY

———— PERFORMANCE TESTING ————
JMeter Beginner – https://bit.ly/2oBbtIU
JMeter Intermediate – https://bit.ly/2oziNVB
JMeter Advanced – https://bit.ly/2Q22Y6a
JMeter Tips & Tricks – https://bit.ly/2NOfWD2
Performance Testing – https://bit.ly/2wEXbLS

———— PROGRAMMING ————
Java Beginners – https://bit.ly/2PVUcXs
Java Tips & Tricks – https://bit.ly/2CdcDnJ
GROOVY – https://bit.ly/2FvWV5C

———— IDE ————
Visual Studio Code – https://bit.ly/2V15yvt

———— MAVEN ————
Maven – https://bit.ly/2NJdDRS

———— OTHERS ————
Redis- https://bit.ly/2N9jyCG
Misc – https://bit.ly/2Q2q5xQ
Tools & Tips – https://bit.ly/2oBfwoR
QnA Friday- https://bit.ly/2NgwGpw
Sunday Special – https://bit.ly/2wB23BO

Ask Raghav – https://bit.ly/2CoJGWf
Interviews – https://bit.ly/2NIPPxk
All Playlists – https://bit.ly/2LSiezA

Keep Learning,
Raghav

Website – https://automationstepbystep.com/
LifeCharger – http://lifecharger.org/
Udemy Courses – https://www.udemy.com/user/raghav-pal-3/
Facebook – https://www.facebook.com/automationstepbystep
Twitter – https://twitter.com/automationsbs
Youtube – http://youtube.com/automationstepbystep
Instagram – https://www.instagram.com/automationstepbystep/

You can support my mission for education by sharing this knowledge and helping as many people as you can.

20 Comments

  • Anju George

    Hi Raghav,
    Iam getting error while trying to invoke the appium using the same code above.

    Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Could not create simulator with name 'appiumTest-3895B329-E7CA-480F-BFF9-181F5CD3CD4B-iPhone 8', device type id 'iPhone 8' and runtime id 'com.apple.CoreSimulator.SimRuntime.iOS-11-3'. Reason: 'simctl error running 'create': Invalid runtime: com.apple.CoreSimulator.SimRuntime.iOS-11-3'
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
    System info: host: 'Admins-MBP-2', ip: 'fe80:0:0:0:46:7a20:6f78:2951%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_222'
    Driver info: driver.version: IOSDriver

  • Monil Joshi

    Hi Raghav
    I created POM framework but I am getting
    java.lang.IllegalArgumentException: Can not set io.appium.java_client.ios.IOSElement field Com.pages.HomePage.firstInt to com.sun.proxy.$Proxy7
    Please let me know how can I share my code with you via mail of just copy-pasting here will do?

  • Vignesh Kumar N

    Hi.. trying iPhone automation.. all configured as explained in your previous videos.. but getting time out error after appium.io is launched from browser. below is the log, can you pls help?

    debug] [iOS] Picking webview 'WEBVIEW_1'
    [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] [RemoteDebugger] Starting to listen for JavaScript console
    [debug] [RemoteDebugger] Sending WebKit data: {"method":"Console.enable","params":{"objectGroup":"console","includeCommandLineAPI":true,"doNotPauseOnExceptionsAndMuteConsole":true}}
    [debug] [RemoteDebugger] Webkit response timeout: 5000
    [XCUITest] TimeoutError: operation timed out
    [XCUITest] at afterTimeout (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/release/timers.js:46:19)
    [XCUITest] at Timeout.timeoutTimeout [as _onTimeout] (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/release/timers.js:76:13)
    [XCUITest] at ontimeout (timers.js:436:11)
    [XCUITest] at tryOnTimeout (timers.js:300:5)
    [XCUITest] at listOnTimeout (timers.js:263:5)
    [XCUITest] at Timer.processTimers (timers.js:223:10)
    [debug] [WD Proxy] Matched '/session/e97c93f7-6ba0-45bb-956e-429a35d2503a' to command name 'deleteSession'
    [debug] [WD Proxy] Proxying [DELETE /session/e97c93f7-6ba0-45bb-956e-429a35d2503a] to [DELETE http://localhost:8100/session/25B14A36-C199-4EE0-9C24-1D072A1A0F92%5D with no body
    [debug] [WD Proxy] Got response with status 200: "{n "value" : {nn },n "sessionId" : "801996AA-9213-4C4E-A660-ECBB85C297A6",n "status" : 0n}"
    [debug] [XCUITest] Not clearing log files. Use `clearSystemFiles` capability to turn on.
    [debug] [XCUITest] In a web session. Removing remote debugger
    [debug] [RemoteDebugger] Disconnecting from WebKit remote debugger
    [debug] [iOSLog] Stopping iOS log capture
    [debug] [iProxy] recv failed: Connection reset by peer
    [debug] [iProxy] recv failed: Operation not permitted
    [debug] [RemoteDebugger] WebKit remote debugger socket disconnected
    [debug] [BaseDriver] Event 'newSessionStarted' logged at 1570113514442 (15:38:34 GMT+0100 (British Summer Time))
    [debug] [W3C] Encountered internal error running command: TimeoutError: operation timed out
    [debug] [W3C] at afterTimeout (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/release/timers.js:46:19)
    [debug] [W3C] at Timeout.timeoutTimeout [as _onTimeout] (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/release/timers.js:76:13)
    [debug] [W3C] at ontimeout (timers.js:436:11)
    [debug] [W3C] at tryOnTimeout (timers.js:300:5)
    [debug] [W3C] at listOnTimeout (timers.js:263:5)
    [debug] [W3C] at Timer.processTimers (timers.js:223:10)
    [HTTP] <– POST /wd/hub/session 500 94953 ms – 535

  • Tulus Hamdani

    hi Ravar, thanks fo this video tutorial

    I'm trying to follow step by step but when I ran the code in eclipse, shown errors in the console like this:

    Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: The desired capabilities must include either an app or a bundleId for iOS
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'tuluss-mbp.telkomsel.co.id', ip: 'fe80:0:0:0:1492:c2f1:df07:3efb%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_221'
    Driver info: driver.version: IOSDriver
    remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: The desired capabilities must include either an app or a bundleId for iOS
    at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:826:9)
    at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:447:37)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'tuluss-mbp.telkomsel.co.id', ip: 'fe80:0:0:0:1492:c2f1:df07:3efb%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_221'
    Driver info: driver.version: IOSDriver
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:208)
    at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:217)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
    at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
    at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:95)
    at iosdemo.FirstiOSTest.firstTest(FirstiOSTest.java:29)
    at iosdemo.FirstiOSTest.main(FirstiOSTest.java:14)
    Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:186)
    … 14 more
    Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: The desired capabilities must include either an app or a bundleId for iOS
    Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
    System info: host: 'tuluss-mbp.telkomsel.co.id', ip: 'fe80:0:0:0:1492:c2f1:df07:3efb%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_221'
    Driver info: driver.version: IOSDriver
    remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: The desired capabilities must include either an app or a bundleId for iOS
    at getResponseForW3CError (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/errors.js:826:9)
    at asyncHandler (/usr/local/lib/node_modules/appium/node_modules/appium-base-driver/lib/protocol/protocol.js:447:37)
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
    at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
    at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
    at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
    at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
    at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:499)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:486)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
    at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
    … 19 more

  • srinu kesireddy

    Hi Raghav, "instruments -s devices" can i use this command for windows as well?
    'instruments' is not recognized as an internal or external command,

    operable program or batch file." This is the error that i was getting when i ran the above command.

  • Ashwajit Thukral

    I always have a doubt which style of writing capability is correct?

    caps.setCapability(MobileCapabilityType.BROWSER_NAME, “Safari”); or caps.setCapability(CapabilityType.BROWSER_NAME, “Safari”); ?

  • Sourabh Roy

    I am following all the above steps but the ios driver is not able to install webdriveragentrunner on the simulator. I am just trying to launch a safari on the iphone 8 simulator

    Please find below my code
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformVersion", "12.4");
    capabilities.setCapability("browserName", "Safari");
    capabilities.setCapability("deviceName", "iPhone 8");
    capabilities.setCapability("platformName", "IOS");
    capabilities.setCapability("udid", "FFFFB0BD-B7A2-4DDC-8456-C92201FF32B7");
    capabilities.setCapability("automationName", "XCUITest");
    capabilities.setCapability ("platformName", "iOS");

    URL url = new URL("http://0.0.0.0:4723/wd/hub&quot😉;
    IOSDriver driver = new IOSDriver(url, capabilities);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

  • Hanse Uber alles

    Hi Raghav. Great Video! Question: I am able to run test in simulator fine, but I am getting error in console when want to test on real device: "'12.3.1' does not exist in the list of simctl SDKs. Only the following Simulator SDK versions are available on your system: 12.0, 12.1, 5.1, 12.2, 5.2".
    Caps I am using:
    .setDeviceName("XS")
    .setIOSBundleId("com.xx.xx.xx")
    .setPlatformVersion("12.3.1")
    .setApp("/Users/xx/Downloads/xx.ipa")
    .buildForIOS();

    NOTE: I am able to see my device when running command: instruments -s devices
    Can you please help ?

  • Pradeep P P

    Hi Raghav, Is it required to enroll apple id (team id) for apple developer program (Cost $119) for building WebdriverAgentRunner project? I am getting the following error while adding team Id in Xcode – Failed to create provisioning profile.
    There are no devices registered in your account on the developer website. Plug in and select a device to have Xcode register it.

  • rajesh be

    Raghav could you explain windows android testing project in java and any option available for doing iOS tesing on windows? Possibility is there or not i don't know whether this question is right or not?

Leave a Reply

Your email address will not be published. Required fields are marked *