实际结果和预期结果显示

时间:2019-04-09 07:07:22

标签: node.js selenium

在此处输入代码`我已经运行了硒webdriver IO的代码,并且还在npm中安装了chrome驱动程序,我想测试Google网站的标题。但是当我运行此代码时,它将显示此消息

 2019-04-09T06:56:33.109Z INFO webdriver: [POST] http://0.0.0.0:4444/wd/hub/session
    2019-04-09T06:56:33.113Z INFO webdriver: DATA { capabilities:
       { alwaysMatch: { browserName: 'chrome' }, firstMatch: [ {} ] },
      desiredCapabilities: { browserName: 'chrome' } }

它将仅在npm命令提示符下生成此代码

var webdriverio = require('webdriverio');

var options = {
    capabilities: {
        browserName: 'chrome'
    }

}

webdriverio.remote(options).then(browser => {
    browser
        .init()
        .url('http://www.google.com')
        .title(function(err, res) {
            console.log('Title was: ' + res.value);
            browser.end();
        })
});

Expected Result:Get title of site
Actual resule: not display title of google

它将显示为以上消息

1 个答案:

答案 0 :(得分:3)

尝试一下,这样就可以测试一种不同的方法,并通过logLevel: 'trace'捕获有关该问题的更多详细信息:

const { remote } = require('webdriverio');

(async () => {
    const browser = await remote({
        logLevel: 'trace',
        capabilities: {
            browserName: 'chrome'
        }
    })

    await browser.url('https://duckduckgo.com/')
    console.log(await browser.getTitle()) // Expected outputs: "Title is: WebdriverIO (Software) at DuckDuckGo"

    await browser.deleteSession()
})().catch((e) => console.error(e))