Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit ae97171

Browse files
committed
Writing new tests 🚀
1 parent e0442a0 commit ae97171

File tree

1 file changed

+98
-4
lines changed

1 file changed

+98
-4
lines changed

_drafts/2019-02-10-mobile-ui-test-crossplatform-appium.md

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,103 @@ authors: [fabrizio_duroni]
1616
---
1717

1818
During my daily job I'm used to write unit test for my code. In fact, I usually develop using [Test Driven Development]() technique. Anyway at the end of the development of a new feature you want to be sure that everything you developer works as expected. In particular, you want to test the entire new feature flow inside the app. This is usually what is called [end to end test]().
19-
In the last few months the mobile team "team cook" at [lastminute.com group](), of which I'm a member, decided to put in place an end to end testing infrastructure for the mobile apps of our main brand [lastminute.com](), [volagratis]() and [rumbo](). In this post I will described this testing infrastructure and how it works.
19+
In the last few months the mobile team "team cook" at [lastminute.com group](), of which I'm a member, decided to put in place an end to end testing infrastructure for the mobile apps of our main brand [lastminute.com](https://lmgroup.lastminute.com/), [volagratis](https://www.volagratis.com/) and [rumbo](https://www.rumbo.es/). In this post I will described this testing infrastructure and how it works.
20+
2021
#### **Software**
21-
To put in place the e2e infrastructure we choose
22+
To put in place the e2e infrastructure we choose:
23+
24+
- Jenkins as our CI platform. Jenkins was already in place for our build jobs and for the submssions on the stores or to [our internal beta programs](/2018/07/05/distribution-enterprise-app-ios-beta.html).
25+
- Appium as end to end testing platform. We chose it because it let us test our apps for both iOS and Android with a single tests codebase. At the moment of this writing we used the Appium version 1.9.0. In particular we chose to use the appium implementation based on:
26+
- JavaScript, to be able to write our tests with a language with similar features to [TypeScript, the language we are using with React Native for our apps](/2018/07/04/react-native-typescript-existing-app.html "TypeScript React Native")
27+
- WebdriverIO is a JavaScript implementation of the Selenium 2.0 WebDriver API
28+
- [mocha](https://github.com/mochajs/mocha "mocha test framework"), a JavaScript test framework
29+
- [babel](https://github.com/babel/babel "babel es6"), is a compiler for writing next generation JavaScript
30+
- [Appium XCUITest Driver](https://appium.io/docs/en/drivers/ios-xcuitest/index.html "appium ios driver") for iOS
31+
- [Appium UiAutomator Driver](https://appium.io/docs/en/drivers/android-uiautomator2/index.html "appium android driver") for Android
32+
33+
#### **How it works**
34+
The first thing we did was installing all the above software on our CI machine. As a consequence of the fact that we want to run tests for both iOS and Android a macOS based CI machine is needed (because you need to install Xcode). Fortunately, our CI machine was already an Apple Computer so we didn't need to change anything.
35+
After that we created a new javascript project that follows the structure of the [WebdriverIO sample code contained in the Appium github repository](https://github.com/appium/appium/tree/master/sample-code/javascript-webdriverio "appium webdriverio sample"). This sample project is written using ES5 syntax, so we decided to upgrade to use ES6 syntax and compile it using Babel. This is possible by launching mocha and specifing babel as the compiler. This is the final command to launch our tests:
36+
37+
```shell
38+
mocha --compilers js:babel-core/register --timeout 6000000 test
39+
```
40+
41+
This is the final `package.json` with all the dependecies and scripts phases.
42+
43+
```json
44+
{
45+
"name": "e2e-tests",
46+
"version": "1.0.0",
47+
"description": "e2e tests",
48+
"main": "index.js",
49+
"scripts": {
50+
"pretest": "./download-artifacts.sh",
51+
"test": "mocha --compilers js:babel-core/register --timeout 6000000 test"
52+
},
53+
"author": "Fabrizio Duroni",
54+
"license": "MIT",
55+
"devDependencies": {
56+
"assert": "^1.4.1",
57+
"babel-core": "^6.26.3",
58+
"babel-preset-env": "^1.7.0",
59+
"chai": "^4.1.2",
60+
"mocha": "^5.0.0",
61+
"webdriverio": "^4.12.0"
62+
}
63+
}
64+
```
65+
66+
As you may already notice from the package.json file above, there's a `pretest` phase that launches a script called `download-artifacts.sh`. This a custom script we added to download the latest release of our iOS ipa and Android apk artifacts. This will be the apps installed on the iOS simulators/Android emulators and tested with appium.
67+
After that we created the iOS and Android appium config to be used by our tests.
68+
69+
```javascript
70+
import path from "path";
71+
72+
const iOSConfig = {
73+
protocol: "http",
74+
host: "localhost",
75+
port: 4723,
76+
path: "/wd/hub",
77+
logLevel: "verbose",
78+
desiredCapabilities: {
79+
platformName: "iOS",
80+
automationName: "XCUITest",
81+
deviceName: "iPhone 8",
82+
platformVersion: "11.4",
83+
clearSystemFiles: true,
84+
wdaStartupRetryInterval: 1000,
85+
useNewWDA: true,
86+
waitForQuiescence: false,
87+
shouldUseSingletonTestManager: false,
88+
app: path.resolve(__dirname, "..", "apps", "<ipa downloaded using pretest download.sh script>"),
89+
orientation: "PORTRAIT",
90+
}
91+
};
92+
93+
const androidConfig = {
94+
host: "localhost",
95+
port: 4723,
96+
logLevel: "verbose",
97+
desiredCapabilities: {
98+
platformName: "Android",
99+
automationName: "UiAutomator2",
100+
deviceName: "Pixel_XL_API_27",
101+
platformVersion: "8.1",
102+
app: path.resolve(__dirname, "..", "apps", "<apk downloaded using pretest download.sh script>")
103+
}
104+
};
105+
106+
export {iOSConfig, androidConfig}
107+
```
108+
109+
One important thing to note about the configuration above is that for iOS we were forced to set the following for options:
110+
111+
```javascript
112+
wdaStartupRetryInterval: 1000,
113+
useNewWDA: true,
114+
waitForQuiescence: false,
115+
shouldUseSingletonTestManager: false,
116+
```
22117

23-
- Jenkins as our CI platform. Jenkins was already in place for our build jobs and for the submssions on the stores or to [our internal beta programs](https://www.fabrizioduroni.it/2018/07/05/distribution-enterprise-app-ios-beta.html).
24-
- Appium as end to end testing platform. We chose it because it let us test our apps for both iOS and Android with a single tests codebase. In particular we chose javascript and webdriverio.....
118+
This were need in order to avoid a [know bug in appium for iOS](https://github.com/appium/appium/issues/9645) that causes the appium test suite be get stuck on iOS during the creation of the appium webdriver session.

0 commit comments

Comments
 (0)