我使用下面提到的钩子来使用wd特定的apis但是我无法做到。假设我要关闭应用程序。我该怎么做呢。它也是读取wdBrowser但是在调用currentContext()
时不打印上下文'use strict';
var log4js = require('log4js');
var fs = require('fs');
exports.config = {
capabilities: {
browserName: '',
platformName: 'Android',
platformVersion: '6.0',
deviceName: 'ZX1D62CVWH',
autoWebview: true,
// change this path to the absolute path of the app
app: '/Users/abhishek/abhishek-test-volunteeringMobileApp/android-debug.apk'
},
//restartBrowserBetweenTests: true,
// Framework to use. Jasmine is recommended.
framework: 'jasmine2',
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: ['Specs/LoginSpec.js'],
seleniumAddress: 'http://localhost:4723/wd/hub',
// 'seleniumAddress': 'http://hub-cloud.browserstack.com/wd/hub',
// Override the timeout for webdriver to 20 seconds.
allScriptsTimeout: 90000,
getPageTimeout: 90000,
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 90000,
showColors: true
// allScriptsTimeout: 50000
},
onPrepare: function() {
// implicit and page load timeouts
browser.manage().timeouts().pageLoadTimeout(40000);
browser.manage().timeouts().implicitlyWait(25000);
// for non-angular page
// browser.ignoreSynchronization = true;
var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');
jasmine.getEnv().addReporter(
new Jasmine2HtmlReporter({
captureOnlyFailedSpecs: true,
savePath: './Web_Automation_Summary',
takeScreenShotsOnlyForFailedSpecs: true,
cleanDestination: true,
fileName: 'Automation_Report'
})
);
var wd = require('wd'),
protractor = require('protractor'),
wdBridge = require('wd-bridge')(protractor, wd);
wdBridge.initFromProtractor(exports.config);
}
}
Spec.js
describe('Login page testcases', function() {
it('should print context of the device', function() {
wdBrowser.currentContext().then(function(value) {
console.log(+value)
})
browser.quit();
});
答案 0 :(得分:0)
可以找到有关WD-API的更多信息here。您只需使用全局wdBrowser
- 对象代替全局量角器browser
- 对象来访问API。
还要检查在应用程序上执行方法之前是否需要更改上下文(NATIVE / WEBVIEW)。
希望有所帮助
答案 1 :(得分:0)
我可以看到几件事:
browser.quit()
放在您拥有它的位置将在currentContext承诺解决之前退出 - 无论如何都不需要它。console.log(+value)
在语法上不正确:应为console.log(value)
done
使量角器等到调用该函数所以尝试这样的事情:
describe('Login page testcases', function() {
it('should print context of the device', function(done) {
wdBrowser.currentContext().then(function(value) {
console.log(value);
done();
});
});
});