Selenium webdriver 如何使用量角器访问wd特定的移动API

Selenium webdriver 如何使用量角器访问wd特定的移动API,selenium-webdriver,webdriver,protractor,appium,Selenium Webdriver,Webdriver,Protractor,Appium,我已经使用了下面提到的钩子来使用wd特定的API,但我无法做到这一点。假设我想关闭应用程序。我该怎么做呢。它还在读取wdBrowser,但在调用currentContext()时不打印上下文 规格js describe('Login page testcases', function() { it('should print context of the device', function() { wdBrowser.currentContext().then(f

我已经使用了下面提到的钩子来使用wd特定的API,但我无法做到这一点。假设我想关闭应用程序。我该怎么做呢。它还在读取wdBrowser,但在调用currentContext()时不打印上下文

规格js

describe('Login page testcases', function() {


    it('should print context of the device', function() {

         wdBrowser.currentContext().then(function(value) {
            console.log(+value)
        })
         browser.quit();
    });

可以找到有关WD-API的更多信息。只需使用全局
wdBrowser
-对象而不是全局量角器
browser
-对象即可访问API

在应用程序上执行方法之前,还要检查是否需要更改上下文(本机/网络视图)


希望能有所帮助

我可以看到以下几点:

  • 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();        
        });
    });
});    

谢谢你的回复。我面临的问题是全局对象浏览器无法调用其方法。类似于wdBrowser.currentContext().then(函数(值){console.log(值)})。。。。。。。这不会打印上下文值功能:{browserName:'',platformName:'Android',platformVersion:'6.0',deviceName:'ZX1D62CVWH',autoWebview:true,//将此路径更改为应用程序应用程序的绝对路径:'/Users/abhishek/abhishek test OrganizationingMobileApp/Android debug.apk'},您是否将代码放置在
wdBridge.initFromGragrator(exports.config)中
在onPrepare中?如果是的话,你能将配置文件和规范文件粘贴到这里吗?请检查更新的问题。我提到了我的onPrepare编码你能将规范文件粘贴到这里吗?@wswebcreation updated所有代码看起来都不错,但是:1.当你记录上下文时应用程序真的打开了吗?2.如果你删除
浏览器。quit()会发生什么情况;
。据我所知,您永远不需要使用
浏览器。quit();
因为当所有STEP文件都运行时,量角器就会这样做。1)是的,它会打开。2)即使我删除了它,它主要还是保持不变,那么还有一些其他问题困扰着它。使用此代码看不到它。您有示例项目吗?
describe('Login page testcases', function() {
    it('should print context of the device', function(done) {
         wdBrowser.currentContext().then(function(value) {
            console.log(value);
            done();        
        });
    });
});