Reputation: 5
For testing,
I have a directory structure like this :
custom
lib
tests
pages
Every JavaScript function written in the 'custom' directory can be accessed by the 'test' directory by a "browser" object.
This is done by the "testutils.js" file in the lib directory.
Likewise,
Is it possible to retrieve the JavaScript functions in the 'pages' directory can be accessed by the 'test' directory by the path "browser.pages.function-name()"?
Upvotes: 0
Views: 135
Reputation: 669
It looks like you're trying to implement the PageObject pattern with WebdriverIO. You can find an example of this in the WebdriverIO examples.
Though, I will say that I have tried that route and I prefer a different approach. With WebdriverIO you can add custom commands to your webdriver client. So you can list your commands in an object :
module.exports = {
searchGoogle: function (searchString) {
return this
.url('http://www.google.com')
.click('input[name="q"]')
.keys(searchString)
.pause(2000)
.keys(['Enter']); //press Enter Key
}
};
And then you can bind those commands to the client:
var client = webdriverio.remote(options);
client.addCommand('searchGoogle',searchGoogle.bind(client));
Upvotes: 1