2017-10-31 4 views
0

Kann ich keine Seitenobjekte finden, was fehlt mir hier?Nightwatch Page Object

Nightwatch 0.9.16

In nightwatch.json

"page_objects_path": "pages", 

Im aktuellen Ordner

\pages\MyLegacyPage.js 

In MyLegacyPage.js

module.exports = { 
    myPauseMethod: function (browser) { 
    browser.pause(1000); 
    return this; 
    } 
}; 

Im Test

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); 
    }); 
}); 

Ausgabe

browser.page.MyLegacyPage() = {} 
TypeError: myPageObject.myPauseMethod is not a function 

Antwort

1

dieses Beispiel von POM Vielleicht haben Sie Ihr Problem lösen helfen könnten:

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'} 
     }, 
} 

, die bedeutet, dass Sie Ihre Funktion innerhalb des var machen müssen und dann müssen Sie diese Befehle mit der folgenden Codezeile in module.exports part einfügen: commands: [nameOfYourVar]

+0

Danke, ich habe das erweiterte Objekt geändert und es hat funktioniert. Bei der Ausgabe eines Seitenobjekts ist es normal, dass entweder '{}' angezeigt wird oder ein Fehler von 'es ist eine kreisförmige Struktur' angezeigt wird. –

Verwandte Themen