无法找到页面对象,我在这里缺少什么?
守夜人0.9.16
在nightwatch.json中
"page_objects_path": "pages",
在实际文件夹中
\pages\MyLegacyPage.js
在MyLegacyPage.js
中module.exports = {
myPauseMethod: function (browser) {
browser.pause(1000);
return this;
}
};
在测试中
describe('CTA', function () {
it('page objects tests', function (browser) {
console.log('browser.page.MyLegacyPage() = ' + JSON.stringify(browser.page.MyLegacyPage()));
var myPageObject = browser.page.MyLegacyPage();
myPageObject.myPauseMethod(browser);
});
});
输出
browser.page.MyLegacyPage() = {}
TypeError: myPageObject.myPauseMethod is not a function
答案 0 :(得分:1)
也许这个POM示例可能会帮助您解决问题:
var dashCommands = {
uploadAvatar:function(){
return this.waitForElementVisible('@profileIcon', TIMEOUT)
.click('@profileIcon')
.waitForElementVisible('@avatarUpload', TIMEOUT)
.moveToElement('@avatarUpload', 0,0)
.click('@avatarUpload')
.waitForElementVisible('@profileImageUploadOverlay', TIMEOUT)
.assert.visible('@closeButton')
.click('@selectPicture')
}
module.exports = {
commands:[dashCommands],
elements: {
dashLogo : { selector: 'div.topbar__title-wrap.topbar-title > h1'},
profileAvatar: { selector: 'span:nth-child(4) > div > img'},
searchField: { selector: 'div.topbar__search-feald-wrap > input'},
topicsColumn: { selector: 'div.inner-dashboard-wrap.topic-wrap'},
conclusionsColumn: { selector: 'div.inner-dashboard-wrap.conclusion-wrap'},
messagesColumn: { selector: 'div.inner-dashboard-wrap.messages-wrap'},
bookmarksColumn: { selector: 'div.inner-dashboard-wrap.request-wrap'},
profileIcon: { selector: 'span:nth-child(4) > div'},
avatarUpload: {selector: '//*[@id="profile-section"]/div[1]/div[1]/img', locateStrategy: 'xpath' },
selectPicture: { selector: '#dialogContent_profile-image-modal'},
profileImageUploadOverlay: { selector: '.layout-column button'},
closeButton: { selector: '.ng-scope.icon-close'}
},
}
这意味着你必须在var中创建你的函数然后你必须在module.exports part:commands:[nameOfYourVar]
中插入以下代码行的命令