Setting up iOS Automation on Sauce Labs with Cucumber and Appium
Sauce AI for Test Authoring: Move from intent to execution in minutes.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from intent to execution in minutes.
|
x
Blog
Setting up iOS Automation on Sauce Labs with Cucumber and Appium
Abstract
Sauce Labshas recently announced which makes it easier to test roving apps in the cloud.Appiumis a mobile examination automation framework for hybrid and aboriginal mobile apps.Cucumberis a behaviour driven development a.k.aBDDpuppet used with different programming languages. The combination of Cucumber and Appium can be used for automating iOS apps in the cloud using Sauce Labs. This is a repost of theoriginal post. In this berth, we will see how to set up test automation of our iOS app in the cloud using Sauce Labs.
Getting Started
In order to get started, we require to have the initial setup handy. This include the followers:
Mac OSX 10.7.4 or high withXcodeinstal with command line tools.
Your app seed code or a prebuilt .app bundle for your app. Browse wide-eyed range of open-source iOS apps
Saucelabs Username and API key. for Saucelabs free chronicle.
Web development environment on Mac OSX for Ruby including Xcode, RVM, HomeBrew, Git and Ruby. FollowMoncef ’ s blog
Appium-Ruby-console with Nodeand npm (Node must be & gt; = v0.8)
Ruby 1.9.3
Get Appium and Your iOS App
Before we go before, let ’ s get the Appium waiter up and run. There are two ways to do it-
You can download Mac OSXAppium.dmgpackage and launch Appium.
You can run it from source. Follow. You need to make sure, You have authorized use of the iOS Simulator. If you are running Appium from NPM, you ’ ll do this by run
$ sudo authorize_ios
There are a wide scope of open source iOS mobile apps availablehere, we are going to usePlainNoteiOS app for this tutorial.
Compile and Upload iOS App on SauceLabs
Now we need to compile PlainNote App with Sauce. [Note Additional parameter TARGET_DEVICE_FAMILY]
$ git clone https: //github.com/vkoser/PlainNote
$ cd PlainNote
$ xcodebuild -sdk iphonesimulator6.0 TARGETED_DEVICE_FAMILY=1
In Sauce, there are optional argument like TARGETED_DEVICE_FAMILY argument. To make an app for iPhone, we use TARGETED_DEVICE_FAMILY= 1, for iPad TARGETED_DEVICE_FAMILY=2.
Now, once the build is successful, it will create “PlaneNote.app” at ‘/build/Release-iphonesimulator‘.
$ cd /build/Release-iphonesimulator/
$ ls
PlainNote.app PlainNote.app.dSYM
Zip the PlainNote App & amp; Upload to SauceLabs
Now that we have ‘PlainNote.app‘, we take to zip it by navigating to that directory
$ cd /build/Release-iphonesimulator/
$ zip -r PlainNote.zip PlainNote.app
Now you will see ‘PlainNote.zip‘ file in that directory
$ ls
PlainNote.app PlainNote.app.dSYM PlainNote.zip
Now, we need to upload this file to Sauce Labs temporary storage using the Sauce REST API. I am apply my Username and API key here.
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
$ whorl -u Shashikant86: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxbfc3 -X POST & quot; http: //saucelabs.com/rest/v1/storage/Shashikant86/PlainNote.zip? overwrite=true & quot; -H & quot; Content-Type: application/octet-stream & quot; -- data-binary @ /path/to/PlainNote/build/Release-iphonesimulator/PlainNote.zip
It will evidence you response something like this,
{& quot; username & quot;: & quot; Shashikant86 & quot;, & quot; size & quot;: 42190, & quot; md5 & quot;: & quot; 6ef42125b024188976af9d6b8a104105 & quot;, & quot; filename & quot;: & quot; PlainNote.zip & quot;}
It will be now uploaded to “sauce-storage: PlainNote.zip“. Now we are all set for compose tests for the application with Cucumber.
Setup Cucumber project
Now that we get already uploaded our app on SauceLabs temporary storage, we can setup Cucumber project to talk to the mobile app in the cloud. I assume that you are familiar with the BDD Code and code construction for the Cucumber projection. Please refer myold postif you are not cognisant of BDD codification.
Create Gemfile
We take a Gemfile in order to specify all our dependencies
$ mkdir sauce-cucumber-appium
$ cd sauce-cucumber-appium
$ rvm use 1.9.3
$ vim Gemfile
Now insert the following addiction into the Gemfile
source & quot; https: //www.rubygems.org & quot;
gem & quot; rest-client & quot;
gem & quot; rspec & quot;
gem & quot; selenium-webdriver & quot;
gem & quot; cucumber & quot;
gem & quot; rspec-expectations & quot;
Now we need to establish the bundle to download all the dependencies.
$ bundle install
This will make a ‘ Gemfile.lock ’ file.
Create Feature File
Now, we will write a feature file using Given When Then format. The feature file is written using theGherkinDomain Specific Language.
Let ’ s create ‘features/plain_note_sauce.feature‘ file.
$ vim features/plain_note_sauce.feature
The PlainNote app lineament will appear something like this
Feature: Notes
As iOS automation specialist
I want to setup iOS app automation in the cloud using Saucelabs, Appium and cucumber
Scenario: Add new Note use PlainNote App
Given I hold App extend with appium on Sauce
When chink + button using sauce driver
And I enroll text & quot; Data & quot; and preserve it on sauce
Then I should see & quot; Data & quot; note added on home page in the sauce cloud
This feature is self explanatory, we are going to add a new note and make sure it displayed on the Home page.
Setup Cucumber Environment
Let ’ s create ‘features/support/env.rb‘ where we can put our support code. We need to add sauce_capabilities note in the Sauce Labs Appium tutorial.
$ vim features/support/env.rb
Insert the following codification in the file.
require & # x27; rspec/expectations & # x27;
require & # x27; selenium-webdriver & # x27;
def sauce_capabilities
{
& # x27; app & # x27; = & gt; & # x27; sauce-storage: PlainNote.zip & # x27;,
& # x27; device & # x27; = & gt; & # x27; iPhone Simulator & # x27;,
& # x27; username & # x27; = & gt; & # x27; Shashikant86 & # x27;,
& # x27; access-key & # x27; = & gt; & # x27; a0e37e25-e2f3-4cba-95d3-936007d8bfc3 & # x27;,
& # x27; platform & # x27; = & gt; & # x27; OS X 10.8 & # x27;,
& # x27; version & # x27; = & gt; & # x27; 6.0 & # x27;,
& # x27; name & # x27; = & gt; & # x27; Running PlainNote wit Cucumber and Appium & # x27;,
& # x27; passed & # x27; = & gt; & # x27; true & # x27;
}
end
def sauce_url
& quot; http: //Shashikant86: a0e37e25-e2f3-4cba-95d3-936007d8bfc3 @ ondemand.saucelabs.com:80/wd/hub & quot;
end
def sauce
@ sauce ||= Selenium: :WebDriver.for (: remote,: desired_capabilities = & gt; sauce_capabilities,: url = & gt; sauce_url)
end
After {@ sauce.quit}
Now that we have a created ‘ sauce ’ driver with all required craved capabilities, ee will using the ‘ sauce ’ object in our step_definitions
Write Step definition using Selenium-Webdriver JSON Wire Protocol
At this point if you run the ‘ bundle exec cucumber ’ command it will tell you step that are not enforce yet. We need to enforce these measure definitions expendSelenium-Webdriver JSON Wire Protocolfor Appium. Now we will create a step definition file and implement it
$ vim features/step_definitions/plain_note.rb
Now add these measure definition to the file.
Given (/^I have App running with appium on Sauce $ /) do
end
When (/^click \+ button using sauce driver $ /) do
sauce.find_element (: name, & quot; Add & quot;) .click
end
When (/^I enter text & quot; (. *?) & quot; and preserve it on sauce $ /) do |data|
sauce.find_element (: xpath, & quot; //window [1] /scrollview [1] /textview [1] & quot;) .send_keys data
sauce.find_element (: name, & quot; Done & quot;) .click
sauce.find_element (: name, & quot; Save & quot;) .click
end
Then (/^I should see & quot; (. *?) & quot; billet added on home page in the sauce cloud $ /) do |text|
billet = sauce.find_element (: xpath, & quot; //window [1] /tableview [1] /cell [1] /text [1] & quot;)
note.attribute (& quot; value & quot;) .should mate schoolbook
end
Appium Inspector
Appium Inspectoris a feature of the Appium OSX app which allows you to scrutinize elements on your mobile app. You can likewise record tests in the different languages. Writing the Ruby code is leisurely if you have used Appium Inspector locally to platter tests. Watch this video to know ‘How to use Appium Inspector‘.
Now, we are all set to run cucumber to execute tests on the SauceLabs
$ bundle exec cucumber features/plain_note_sauce.feature
Now you will see the tests run on Sauce Labs and in your terminal you will see something like this
Feature: Notes
As iOS automation specialist
I want to setup iOS app automation in the cloud using Saucelabs, Appium and cucumber
Scenario: Add new Note expend PlainNote App # features/plain_note_sauce.feature:5
Given I get App running with appium on Sauce # features/step_definitions/plain_note_sauce.rb:1
When dog + push using sauce driver # features/step_definitions/plain_note_sauce.rb:4
And I enter text & quot; Data & quot; and saved it on sauce # features/step_definitions/plain_note_sauce.rb:8
Then I should see & quot; Data & quot; note added on home page in the sauce cloud # features/step_definitions/plain_note_sauce.rb:14
1 scenario (1 passed)
4 steps (4 pass)
0m35.213s
You can watchvideo and screenshotsof the job.
Cucumber-Appium-SauceLabs
You can find source codification on GitHub:
GitHub : cucumber-appium
Watch thisvideoget a open idea of the cucumber-appium setup on Sauce Labs. If any questions, feel free tocontact me.
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free