Skip to content

Appium fixes #1609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions docs/helpers/Appium.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Field is located by name, label, CSS, or XPath.
// by label
I.fillField('Email', 'hello@world.com');
// by name
I.fillField('password', '123456');
I.fillField('password', secret('123456'));
// by CSS
I.fillField('form#login input[name=username]', 'John');
// or by strict locator
Expand Down Expand Up @@ -376,25 +376,7 @@ I.performswipe(100,200);
#### Parameters

- `from`
- `to`

Appium: support Android and iOS

### performTouchAction

Perform a certain touch action on the screen such as swipeDown, swipeUp, swipeLeft, swipeRight.

```js
I.swipeDown('swipeDown'); // perform swipe down on the screen
I.swipeDown('swipeUp'); // perform swipe up on the screen
I.swipeDown('swipeLeft'); // perform swipe left on the screen
I.swipeDown('swipeRight'); // perform swipe right on the screen
```

#### Parameters

- `action`
- `percentage` (optional), from 0 - 1, 1 by defaultAppium: support Android and iOS
- `to` Appium: support Android and iOS

### pullFile

Expand Down Expand Up @@ -704,6 +686,19 @@ I.sendDeviceKeyEvent(3);

- `keyValue` Device specific key valueAppium: support only Android

### sendKey

Send a sequence of key strokes to an element

```js
I.sendKey('~email of the customer', '1');;
```

#### Parameters

- `locator` element to send a sequence of key strokes
- `keys` a sequence of key strokes to send to an element

### setImmediateValue

Set immediate value in app.
Expand Down
105 changes: 18 additions & 87 deletions lib/helper/Appium.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,6 @@ const axios = requireg('axios');

const mobileRoot = '//*';
const webRoot = 'body';
const SWIPE_DIRECTION = {
down: {
start: { x: 50, y: 15 },
end: { x: 50, y: 85 },
},
left: {
start: { x: 95, y: 50 },
end: { x: 5, y: 50 },
},
right: {
start: { x: 5, y: 50 },
end: { x: 95, y: 50 },
},
up: {
start: { x: 50, y: 85 },
end: { x: 50, y: 15 },
},
};


/**
* Appium helper extends [Webriver](http://codecept.io/helpers/WebDriver/) helper.
Expand Down Expand Up @@ -826,6 +807,23 @@ class Appium extends Webdriver {
return this.browser.pressKeyCode(keyValue);
}

/**
* Send a sequence of key strokes to an element
*
* ```js
* I.sendKey('~email of the customer', '1');;
* ```
*
* @param locator element to send a sequence of key strokes
* @param keys a sequence of key strokes to send to an element
*
*/
async sendKey(locator, keys) {
onlyForApps.call(this);
const res = await this.browser.$(parseLocator.call(this, locator));
return res.addValue(keys);
}

/**
* Open the notifications panel on the device.
*
Expand Down Expand Up @@ -878,30 +876,6 @@ class Appium extends Webdriver {
return this.makeTouchAction(locator, 'tap');
}

_calculateXY({ x, y }, percentage) {
return {
x: x * percentage,
y: y * percentage,
};
}

_getDeviceScreenCoordinates(screenSize, coordinates) {
return {
x: Math.round(screenSize.width * (coordinates.x / 100)),
y: Math.round(screenSize.height * (coordinates.y / 100)),
};
}

async _swipeOnPercentage(from, to) {
SCREEN_SIZE = SCREEN_SIZE || await this.browser.getWindowRect();
const pressOptions = this._getDeviceScreenCoordinates(SCREEN_SIZE, from);
const moveToScreenCoordinates = this._getDeviceScreenCoordinates(SCREEN_SIZE, to);
await this.performSwipe(
pressOptions,
moveToScreenCoordinates,
);
}

/**
* Perform a swipe on the screen or an element.
*
Expand All @@ -923,7 +897,7 @@ class Appium extends Webdriver {
onlyForApps.call(this);
const res = await this.browser.$(parseLocator.call(this, locator));
// if (!res.length) throw new ElementNotFound(locator, 'was not found in UI');
return this.browser.touchFlick(xoffset, yoffset, res.ELEMENT, speed);
return this.performSwipe(await res.getLocation(), { x: await res.getLocation().x + xoffset, y: await res.getLocation().y + yoffset });
}

/**
Expand Down Expand Up @@ -982,50 +956,7 @@ class Appium extends Webdriver {
}

/**
* Perform a certain touch action on the screen such as swipeDown, swipeUp, swipeLeft, swipeRight.
*
* ```js
* I.swipeDown('swipeDown'); // perform swipe down on the screen
* I.swipeDown('swipeUp'); // perform swipe up on the screen
* I.swipeDown('swipeLeft'); // perform swipe left on the screen
* I.swipeDown('swipeRight'); // perform swipe right on the screen
* ```
*
* @param action
* @param percentage (optional), from 0 - 1, 1 by default
*
* Appium: support Android and iOS
*/
async performTouchAction(action, percentage = 1) {
switch (action) {
case 'swipeDown':
this._swipeOnPercentage(
this._calculateXY(SWIPE_DIRECTION.down.start, percentage),
this._calculateXY(SWIPE_DIRECTION.down.end, percentage),
);
break;
case 'swipeUp':
this._swipeOnPercentage(
this._calculateXY(SWIPE_DIRECTION.up.start, percentage),
this._calculateXY(SWIPE_DIRECTION.up.end, percentage),
);
break;
case 'swipeLeft':
this._swipeOnPercentage(
this._calculateXY(SWIPE_DIRECTION.left.start, percentage),
this._calculateXY(SWIPE_DIRECTION.left.end, percentage),
);
break;
case 'swipeRight':
this._swipeOnPercentage(
this._calculateXY(SWIPE_DIRECTION.right.start, percentage),
this._calculateXY(SWIPE_DIRECTION.right.end, percentage),
);
break;
}
}

