Skip to content
This repository has been archived by the owner on Sep 4, 2021. It is now read-only.

Commit

Permalink
appium test
Browse files Browse the repository at this point in the history
  • Loading branch information
devfd committed May 17, 2016
1 parent 753db4f commit 14a99ec
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
e2e/GeocoderE2EApp

# OSX
#
.DS_Store
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
img
example
e2e
test

# OSX
#
Expand Down
15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "react native geocoding and reverse geocoding",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "npm run e2e",
"e2e": "e2e/prepare.sh && e2e/run.sh"
},
"keywords": [
"react-component",
Expand All @@ -26,5 +27,15 @@
"url": "https://github.com/devfd/react-native-geocoder/issues"
},
"homepage": "https://github.com/devfd/react-native-geocoder",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"appium": "^1.5.2",
"babel-core": "^6.8.0",
"babel-polyfill": "^6.8.0",
"babel-preset-react-native": "^1.8.0",
"chai": "^3.5.0",
"colors": "^1.1.2",
"mocha": "^2.4.5",
"wd": "^0.4.0"
}
}
10 changes: 10 additions & 0 deletions test/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require('babel-core/register')({
presets: ["react-native"]
});
require("babel-polyfill");

require('colors');

process.on('unhandledRejection', function(reason, p) {
throw new Error(reason);
});
14 changes: 14 additions & 0 deletions test/helpers/logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";

exports.configure = function (driver) {
// See whats going on
driver.on('status', function (info) {
console.log(info.cyan);
});
driver.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
driver.on('http', function (meth, path, data) {
console.log(' > ' + meth.magenta, path, (data || '').grey);
});
};
84 changes: 84 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import wd from 'wd';
import path from 'path';
import { expect } from 'chai';

const London = {
lat: 51.50853,
lng: -0.12574,
};

const Paris = {
lat: 48.85341,
lng: 2.3488,
};

describe ('react-native-geocoder', function() {
this.timeout(600000);

let driver;

before(() => {
driver = wd.promiseChainRemote({
host: 'localhost',
port: 4723
});
require("./helpers/logging").configure(driver);

return driver
.init({
platformName: 'Android',
deviceName: 'Android Emulator',
newCommandTimeout: 60000,
app: path.resolve('e2e/GeocoderE2EApp/android/app/build/outputs/apk/app-debug.apk')
})
.setImplicitWaitTimeout(3000);
// .waitForElementByXPath('//android.widget.Button[@text="Reload JS"]').
// then((elem) => {
// elem.click();
// }, (err) => {
// ignoring if Reload JS button can't be located
// })
});

after(() => {
return driver.quit();
});


it ('displays default view', async () => {
await driver.waitForElementByXPath('//android.widget.EditText[1]', 30000); // wait for view to be initialized
await driver.waitForElementByXPath('//android.widget.EditText[2]');
await driver.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Geocode")]');
await driver.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Reverse")]');
});

it ('geocodes address', async () => {
await driver.waitForElementByXPath('//android.widget.EditText[1]').sendKeys("London");
await driver.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Geocode")]').click().click();

const locality = await driver.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Locality")]', 5000).text();
expect(locality.split(':')[1].trim().toLowerCase()).to.contain('london');

const latlng = await driver.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "LatLng")]').text();
const [lat, lng] = latlng.split(':')[1].split(',').map(v => 1 * v.trim());

expect(lat - London.lat).to.be.below(0.001);
expect(lng - London.lng).to.be.below(0.001);
});

it ('geocodes lat lng into address', async () => {
await driver.waitForElementByXPath('//android.widget.EditText[2]').sendKeys(`${Paris.lat} ${Paris.lng}`);
await driver.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Reverse")]').click().click();

const locality = await driver.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Locality")]', 5000).text();
expect(locality.split(':')[1].trim().toLowerCase()).to.contain('paris');

const latlng = await driver.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "LatLng")]').text();
const [lat, lng] = latlng.split(':')[1].split(',').map(v => 1 * v.trim());

expect(lat - Paris.lat).to.be.below(0.001);
expect(lng - Paris.lng).to.be.below(0.001);
});

});

0 comments on commit 14a99ec

Please sign in to comment.