Testing Your Mobile Apps with Behat & Sauce (Pt. 2)
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
Testing Your Mobile Apps with Behat & amp; Sauce (Pt. 2)
This is a guest blog post byShashikant Jagtap. It is the second post in a 2-part serial on configure Behat with Selenium and Sauce to test mobile devices.Part 1 is here. You can read more about the authorhere.
Last workweek, I did aguest postthat talked about some of the outstanding new add-on to latest freeing of Behat and how to integrate that with Sauce. In this component of the blog serial, we & # x27; ll continue mobile tryout mechanization in the cloud using Apple Sauce and withBehat. Let & # x27; s get started!
Create Your Sauce Account
So far, we have successfully implemented features to run locally in a browser. Now it & # x27; s time to add some Sauce to it. First, you & # x27; ll need to sign up for a. Once you & # x27; ve done that, you will see your own personal Sauce USERNAME and SAUCE-ACCESS KEY [SAUCE-API-KEY] on your story page, which we & # x27; ll use to configure the Behat test with Sauce Labs.
Sauce Connect [Composer]
Before we preserve, we should figure out with we & # x27; re quiz internal application. If yes, so we need to use & # x27; Sauce Connect & # x27;. During the set up process covered in the final post, we downloaded Sauce Connect and Sauce-Config with Composer. It should be in the ./bin directory. Assuming that you experience made Sauce-Config and Sauce Connect global, you can configure your account with Sauce Connect as follow:
$ sauce_config YOUR-SAUCE-USERNAME YOUR-SAUCE-API-KEY
Successfully configured Sauce to use account YOUR-SAUCE-USERNAME
$ sauce_connect
This will launch Sauce Connect, which tests your internal applications by say your local configuration. You can also start Sauce Connect using the following bid once you have download the jar file:
java -jar Sauce-Connect.jar YOUR-SAUCE-USERNAME YOUR-SAUCE-API-KEY
Note: We don & # x27; t demand Sauce Connect for this tutorial as we are testing live websites.In order to run Behat Tests on iOS and Android devices, we want to create profile and run exam with those. Mink Extension has Selenium 2/WebDriver, which prvides different capability. Selenium 2/WebDriver for Mink has three options:
Browser: Here you can set the & # x27; desiredCapabilities & # x27; of the webdriver eg. iPhone, iPad, Android, Safari, etc.
wd_host: Here you have to provide your Sauce credentials, such as your username and API key e.g SAUCE-USERNAME: SAUCE-API-KEY @ ondemand.saucelabs.com/wd/hub
capabilities: Here you can delimit the platform and version of the device. You can use Sauce Capabilities hither e.g {& quot; platform & quot;: & quot; Mac 10.8 & quot;, & quot; version & quot;: & quot; 6 & quot;}
The leaning of supported Browsers, OS, Devices can be found on SauceLabs & # x27; page. You need to take & # x27; webdriver & # x27; and & # x27; php & # x27; code from the dropdown in order to see which combination are supported for PHP and Behat.iPhone Sauce:

In order to run test on iPhone, we need to create the & # x27; iPhone & # x27; profile in the & # x27; behat.yml. & # x27; Just glue the following code into your & # x27; behat.yml. & # x27; We need to set the browser parameter to & # x27; iPhone & # x27; and add the Sauce credentials in the & # x27; wd_host & # x27; parameter. We also need to select the proper & # x27; platform & # x27; and & # x27; version & # x27; combination from & # x27; capabilities. & # x27;
iPhone:
context:
class: & # x27; FeatureContext & # x27;
extensions:
Behat\MinkExtension\Extension:
selenium2:
browser: iphone
wd_host: SAUCE-USERNAME: SAUCE-API-KEY @ ondemand.saucelabs.com/wd/hub
capableness: {platform: Mac 10., version: 6}
Now, run your test with & # x27; iPhone & # x27; profile like this
$ behat -p iPhone
You can see the job running unrecorded on Sauce Labs if you see your. Watch the of this trial on Sauce Labs.

