Testing Your Mobile Apps with Behat & Sauce Labs (Pt. 1)

Sauce AI for Test Authoring: Move from purpose to execution in transactions.|xBack to ResourcesBlogPos

March 18, 2026 · 9 min read · Mobile Testing

Sauce AI for Test Authoring: Move from purpose to execution in transactions.

|

x

Back to Resources

Blog

Posted October 27, 2012

Testing Your Mobile Apps with Behat & amp; Sauce Labs (Pt. 1)

quote

This is a guest blog post by Shashikant Jagtap. You can say more about the authorhere.Hope you enjoyed my final post & # x27;Adding Sauce To Behat& # x27;, which covered the fundamentals ofBehat and BDD. This is a follow up post, as Behat has changed drastically since then.

Behatis an astonishing BDD framework for PHP applications. It recently added some outstanding new capableness, including the use ofComposer and Behat Extensions. Composer is a dependence management system for PHP applications that helps us manage all the third party dependency in one place. Another outstanding lineament Behat bring is & # x27;Behat Extensions & # x27;, which lets you pass Behat by adding extensions of your choice.MinkExtensionis one such propagation that software QA engineers can use effectively, and it has everything we need to configure the features of Sauce Labs into it.

Peregrine Test Automation + Sauce Labs + Behat

proclaimed support for iOS and Andriod devices in August, allowing the Behat community to enjoy the benefits of Apple and Android Sauce. Mobile automation testing is more challenging than web applications and desktop applications testing because mobile apps are new in the marketplace and don & # x27; t receive proper industry standards yet. Mobile application tend to lack proper automation creature and substructure for a variety of the mobile device out there. One of the major matter in mobile automation is setting up an environment for mobile device, which usually requires a eminent grade of QA and base skills. Sauce Labs solved most of the these job by ply cloud support for mobile automate testing, so this post will explain some great new features ofBehat 2.4(portion 1 of this blog series) and its integration with Apple Sauce and Android Sauce (part 2). Let & # x27; s start with the Behat installtion.

Remove previous Behat induction [Pear]

In the last post about Behat, we establish Behat with & # x27; pear & # x27; bundle. The Behat version installed with pear packet is no longer supported so be sure to say theBehat installationusher for further information. Now, let & # x27; s uninstall the old version of Behat and install a new one. Open your terminal and character in the following bidding. Check your existing installation with this:

$ which behat

If you instal Behat with the pear package, you will see something like this:

$ which behat
/usr/local/pear/bin/behat

Remove this Behat vesion by running:

$ sudo pear uninstall behat/behat
uninstall ok: groove: //pear.behat.org/behat-2.3.5

$ sudo pear uninstall behat/gherkin
uninstall ok: groove: //pear.behat.org/gherkin-2.1.1

Remove & # x27;Mink& # x27; too, as we are locomote to use & # x27; MinkExtension & # x27;:

$ sudo pear uninstall behat/mink
uninstall ok: channel: //pear.behat.org/mink-1.3.3

Behat 2.4 installation [Composer]

Now that we have withdraw the old version of Behat, we won & # x27; t regain anything in binary when you fulfil the & # x27; behat & # x27; bid:

$ behat
-bash: /usr/local/pear/bin/behat: No such file or directory

Now make a new Behat facility directory. Here we receive & # x27; /opt/behat & # x27; directory with all the permit.

$ sudo mkdir /opt/behat
$ cd /opt/behat/
$ sudo chmod -R 777 /opt/behat/

Composer.jsonCreate the & # x27; composer.json & # x27; file inside & # x27; /opt/behat & # x27; and add all the third-party libraries, packages, dependencies into it like this:

$ sudo vi composer.json

Add the following dependencies in the json file (you can add more as per your project requirement). You can find more packages on thePackagist website:

