|
| 1 | +# Aquality Appium Mobile for Java |
| 2 | + |
| 3 | +[](https://dev.azure.com/aquality-automation/aquality-automation/_build/latest?definitionId=6&branchName=master) |
| 4 | +[](https://sonarcloud.io/dashboard?id=aquality-automation_aquality-appium-mobile-java) |
| 5 | + |
| 6 | +### Overview |
| 7 | + |
| 8 | +This package is a library designed to simplify automation of Android and iOS mobile applications using Appium. |
| 9 | + |
| 10 | +You've got to use this set of methods, related to most common actions performed with web elements. |
| 11 | + |
| 12 | +Most of performed methods are logged using LOG4J, so you can easily see a history of performed actions in your log. |
| 13 | + |
| 14 | +We use interfaces where is possible, so you can implement your own version of target interface with no need to rewrite other classes. |
| 15 | + |
| 16 | +### Quick start |
| 17 | + |
| 18 | +1. To start work with this package, simply add the dependency to your pom.xml: |
| 19 | +``` |
| 20 | +<dependency> |
| 21 | + <groupId>com.github.aquality-automation</groupId> |
| 22 | + <artifactId>aquality-selenium</artifactId> |
| 23 | + <version>1.0.0</version> |
| 24 | +</dependency> |
| 25 | +``` |
| 26 | + |
| 27 | +2. Configure path to your application at settings.json: |
| 28 | + - Copy [settings.json](./src/main/resources/settings.json) into the resources directory of your project. |
| 29 | + - Open settings.json and find `applicationPath` option under the `driverSettings` section of desired platform. Replace the value with full or relative path to your app, e.g. `./src/test/resources/apps/ApiDemos-debug.apk`. |
| 30 | + |
| 31 | +3. Ensure that [Appium server](https://appium.io) is set up at your machine where the code would be executed, and the address/port match to set in your `settings.json` in `remoteConnectionUrl` parameter. |
| 32 | +If the parameter `isRemote` in your settings.json is set to `false`, this means that AppiumDriverLocalService would be used to setup Appium server using Node.js. This option requires specific version of node.js to be preinstalled on your machine (Please read more [here](http://appium.io/docs/en/contributing-to-appium/appium-from-source/#nodejs) ) |
| 33 | + |
| 34 | +4. (optional) Launch an application directly by calling `AqualityServices.getApplication();`. |
| 35 | +> Note: |
| 36 | +If you don't start an Application directly, it would be started with the first call of any Aquality service or class requiring interacting with the Application. |
| 37 | + |
| 38 | +5. That's it! Now you are able work with Application via AqualityServices or via element services. |
| 39 | +Please take a look at our example tests [here](./src/test/java/samples/android/AndroidBasicInteractionsTest.java) |
| 40 | + |
| 41 | +6. To interact with Application's forms and elements, we recommend following the Page/Screen Objects pattern. This approach is fully integrated into our package. |
| 42 | +To start with that, you will need to create a separate class for each window/form of your application, and inherit this class from the [AndroidScreen](./src/main/java/aquality/appium/mobile/screens/AndroidScreen.java) or [IOSScreen](./src/main/java/aquality/appium/mobile/screens/IOSScreen.java) respectively. |
| 43 | + |
| 44 | +> We recommend to use separate Screen class for each form of your application. You can take advantage of inheritance and composition pattern. We also suggest not to mix app different platforms in single class: take advantage of interfaces instead, adding the default implementation to them if is needed. |
| 45 | +
|
| 46 | + |
| 47 | +7. From the Screen Object perspective, each Screen consists of elements on it (e.g. Buttons, TextBox, Labels and so on). |
| 48 | +To interact with elements, on your form class create fields of type IButton, ITextBox, ILabel, and initialize them using the `getElementFactory()`. Created elements have a various methods to interact with them. We recommend combining actions into a business-level methods: |
| 49 | + |
| 50 | +```java |
| 51 | +package samples.android.apidemos.screens; |
| 52 | + |
| 53 | +import aquality.appium.mobile.elements.interfaces.IButton; |
| 54 | +import aquality.appium.mobile.elements.interfaces.ILabel; |
| 55 | +import aquality.appium.mobile.elements.interfaces.ITextBox; |
| 56 | +import aquality.appium.mobile.screens.AndroidScreen; |
| 57 | +import org.openqa.selenium.By; |
| 58 | + |
| 59 | +public class InvokeSearchScreen extends AndroidScreen { |
| 60 | + |
| 61 | + private final ITextBox txbSearch = getElementFactory().getTextBox(By.id("txt_query_prefill"), "Search"); |
| 62 | + private final IButton btnStartSearch = getElementFactory().getButton(By.id("btn_start_search"), "Start search"); |
| 63 | + private final ILabel lblSearchResult = getElementFactory().getLabel(By.id("android:id/search_src_text"), "Search results"); |
| 64 | + |
| 65 | + public InvokeSearchScreen() { |
| 66 | + super(By.xpath("//android.widget.TextView[@text='App/Search/Invoke Search']"), "Invoke Search"); |
| 67 | + } |
| 68 | + |
| 69 | + public void submitSearch(String query) { |
| 70 | + txbSearch.clearAndType(query); |
| 71 | + btnStartSearch.click(); |
| 72 | + } |
| 73 | + |
| 74 | + public String getSearchResult() { |
| 75 | + return lblSearchResult.getText(); |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +``` |
| 80 | + |
| 81 | +8. We use DI Guice to inject dependencies, so you can simply implement your MobileModule extended from [MobileModule](./src/main/java/aquality/appium/mobile/application/MobileModule.java) and inject it to `AqualityServices.initInjector(yourModule)`. |
| 82 | + |
0 commit comments