我正在尝试测试Vue应用程序。我有2个简单的页面对象和2个简单的spec文件。当我运行e2e测试时,第一个(登录)通过没有问题,但第二个失败并出现此错误:
错误:没有元素"客户端"的选择器属性而是找到属性:功能,全局,sessionId,选项,launchUrl,launch_url,screenshotsPath,键,会话,会话,超时,timeoutsAsyncScript,timeoutsImplicitWait,elemen 吨,elementIdElement,元件,elementIdElements,elementActive,elementIdAttribute,elementIdClick,elementIdCssProperty,elementIdDisplayed,elementIdLocationInView,elementIdLocation,elementIdName,elementIdClear,elementIdSelected,的Elemen tIdEnabled,elementIdEquals,elementIdSize,elementIdText,elementIdValue,提交,来源,背景,currentContext,setContext,getOrientation,setOrientation,的moveTo,双击,mouseButtonClick,MOUSEBUTTONDOWN,MOUSEBUTTONUP,执行,EXECUT eAsync,execute_async,框架,frameParent,窗口,windowHandle,windowMaximize,WINDOW_HANDLE,windowHandles,window_handles,windowSize,windowPosition,刷新,后退,前进,屏幕截图,网址,地位,职称,钥匙,饼干,acceptAlert,accept_alert, dismissAlert,setAlertText,getAlertText,dismiss_alert,sessionLog,sessionLogTypes,单击,clearValue,的getAttribute,getCssProperty,getElementSize,的getLocation,getLocationInView,getTagName,gettext的,的getValue,ISVISIBLE,moveToElement,setValu 即,submitForm,的SendKeys,switchWindow,resizeWindow,setWindowPosition,maximizeWindow,saveScreenshot,的getTitle,closeWindow,INIT urlHash,的getCookies,的getCookie,setCookie方法,deleteCookie,deleteCookies,injectScript,getLogTypes,getLog,isLogAvai 拉布勒,waitForElementNotPresent,waitForElementNotVisible,waitForElementPresent,waitForElementVisible,结束,暂停执行,useCss,useRecursion,useXpath,页面,期待,断言,验证,currentTest,父母,名字 at new Element(C:\ aquaprojects \ src \ bitbucket.org \ scalock \ tenantmanager \ client \ node_modules \ nightwatch \ lib \ page-object \ element.js:11:11) 在C:\ aquaprojects \ src \ bitbucket.org \ scalock \ tenantmanager \ client \ node_modules \ nightwatch \ lib \ page-object \ page-utils.js:39:35 at Array.forEach(native) 在C:\ aquaprojects \ src \ bitbucket.org \ scalock \ tenantmanager \ client \ node_modules \ nightwatch \ lib \ page-object \ page-utils.js:35:24 at Array.forEach(native) 在module.exports.createElements(C:\ aquaprojects \ src \ bitbucket.org \ scalock \ tenantmanager \ client \ node_modules \ nightwatch \ lib \ page-object \ page-utils.js:34:14) at Object.Page(C:\ aquaprojects \ src \ bitbucket.org \ scalock \ tenantmanager \ client \ node_modules \ nightwatch \ lib \ page-object \ page.js:19:6) 在Object.parent。(匿名函数)[作为租户](C:\ aquaprojects \ src \ bitbucket.org \ scalock \ tenantmanager \ client \ node_modules \ nightwatch \ lib \ core \ api.js:469:16) 在Object.before(C:/aquaprojects/src/bitbucket.org/scalock/tenantmanager/client/test/e2e/specs/tenants.spec.js:7:26) 在对象。 (C:\ aquaprojects \ SRC \ bitbucket.org \ scalock \ tenantmanager \客户\ node_modules \ nightwatch \ lib中\ UTIL \ utils.js:35:8)
login.js:
module.exports = {
url: 'http://localhost:8080/#/login',
elements: {
app: '#app',
loginSection: '.login-page',
title: 'h3',
submitButton: '.btn-primary',
username: '#username',
password: '#password'
}
}
login.spec.js:
let login = null
module.exports = {
before: function (client) {
console.log('*********** Init login page *******************')
login = client.page.login()
},
'open login page': function () {
login
.navigate()
.waitForElementVisible('@app', 5000)
.assert.elementPresent('@loginSection')
.assert.containsText('@title', 'Tenant Manager Login')
},
'try to login': function () {
login.setValue('@username', 'administrator')
login.setValue('@password', '1234')
login.click('@submitButton')
login.waitForElementNotPresent('@submitButton')
},
after: function (client) {
client.end()
}
}
这个通过,另一个,基本上是复制/粘贴,有一些更改,在这一行失败:
tenant = client.page.tenant()
tenant.js:
module.exports = {
url: 'http://localhost:8080/#/tenants',
elements: {
tab: '#tenants',
tenantsFilter: '.tenants-filter input',
statusFilter: '.status-filter input',
add: '.add-tenant'
}
}
tenants.spec.js:
let tenant = null
module.exports = {
before: function (client) {
console.log('*********** Init tenant page *******************')
tenant = client.page.tenant()
},
'open tenant page': function () {
console.log('*********** Navigating to tenant page *******************')
tenant
.navigate()
.waitForElementVisible('@tab', 5000)
.assert.elementPresent('@tenantsFilter')
// .assert.containsText('@title', 'Tenant Manager Login')
},
after: function (client) {
client.end()
}
}
nightwatch.conf.js:
require('babel-register')
var config = require('../../config')
// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
src_folders: ['test/e2e/specs'],
output_folder: 'test/e2e/reports',
custom_assertions_path: ['test/e2e/custom-assertions'],
"page_objects_path" : "test/e2e/pages",
selenium: {
start_process: true,
server_path: require('selenium-server').path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},
test_settings: {
default: {
selenium_port: 4444,
selenium_host: 'localhost',
silent: true,
globals: {
devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox',
javascriptEnabled: true,
acceptSslCerts: true
}
}
}
}
答案 0 :(得分:0)
您尚未定义页面对象路径
require('babel-register')
var config = require('../../config')
// http://nightwatchjs.org/gettingstarted#settings-file
module.exports = {
src_folders: ['test/e2e/specs'],
output_folder: 'test/e2e/reports',
custom_assertions_path: ['test/e2e/custom-assertions'],
"page_objects_path" : "test/e2e/pages", //page-object path
selenium: {
start_process: true,
server_path: require('selenium-server').path,
host: '127.0.0.1',
port: 4444,
cli_args: {
'webdriver.chrome.driver': require('chromedriver').path
}
},
test_settings: {
default: {
selenium_port: 4444,
selenium_host: 'localhost',
silent: true,
globals: {
devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
}
},
chrome: {
desiredCapabilities: {
browserName: 'chrome',
javascriptEnabled: true,
acceptSslCerts: true
}
},
firefox: {
desiredCapabilities: {
browserName: 'firefox',
javascriptEnabled: true,
acceptSslCerts: true
}
}
}
}
创建一个目录" pages"并将租户纳入其中。