{
& quot; require & quot;: {
& quot; behat/behat & quot;: & quot; 2.4. * @ stable & quot;,
& quot; behat/mink & quot;: & quot; 1.4 @ stable & quot;,
& quot; behat/mink-goutte-driver & quot;: & quot; * & quot;,
& quot; behat/mink-selenium-driver & quot;: & quot; * & quot;,
& quot; behat/mink-selenium2-driver & quot;: & quot; * & quot;,
& quot; behat/mink-extension & quot;: & quot; * & quot;,
& quot; sauce/sausage & quot;: & quot; & gt; =0.5 & quot;,
& quot; sauce/connect & quot;: & quot; & gt; =3.0 & quot;
}, & quot; minimum-stability & quot;: & quot; dev & quot;, & quot; config & quot;: {& quot; bin-dir & quot;: & quot; bin/ & quot;}}

Note that we have include software for Behat, Mink, and Mink drivers such as Selenium & amp; WebDriver. We have also include theMinkExtensionand packages in order to use them in the projection. MinkExtension creates Mink instances in each sub-context or it could be habituate as a subcontext on its own. You can read more about it on the MinkExtensiondocumentationpage. We will demonstrate how to use MinkExtension and Sauce Connect later in this berth. The next footstep is to download composer.phar file consisting of all the above packages. Let & # x27; s do that with the undermentioned commands:

$ curl http: //getcomposer.org/installer | php
$ curl
http: //getcomposer.org/installer | php
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 11038 0 11038 0 0 88692 0 --: --: -- --: --: -- --: --: -- 307k
#! /usr/bin/env php
All settings correct for using Composer
Downloading ...

Composer successfully installed to: /opt/behat/composer.phar
Use it: php composer.phar

This will download & # x27; composer.phar & # x27; file, but let & # x27; s confirm with this:

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

$ ls
composer.json composer.phar

Now install it using the next dictation:

$ php composer.phar install

This will download all the dependencies. You can see it in the & # x27; Behat & # x27; directory. Once it has finished downloading, your directory should look like this:

$ ls
bin composer.json composer.lock composer.phar vendor

It will also make a composer.lock file that will contain the list of installed packages and their associated versions andvendor/autoload.phpfile that can be used to autoload all the dependencies in your project. You should now be able to use any grade from your installed packages. Now, you are ready to run Behat employ & # x27; ./bin/behat & # x27; command.

$ ./bin/behat

Don & # x27; t forget to make & # x27; ./bin & # x27; directory workable so that we can execute all the binary from outside:

$ cd /opt/behat
$ sudo chmod -R 777 bin/

Access Behat Locally

You can now access Behat topically from where you downloaded composer. OR you can get it spherical.

$ ./bin/behat

Check the Behat variation:

$ ./bin/behat -- version
Behat version DEV

Make Behat Global

Now, let & # x27; s make a global symlink to access Behat from anywhere.

$ sudo ln -s /opt/behat/bin/behat /usr/local/bin/behat

Make Sauce Connect Global

You can also run Behat and sauce_config, sauce_connect from anyplace. It dispatch the Behat2.4 facility process.

$ sudo ln -s /opt/behat/bin/sauce_config /usr/local/bin/sauce_config
$ sudo ln -s /opt/behat/bin/sauce_connect /usr/local/bin/sauce_connect

Note: You may demand to restart your terminal session to get the raw version. 

$ which behat
/usr/local/bin/behat

If you had any trouble with the old bid, watch the picture demo of the Behat initiation with Composer onYoutube.

Creating Our Behat Project

Now, let & # x27; s create our maiden Behat project by running the next bidding.

$ sudo mkdir SaucyBehat
$ sudo chmod -R 777 SaucyBehat
$ cd SaucyBehat
$ behat -- init
+d features - place your * .feature files hither
+d features/bootstrap - place bootstrap playscript and static files hither
+f features/bootstrap/FeatureContext.php - place your lineament related codification hither

Behat has already make a & # x27; features & # x27; directory to write feature file. We need to implement the footstep definition in auto-generated & # x27; feature/bootstrap/FeatureContext.php & # x27; file. Let & # x27; s first create a feature file to see Sauce Labs features:

$ sudo vi Sauce.feature