/**
* Perform a swipe left on an element.
*
* ```js
Expand Down
78 changes: 39 additions & 39 deletions test/helper/Appium_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Appium', function () {
app = new Appium({
app: apk_path,
desiredCapabilities: {
appiumVersion: '1.6.4',
appiumVersion: '1.9.1',
browserName: '',
recordVideo: 'false',
recordScreenshots: 'false',
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('Appium', function () {
},
);

it.only('should remove App and install it again', () => app.seeAppIsInstalled('io.selendroid.testapp')
it('should remove App and install it again', () => app.seeAppIsInstalled('io.selendroid.testapp')
.then(() => app.removeApp('io.selendroid.testapp'))
.then(() => app.seeAppIsNotInstalled('io.selendroid.testapp'))
.then(() => app.installApp(apk_path))
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('Appium', function () {
assert.equal(val, '.WebViewActivity');
});

it('should react on swipe action @second', function* () {
it('should react on swipe action', function* () {
yield app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
yield app.waitForText(
'Gesture Type', 10,
Expand Down Expand Up @@ -254,14 +254,18 @@ describe('Appium', function () {
assert.ok(vy.match(/vy: \d\d000\.0 pps/), 'to be like \d\d000.0 pps');
});

it('run simplified swipeDown @quick', function* () {
yield app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
yield app.waitForText(
it('run simplified swipeDown @quick', async () => {
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
await app.waitForText(
'Gesture Type', 10,
"//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']",
);
yield app.swipeDown('#io.selendroid.testapp:id/LinearLayout1');
const type = yield app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
// yield app.swipeDown('#io.selendroid.testapp:id/LinearLayout1');
await app.swipeDown(
"//android.widget.LinearLayout[@resource-id = 'io.selendroid.testapp:id/LinearLayout1']",
1200, 1000,
);
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
// const vy = yield app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/text_view4']");
assert.equal(type, 'FLICK');
});
Expand Down Expand Up @@ -345,60 +349,56 @@ describe('Appium', function () {
});

describe('#performTouchAction', () => {
it('should react on swipeUp action', function* () {
yield app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
yield app.waitForText(
it('should react on swipeUp action @second', async () => {
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
await app.waitForText(
'Gesture Type', 10,
"//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']",
);
yield app.performTouchAction('swipeUp');
const type = yield app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const vy = yield app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/text_view4']");
console.log(vy.split(' ')[1]);
await app.swipeUp("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const vy = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/text_view4']");
assert.equal(type, 'FLICK');
expect(vy.split(' ')[1]).to.be.below(1006);
});

it('should react on swipeDown action', function* () {
yield app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
yield app.waitForText(
it('should react on swipeDown action @second', async () => {
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
await app.waitForText(
'Gesture Type', 10,
"//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']",
);
yield app.performTouchAction('swipeDown');
const type = yield app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const vy = yield app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/text_view4']");
console.log(vy.split(' ')[1]);
await app.swipeUp("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const vy = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/text_view4']");
assert.equal(type, 'FLICK');
expect(vy.split(' ')[1]).to.be.above(178);
});

it('should react on swipeLeft action', function* () {
yield app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
yield app.waitForText(
it('should react on swipeLeft action', async () => {
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
await app.waitForText(
'Gesture Type', 10,
"//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']",
);
yield app.performTouchAction('swipeLeft');
const type = yield app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const vy = yield app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/text_view4']");
console.log(vy.split(' ')[1]);
await app.swipeLeft("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const vy = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/text_view4']");
assert.equal(type, 'FLICK');
expect(vy.split(' ')[1]).to.be.below(730);
});

it('should react on swipeRight action', function* () {
yield app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
yield app.waitForText(
it('should react on swipeRight action', async () => {
await app.click("//android.widget.Button[@resource-id = 'io.selendroid.testapp:id/touchTest']");
await app.waitForText(
'Gesture Type', 10,
"//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']",
);
yield app.performTouchAction('swipeRight');
const type = yield app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const vy = yield app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/text_view4']");
console.log(vy.split(' ')[1]);
await app.swipeRight("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const type = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/gesture_type_text_view']");
const vy = await app.grabTextFrom("//android.widget.TextView[@resource-id = 'io.selendroid.testapp:id/text_view4']");
assert.equal(type, 'FLICK');
expect(vy.split(' ')[1]).to.be.below(38);
expect(vy.split(' ')[1]).to.be.above(278);
});
});
});
Expand All @@ -424,11 +424,11 @@ describe('Appium', function () {
});
});

describe('#pressKey', () => {
describe('#sendKey', () => {
it('should be able to send special keys to element @second', function* () {
yield app.click('~startUserRegistrationCD');
yield app.click('~email of the customer');
yield app.pressKey('1');
yield app.sendKey('~email of the customer', '1');
yield app.hideDeviceKeyboard('pressKey', 'Done');
yield app.swipeTo(
'//android.widget.Button', '//android.widget.ScrollView/android.widget.LinearLayout', 'up', 30,
Expand Down