iPad Sauce

In order to run test on an iPad, we demand to create the & # x27; iPad & # x27; profile in the & # x27; behat.yml. & # x27; Just paste follow codification into your & # x27; behat.yml. & # x27;
Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.
iPad:
context:
class: & # x27; FeatureContext & # x27;
extensions:
Behat\MinkExtension\Extension:
selenium2:
browser: iPad
wd_host: SAUCE-USERNAME: SAUCE-API-KEY @ ondemand.saucelabs.com/wd/hub
capabilities: {platform: Mac 10.8, adaptation: 6}
Now, run your test with the & # x27; iPhone & # x27; profile like this:
$ behat -p iPad
You will see the job running on Sauce Labs. Watch the of this tryout on Sauce.Android

Sauce
In order to run test on Android, we want to create an & # x27; Android & # x27; profile in the & # x27; behat.yml & # x27;. Just paste postdate codification into your & # x27; behat.yml & # x27;.
Android:
context:
class: & # x27; FeatureContext & # x27;
extensions:
Behat\MinkExtension\Extension:
selenium2:
browser: android
wd_host: SAUCE-USERNAME: SAUCE-API-KEY @ ondemand.saucelabs.com/wd/hub
capableness: {program: Linux, version:4}
Now, run your examination with the & # x27; Android & # x27; profile like this:
$ behat -p Android
You will see the job running on Sauce Labs. Watch the of this test on Sauce.
Generating HTML reports
Create an empty directory called & # x27; report & # x27; to store reports generated by Behat.
$ behat -p iPhone -f html -- out report/report.html
This will generate a skillful looking HTML report in the & # x27; reports & # x27; directory that look like this:

Build Features With Apache ANT
We can run all the feature files in one go using a build puppet called& # x27; Apache ANT& # x27;. You need to install it using thefacilityguild on ANT documentation. Next step is to make & # x27; build.xml & # x27; file into your project. Copybuild.xmlfrom GitHub. You can now run all the features apply the command:
$ ant SaucyBehat
Source Code and Usage on Github
If you have any topic while setting up Behat with Sauce Labs, be certain to assure out the source code with build script on GitHub. The source codification is in a repository called & # x27;SaucyBehat-iOS-Android& # x27;, and there is documentation on how to use this repository in theREADME file. Summary of Steps
Clone Repository
$ git clone git @ github.com: Shashikant86/SaucyBehat-iOS-Android.git
$ cd SaucyBehat-iOS-Anroid
Download Composer
$ curl http: //getcomposer.org/installer | php
$ php composer.phar install
Update & # x27; behat.yml & # x27; with YOUR-SAUCE-USERNAME YOUR-SAUCE-API-KEY
Run Selenium Server if you wish to tryout locally. Don & # x27; t need to run selenium to run tryout on Saucelabs.
Execute anatomy to run all tryout using ApacheANT
$ ant SaucyBehat
Watch the Video Demo onYoutube.
Final Thoughts
Mobile test automation, while challenging, is becoming a bit easier and simpler with the help of Behat, Mink Extension and Sauce Labs. Dependency management using Composer makes our living easy while handling third-party repositories and simple constellation in Behat create it possible to run our BDD sport on mobile device with help of WebDriver & # x27; s desired capabilities. As of this poisting, we are bestowSauce & # x27; s Capabilitiesto Mink Extension. Stay tuned for more exciting clobber related to Behat and Sauce Labs!LINKS & amp; RESOURCES Source Code on Github : SaucyBehat-iOS-Android Video Demo on Youtube : Behat Installation & iOS-Android -Saucelabs Demo Behat Official Documentation : Behat Docs Sauce Labs Documentation PHP: with PHP and WebdriverMy Blog : Let & # x27; s BDD PHP About Me: SHASHIKANT JAGTAP
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