Guest Post: Automated iOS Acceptance Testing with Appium, Cucumber-JVM, Jenkins, and Sauce Labs Part 3
Sauce AI for Test Authoring: Move from intention to execution in minutes.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from intention to execution in minutes.
|
x
Blog
Guest Post: Automated iOS Acceptance Testing with Appium, Cucumber-JVM, Jenkins, and Sauce Labs Part 3
For all you folks following along at domicile, we & # x27; ve been posting a series of guest posts written byUnmesh Gundecha, testing guru and author ofSelenium Testing Tools Cookbook. Here we have the terminal post in his series, which lead the mobile tests he & # x27; s discussed running on a local environment and running them on Sauce with Appium. Many thanks to Unmesh for this awful and thorough serial. And let us cognize what other mobile testing topics you & # x27; d like to read about. Read on for the net part! _________________________________
Running on Sauce Labs
So far we executed feature on a local environment. Now this is but one lineament, there could be 100s of such and you might desire to run these characteristic frequently. Setting up dedicated machine may not be always possible and imply costs. Sauce labs, the company behind Appium, provides you an ability to run Appium tests in a virtual environment without needing you to setup everything from scratch. This also saves you costs for put up the base on your own. But at time you may also need to run these on a local surroundings, how do we support both running in local environment and sauce? Let ’ s use Tags and Hook feature of Cucumber. We already have a setup method which connects to a local Appium sever using the RemoteWebDriver. Let ’ s add a tag to this method: @ Before(& quot; local & quot;)public void setUpLocal () throws Throwable {...} And add another apparatus method setUpiOS () and add “ ios-sauce ” tag to it:
@ Before (& quot; @ ios-sauce & quot;)
public emptiness setUpiOS () throws Throwable
{
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities.setCapability (CapabilityType.VERSION, & quot; 6.1 & quot;);
capabilities.setCapability (CapabilityType.PLATFORM, & quot; Mac & quot;);
capabilities.setCapability (& quot; app & quot;, & quot; sauce-storage: my_ios_app.zip & quot;);
capabilities.setCapability (& quot; device & quot;, & quot; iPhone Simulator & quot;);
String sauceUserName = System.getenv (& quot; SAUCE_USER_NAME & quot;);
String sauceAccessKey = System.getenv (& quot; SAUCE_ACCESS_KEY & quot;);
//Create an representative of RemoteWebDriver and connect to the Appium waiter.
//Appium will launch the BmiCalc App in iPhone Simulator using the
configurations specified in Desired Capabilities
driver = new RemoteWebDriver (new URL (MessageFormat.format (& quot; http: // {0}:
{1} @ ondemand.saucelabs.com:80/wd/hub & quot;, sauceUserName, sauceAccessKey)), capabilities);
}
This allows selectively run feature on desired environment. For example if you wish to run scenario on Sauce Labs, then you need to stipulate the “ ios-sauce ” tag on the scenario definition in feature file@ ios-sauceScenario Outline: Calculate Body Mass Index … This will run the feature on Sauce Labs environment. If you limit “ local ” then it will run the feature on local Appium setup. Here is the consummate code model:
package bmicalculator.test;
importation java.net.URL;
import java.text.MessageFormat;
import cucumber.annotation. *;
signification cucumber.annotation.en. *;
import stable org.junit.Assert.assertEquals;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
importation org.openqa.selenium.remote.RemoteWebDriver;
importee org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
public class Bmi_Calculator_Step_Defs {
private WebDriver driver;
@ Before (& quot; @ local & quot;)
public void setUpLocal () throws Throwable
{
//Setup for run Appium tryout in local environment
DesiredCapabilities capableness = new DesiredCapabilities ();
capabilities.setCapability (CapabilityType.BROWSER_NAME, & quot; iOS & quot;);
capabilities.setCapability (CapabilityType.VERSION, & quot; 6.1 & quot;);
capabilities.setCapability (CapabilityType.PLATFORM, & quot; Mac & quot;);
capabilities.setCapability (& quot; app & quot;,
& quot; /Users/upgundecha/Desktop/AppExamples/BmiCalculator/build/Release-iphonesimulator/BmiCalculator.app & quot;);
//Create an instance of RemoteWebDriver and connect to the Appium server.
//Appium will launch the BmiCalc App in iPhone Simulator using the conformation specified in Desired Capabilities
driver = new RemoteWebDriver (new URL (& quot; http: //0.0.0.0:4723/wd/hub & quot;), capabilities);
}
@ Before (& quot; @ ios-sauce & quot;)
public void setUpiOS () throw Throwable
{
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities.setCapability (CapabilityType.VERSION, & quot; 6.1 & quot;);
capabilities.setCapability (CapabilityType.PLATFORM, & quot; Mac & quot;);
capabilities.setCapability (& quot; app & quot;, & quot; sauce-storage: my_ios_app.zip & quot;);
capabilities.setCapability (& quot; twist & quot;, & quot; iPhone Simulator & quot;);
String sauceUserName = System.getenv (& quot; SAUCE_USER_NAME & quot;);
String sauceAccessKey = System.getenv (& quot; SAUCE_ACCESS_KEY & quot;);
//Create an instance of RemoteWebDriver and connect to the Appium waiter.
//Appium will establish the BmiCalc App in iPhone Simulator using the configurations specified in Desired Capabilities
driver = new RemoteWebDriver (new URL (MessageFormat.format (& quot; http: // {0}: {1} @ ondemand.saucelabs.com:80/wd/hub & quot;, sauceUserName, sauceAccessKey)), capabilities);
}
@ Given (& quot; ^I participate \ & quot; ([^\ & quot;] *) \ & quot; as height $ & quot;)
public void I_enter_as_height (String height) throws Throwable {
WebElement heightTextField = driver.findElement (By.name (& quot; Height & quot;));
heightTextField.sendKeys (height);
}
@ Then (& quot; ^I enter \ & quot; ([^\ & quot;] *) \ & quot; as weight $ & quot;)
public void I_enter_as_weight (String weight) shed Throwable {
WebElement weightTextField = driver.findElement (By.name (& quot; Weight & quot;));
weightTextField.sendKeys (weight);
}
@ Then (& quot; ^I press the Calculate button $ & quot;)
public void I_press_the_Calculate_button () throws Throwable {
WebElement calculateButton = driver.findElement (By.name (& quot; Calculate & quot;));
calculateButton.click ();
}
@ Then (& quot; ^I should see \ & quot; ([^\ & quot;] *) \ & quot; as bmi and \ & quot; ([^\ & quot;] *) \ & quot; as class $ & quot;)
public nothingness I_should_see_as_bmi_and_Normal_as_category (String bmi, String category) drop Throwable {
WebElement bmilabel = driver.findElement (By.name (& quot; bmi & quot;));
WebElement bmiCategorylabel = driver.findElement (By.name (& quot; family & quot;));
//Check the calculated Bmi and Category displayed
assertEquals (bmi, bmilabel.getText ());
assertEquals (category, bmiCategorylabel.getText ());
@After
public void tearDown ()
{
driver.quit ();
}
}
The accomplished source code for the sample App and test is available athttps: //github.com/upgundecha/BmiCalculator
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
Using Uninterrupted Integration
Uninterrupted Integration (CI) is becoming a widely accepted recitation in agile projects for early feedback. Each consolidation is verified by an machine-controlled build to detect errors as quickly as possible. CI also gives outstanding visibility to all stakeholders about the overall health of the project and its procession. Jenkins is one of the popular CI tool used by the teams. You can setup the build and exam jobs on Jenkins for this project.
Building the App with Jenkins
For building the App with Jenkins, create a newBuild a free-style software projectJob. The sampling App source is hosted on GitHub. Configure the Git repository and point it to the GitHub repo as display in below blind shot Next, configure the build trigger, so every time a change is submitted to Git, this job will be trigger a new habitus of the App. Once the App is establish it will be upload to the Sauce Labs temporary depot region so the test job can run acceptance tests on the build.
Running Acceptance tests with Jenkins
For running espousal trial after a successful chassis, make anew Build a maven2/3 taskjob in Jenkins with following parameters In theBuild Triggersection configureBuild after other projection are builtand delineate name of the earlier job. This will automatically run acceptance tryout (i.e. current job) when the App build is successful Cucumber provides a report plugin for Jenkins which provides a nicely formatted interactive web reports as demonstrate in below screenshot:
Summary
We can write credence tryout for aboriginal mobile Apps with Cucumber, Selenium WebDriver API and Appium. These can be run on local or environs. We can also get benefit of unscathed squad communication and early feedback by applying these methods in roving coating development.
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