Closed DesmondFinks closed 3 years ago
Currently the codemod only detects direct assignments, e.g.:
class targetPage extends basePage {
constructor() {
super();
this.minimumPaymentDue = element(by.id("rdStatementBalance"))
// ...
In WebdriverIO it is not advised to initiate elements in constructors as it just creates a bunch of useless WebDriver calls. I believe it should be feasible to enhance the codemod to also recognise properties stored in this.PageObjects
. PRs welcome!
Closing due to inactivity. I recommend to define elements through getters, so instead of this:
class targetPage extends basePage {
constructor() {
super();
this.pageObjects = {
minimumPaymentDue: $("#rdStatementBalance"),
nextButton: $("//[@id='smartwizard']/nav/div[2]/button[2]"),
agreeCheckBox: $(".ccheckbox-primary ccheckbox"),
submitButton: $("button[id=ubmit]"),
payMyBillSubmit: $("#btnSubmitPayMyBill")
}}}
it would be better to do this:
class targetPage extends basePage {
get minimumPaymentDue () { return $("#rdStatementBalance") }
get nextButton () { return $("//[@id='smartwizard']/nav/div[2]/button[2]") }
get agreeCheckBox () { return $(".ccheckbox-primary ccheckbox") }
get submitButton () { return $("button[id=ubmit]") }
get payMyBillSubmit () { return $("#btnSubmitPayMyBill") }
}
This way, element calls are initiated once the property is accessed. For more information on the page object pattern in WebdriverIO please have a look into our docs. Let me know if you have any further questions.
When attempting to convert my page objects from Protractor to WDIO v7, the format of the page objects change as follows:
FROM
TO
When this occurs and I attempt to run the test to validate, I get the following response:
Now, I understand if I update my page objects file to be more like this, the test will run correctly without the browser object initialization error:
My basePage helper function is set up as follows for a command to select a page object (usually a field):
So, while I can get it to work, it sort of ruins the point of using the code mod as i'm having to update just about all of the page objects in my project manually, which appears to be the heaviest lift for conversion.
Can you provide solution (if already exists), or validate this needs to be solutioned?