-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add global
app
alias to browser
to be used for native app testing. (
- Loading branch information
Showing
5 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,7 @@ | |
"by": "readonly", | ||
"expect": "readonly", | ||
"browser": "readonly", | ||
"app": "readonly", | ||
"Key": "readonly" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const assert = require('assert'); | ||
|
||
describe('appium api demo', function () { | ||
after((app) => app.end()); | ||
|
||
const availableAppiumCommands = [ | ||
'startActivity', | ||
'getCurrentActivity', | ||
'getCurrentPackage', | ||
'getOrientation', | ||
'setOrientation', | ||
'getGeolocation', | ||
'setGeolocation', | ||
'pressKeyCode', | ||
'longPressKeyCode', | ||
'hideKeyboard', | ||
'isKeyboardShown', | ||
'getContexts', | ||
'getContext', | ||
'setContext' | ||
]; | ||
|
||
it('test appium available API commands', async function () { | ||
// app variable is available globally | ||
assert.strictEqual(app !== undefined, true); | ||
|
||
availableAppiumCommands.forEach((command) => { | ||
assert.strictEqual(typeof app.appium[command], 'function'); | ||
}); | ||
}); | ||
|
||
it('Search for Nightwatch', async function() { | ||
app // available globally | ||
.click('id', 'com.app:id/search') | ||
.sendKeys('id', 'com.app:id/search', 'Nightwatch'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
const {strictEqual} = require('assert'); | ||
const path = require('path'); | ||
const common = require('../../../common.js'); | ||
const MockServer = require('../../../lib/mockserver.js'); | ||
const NightwatchClient = common.require('index.js'); | ||
|
||
describe('appium api demos', function () { | ||
beforeEach(function (done) { | ||
this.server = MockServer.init(undefined, {port: 4723}); | ||
this.server.on('listening', () => { | ||
done(); | ||
}); | ||
}); | ||
|
||
afterEach(function (done) { | ||
this.server.close(function () { | ||
done(); | ||
}); | ||
}); | ||
|
||
it('run appium api demo tests basic', function () { | ||
const testsPath = path.join(__dirname, '../../../apidemos/appium/appiumTest.js'); | ||
|
||
const globals = { | ||
waitForConditionPollInterval: 50, | ||
|
||
reporter(results) { | ||
if (results.lastError) { | ||
throw results.lastError; | ||
} | ||
} | ||
}; | ||
|
||
MockServer | ||
.addMock({ | ||
url: '/wd/hub/session', | ||
method: 'POST', | ||
response: JSON.stringify({ | ||
value: { | ||
sessionId: '13521-10219-202', | ||
version: 'TEST', | ||
platform: 'TEST' | ||
} | ||
}) | ||
}, true) | ||
.addMock({ | ||
url: '/wd/hub/session/13521-10219-202/elements', | ||
postdata: { | ||
using: 'id', | ||
value: 'com.app:id/search' | ||
}, | ||
method: 'POST', | ||
response: JSON.stringify({ | ||
status: 0, | ||
state: 'success', | ||
value: [{'element-6066-11e4-a52e-4f735466cecf': '0'}] | ||
}) | ||
}, true, true) | ||
.addMock({ | ||
url: '/wd/hub/session/13521-10219-202/element/0/click', | ||
method: 'POST', | ||
response: JSON.stringify({ | ||
value: null | ||
}) | ||
}, true) | ||
.addMock({ | ||
url: '/wd/hub/session/13521-10219-202/element/0/value', | ||
method: 'POST', | ||
postdata: JSON.stringify({ | ||
text: 'Nightwatch', | ||
value: 'Nightwatch'.split('') | ||
}), | ||
response: JSON.stringify({ | ||
value: null | ||
}) | ||
}, true); | ||
|
||
return NightwatchClient.runTests(testsPath, { | ||
selenium: { | ||
host: 'localhost', | ||
port: 4723, | ||
start_process: false, | ||
use_appium: true | ||
}, | ||
desiredCapabilities: { | ||
browserName: '' | ||
}, | ||
output: false, | ||
skip_testcases_on_fail: false, | ||
silent: true, | ||
persist_globals: true, | ||
globals, | ||
output_folder: false | ||
}).then(_ => { | ||
strictEqual(NightwatchClient.app !== undefined, true); | ||
}); | ||
}); | ||
}); |