我想用Nightwatch为我的Vue.js项目进行UI测试。 我想用PhantomeJS作CI。
但是PhantomeJS似乎没有在body标签下读取任何元素。 你如何用PhantomJS声明任何元素?
我发现了这个错误:
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:color="#ffffff"
android:textSize="25sp"></Button>
我的测试来源:
√ Element <body> was visible after 47 milliseconds.
√ Testing if the page title equals "frontend".
× Testing if element <h2> contains text: "section 1". Element could not be located. - expected "section 1" but got: "null"
然后我确认身体innerHTML是“”。
module.exports = {
'toppage': browser => {
browser
.url(browser.launchUrl)
// .assert.containsText('body', 'dummy')
.waitForElementVisible('body', 1000)
.assert.title('frontend')
.assert.containsText('h2', 'section 1')
.end()
},
nightwatch.config.js:
Testing if element <body> contains text: "dummy". - expected "dummy" but got: ""
对于Chrome,我的测试源运行良好。
版本:
守夜人0.9.20
webdriver-manager 12.0.6
硒 - 服务器 - 独立-2.53.1.jar
phantomjs.exe 2.1.1
////////添加于2018年3月29日////////
我尝试了text.to.equal。
新的测试来源:
desiredCapabilities: {
// TODO chrome can cover these tests
// browserName: 'chrome',
// javascriptEnabled: true,
// acceptSslCerts: true,
// TODO but phantomJS can't
browserName: 'phantomjs',
javascriptEnabled: true,
acceptSslCerts: true,
'phantomjs.binary.path': 'node_modules/webdriver-manager/selenium/phantomjs.exe',
'phantomjs.cli.args': ['--ignore-ssl-errors=true'],
},
新错误消息:
toppage: browser => {
browser
.url(browser.launchUrl)
.waitForElementVisible('body', 1000)
.expect.element('h2')
.text.to.equal('section 1')
// .assert.title('frontend') // TypeError: browser.url(...).expect.element(...).text.to.equal(...).assert.title is not a function
// .containsText('h2', 'section 1') // TypeError: browser.url(...).expect.element(...).text.to.equal(...).containsText is not a function
// .end() // TypeError: browser.url(...).waitForElementVisible(...).expect.element(...).text.to.equal(...).end is not a function
},
答案 0 :(得分:0)
当您调用网址为wait
时,网络客户端需要一定的时间来在HTML DOM内呈现 WebElements 。因此,您需要针对属性 .text 以expect-api的形式诱导browser.expect.element('#element_id').text.to.equal('dummy');
,最好是expect-attribute,如下所示:
assert.containsText('body', 'dummy')
接下来,您可以将断言作为<img src='@Url.Content("~/images/image.jpg")'/>