Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
295 views
in Technique[技术] by (71.8m points)

javascript - Webdriverio:访问窗口对象(Webdriverio: access to window object)

I'm trying Webdriverio Testrunner with Selenium Standalone.

(我正在尝试使用Selenium Standalone的Webdriverio Testrunner。)

One test I would like to do should check a global variable (window.myVar) but when I try to return the window object I receive something weird

(我想做的一个测试应该检查一个全局变量(window.myVar),但是当我尝试返回窗口对象时,我收到一些奇怪的信息)

it('should return window', (done) => {

const url = 'http://www.example.com';

browser.url(url);
browser.waitForVisible('body', 20000);
browser.pause(1000);
browser.execute(getWindow)
    .then(result => {
        console.log(result);
    });

});

(});)

This print:

(此打印:)

?{ sessionId: '6f0cd910-2ec8-11e8-80fb-bf4604ec860e',
  status: 0,
  value: { WINDOW: ':wdc:1521829902692' } }

What is WINDOW: ':wdc:1521829902692'?

(什么是WINDOW:':wdc:1521829902692'?)

How can I get the actual window object?

(如何获得实际的窗口对象?)

  ask by Luca S. translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For that scenario, you don't need to return the window object.

(对于这种情况,您不需要返回window对象。)

You can get your global variable like this: window['myVar']

(您可以像这样获取全局变量: window['myVar'])

Here is my working test code (Webdriverio version 5+) in Jasmine:

(这是我在Jasmine中工作的测试代码(Webdriverio版本5+):)

  var result = browser.execute(function() {
    return window['outerWidth']
  });
  console.log(result); // <- returns a number

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...