Add the following feature:Feature: SauceLabs Documentation In order to learn SauceLabs features As a Software Tester I need to see resource @ javascript Scenario: Access feaures Given I am on & quot; / & quot; When I follow & quot; Features & quot; And I saw page loaded Then I should be on & quot; /features & quot; And I should see & quot; Check out our features. & quot;We also postulate to make a configuration file called & # x27; behat.yml & # x27; in the task root directory. It should use MinkExtension. Let & # x27; s create & # x27; default & # x27; profile to run exam locally:

default:
context:
category: & # x27; FeatureContext & # x27;
extensions:
Behat\MinkExtension\Extension:
base_url: & # x27;
'
javascript_session: & # x27; selenium2 & # x27;
goutte: ~
selenium2:

We experience now create a & # x27; default & # x27; profile, which uses the Context & # x27; FeatureContext.php & # x27; and the Extension called & # x27; MinkExtension. Mink Extension provides different driver such as Selenium,Selenium2[WebDriver] etc. We feature apply & # x27; Selenium2 & # x27; driver to run tests. Read more aboutMinkExtentionhither or follow it onGitHub.Now, we ask to update & # x27; feature/bootstrap/FeatureContext.php & # x27; to use & # x27; MinkExtension & # x27;. In order to do this, we involve to extend the file to & # x27; Behat\MinkExtension\Context\MinkContext & # x27; alternatively of & # x27; BehatContext & # x27;. First we need to delete all the code from unnessesary code from FeatureContext File. Now, it should appear like this:

/**
* Features context.
*/
class FeatureContext extends Behat\MinkExtension\Context\MinkContext
{
}

We are set to run the Behat characteristic locally. Now we need to download theSelenium Serverand run it in the ground.

$ /path/to/seleniumjar/ java -jar selenium-server-standalone-2.25.0.jar

Let & # x27; s run & # x27; Behat & # x27; from the beginning of the project. (Remember you incessantly have to run & # x27; behat & # x27; from beginning undertaking directory unless you provided PATH in & # x27; behat.yml).

$ behat

You can see test running in the browser. It will complain about the & # x27; UnDefined & # x27; step, which Mink didn & # x27; t understand. We need to copy that code snippet and implement it in the FeatureContext.php file using cleanMinkApi & # x27; s. Here is the implemented footstep to get the lineament work. Now, FeatureContext.php file will look like this:

/**
* Features context.
*/
class FeatureContext go Behat\MinkExtension\Context\MinkContext
{
/ * * * @ Given /^I saw page loaded $ / * /
public function iSawPageLoaded ()
{
$ this- & gt; getSession () - & gt; wait (& quot; 5000 & quot;, & quot; document.getElementById (& # x27; pricing-table & # x27;) & quot;);
}
}

Now if you run the Behat command again, you will see that the tests passed like this:Feature: SauceLabs Documentation In order to learn SauceLabs features As a Software Tester I necessitate see resource @ javascript Scenario: Access feaures # features/Sauce.feature:7 Given I am on & quot; / & quot; # FeatureContext: :visit () When I postdate & quot; Features & quot; # FeatureContext: :clickLink () And I saw page loaded # FeatureContext: :iSawPageLoaded () Then I should be on & quot; /features & quot; # FeatureContext: :assertPageAddress () And I should see & quot; Check out our features. & quot; # FeatureContext: :assertPageContainsText () 1 scenarios (1 passed) 5 steps (5 passed) 0m35.164sAnd that & # x27; s it! In portion 1 of this tutorial, we covered, Behat, Sauce Connect, Mink, establish Selenium with Composer and running Behat tests in local browsers. In part 2, we will learn how to run Behat tests on Mobile device using Sauce Labs.

Published:
Oct 27, 2012
Share this berth
Copy Share Link
LinkedIn
© 2026 Sauce Labs Inc., all rights reserved. SAUCE and SAUCE LABS are registered trademarks owned by Sauce Labs Inc. in the United States, EU, and may be registered in other jurisdictions.
robot
quote

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 Free

Test 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