For any help/queries on this framework. Please feel free to drop an email @ [email protected] If you find it helpful, star the repository and share with your network on LinkedIn,Twitter etc :) Connect with me on LinkedIn Cheers!
Single code base framework to test android and iOS app using appium. It is a boilerplate code. Clone it and you are good to go!
-
Appium server installed on the machine. In case not, install it by running command
npm install -g appium
. For more details visit: https://appium.io/docs/en/about-appium/getting-started/?lang=en -
iOS Simulator or Android Emulator or real device to execute tests.
-
Install Maven in your machine. Maven is a build tool (can be downloaded from here). pom.xml file is present in base directory which has all the required dependencies and code to invoke testng.xml file when executed from command line.
- Connect your device to your machine or start the emulator.
Note: start appium server on your machine if not included programatically
$ cd one_for_all_ui/ $ mvn test -Dos=android -Dsurefire.suiteXmlFiles=testng.xml
Include iOS app on which you want to run test. Provide its path in config.xml file (iOSAppPath=src/app/path-to-your-iOSfile). And write screen locators in IOSLoginScreen and methods in IOSLoginCorelogic. Now you are ready to run below commands.
$ cd mobileautomationframework/ $ mvn test -Dos=iOS -Dsurefire.suiteXmlFiles=testng.xml
Package : oneforall : It includes the common classes (and methods) which are required by each test to perform actions. Below are classes in this package:
retryLogic : It has classes to implement retry in case of failure of a test. Retry count is set to 1 as of now. Test will be run once if it fails during the execution.
Add below listener to testng.xml file to include retry functionality.
CreateSession.java : All the methods to create a new session and destroy the session after the test(s) execution is over. Each test extends this class. Below are the methods in CreateSession class in their execution order.
-
invokeAppium() - method starts Appium server. Calls startAppiumServer method to start the session depending upon your OS.
-
createDriver(String os, Method methodName) - method creates the driver depending upon the passed parameter (android or iOS) and loads the properties files (config and test data properties files).
-
Tests execution (tests are present in integrationtests.tests package)
-
teardown() - method quit the driver after the execution of test(s)
-
stopAppium() - method to stop Appium server. Calls stopAppiumServer() method to stop session depending upon your OS.
GenericMethods.java : It is a common repository for all the webdriver and appium methods which are called in each coreLogic classes. Every new method which is being used in coreLogic classes should be added in this class as well. It is to reduce the duplicate code. Each screen class extends this class. Below are few methods defined in this class:
waitForVisibility(By targetElement) - method to wait for an element to be visible findElement(By locator) - method to find an element findElements(By locator) - method to find all the elements of specific locator
MysqlDatabase.java : This can be used if any DB values need to be verifiedIt has method to read DB and get data from required table. For more help, read on this link: http://www.vogella.com/tutorials/MySQLJava/article.html
Package : app : It contains the app build against which tests would be executed.
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
- Unable to start Appium server: java.lang.Exception: Invalid server instance exception has occured: There is no installed nodes!
Add JS path in command to start appium server (CreateSession.java -> startAppiumServer)
'builder = new AppiumServiceBuilder() .withAppiumJS(new File("/usr/local/lib/node_modules/appium/build/lib/main.js")) .usingPort(4723) .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withArgument(GeneralServerFlag.LOG_LEVEL, "error");'