Mobile Test Automation in Java with Appium
Sauce AI for Test Authoring: Move from intent to performance in second.|xBack to ResourcesBlogPosted
Sauce AI for Test Authoring: Move from intent to performance in second.
|
x
Appiumis an open source test automation tool which allows you to well write functional tests that automate iOS and Android roving apps. One big vantage Appium has over other wandering tryout automation tool is that Appium tests can be compose in any lyric that has a Selenium client library, include Python, Ruby, Node.js, and, perhaps most interesting to mobile developer, Objective-C and Java.
In this billet we & # x27; ll walk through the steps imply in testing theiOS sample apps using the JUnit Java exemplar tests(we also have createdTestNG example tests too).
To start, branching and clone Appium fromhttps: //github.com/appium/appium, and postdate the installation instructions to set up Appium in your environment.
Download and establish thesampling projectsby running the following from the command line:
grunt getSampleCode
grunt buildApp: TestApp
grunt buildApp: UICatalog
Once the sampling projects have have been built, you can then depart Appium by running the following:
grunt appium
Change the act directory to thesample-code/examples/java/junitdirectory, and run the tests by executing:
mvn test
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
Or run a individual test by executing: mvn -Dtest=com.saucelabs.appium.SimpleTest test
A Java Appium examination is lots the same as a Selenium test ... you make a RemoteWebDriver instance by determine some DesiredCapabilities, e.g.:
1@Before2public vacuum setUp () throws Exception {3// set up appium against a local application4File appDir = new File (System.getProperty (& quot; user.dir & quot;), & quot; .. / .. / .. /apps/TestApp/build/Release-iphonesimulator & quot;);56File app = new File (appDir, & quot; TestApp.app & quot;);7DesiredCapabilities capableness = new DesiredCapabilities ();8capabilities.setCapability (CapabilityType.BROWSER_NAME, & quot; iOS & quot;);9capabilities.setCapability (CapabilityType.VERSION, & quot; 6.0 & quot;);10capabilities.setCapability (CapabilityType.PLATFORM, & quot; Mac & quot;);1112//tell Appium where the location of the app is13capabilities.setCapability (& quot; app & quot;, app.getAbsolutePath ());1415//create a RemoteWebDriver, the default porthole for Appium is 472316driver = new RemoteWebDriver (new URL (& quot; http: //127.0.0.1:4723/wd/hub & quot;), capabilities);17}181920
Tests can also be publish to be run against. To do this, just update your tests to reference a zip file containing your app, and update your RemoteWebDriver representative to orient to ondemand.saucelabs.com, eg:
1@Before2public nullity frame-up () cast Exception {3String sauceUserName = & quot; YOUR_SAUCE_USERNAME & quot;;4String sauceAccessKey = & quot; YOUR_SAUCE_ACCESS_KEY & quot;;56DesiredCapabilities capabilities = new DesiredCapabilities ();7capabilities.setCapability (CapabilityType.BROWSER_NAME, & quot; iOS 6.0 & quot;);8capabilities.setCapability (& quot; device & quot;, & quot; iPhone Simulator & quot;);9capabilities.setCapability (CapabilityType.PLATFORM, & quot; Mac 10.8 & quot;);1011//zip file check your app to be tested12capabilities.setCapability (& quot; app & quot;, & quot; http: //appium.s3.amazonaws.com/TestApp6.0.app.zip & quot;);1314driver = new RemoteWebDriver (new URL (MessageFormat.format (& quot; http: // {0}: {1} @ ondemand.saucelabs.com:80/wd/hub & quot;, sauceUserName, sauceAccessKey)),15capabilities);16}
The tests themselves are written but like regular Selenium tests, eg.
1@Test2public nullity example () throw Exception {34// find an element by tag name5WebElement push = driver.findElement (By.tagName (& quot; button & quot;));6button.click ();78// get the value of the component9WebElement textbook = driver.findElement (By.tagName (& quot; staticText & quot;));10assertEquals (texts.getText (), & quot; some expected value & quot;);11}
The Java sampling tests for Appium include the following form:
- go a tryout against a simpleTestApp
- extend the same examination using
- runs a series of tests against the UICatalog sample coating
Please let us know if you receive any questions or gossip about running Appium examination with Java!
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