Currently, I am developing automated end-to-end tests using Protractor with Selenium. I have a class where I intend to store a property to improve the organization of my tests.
Below is the specific class:
export class Tab {
constructor(job) {
this._criterionList = [];
this._job = job;
this._JOBBASEPATH = element(by.css_sr('iris-app::sr #jobs'))
.all(by.css_sr('::sr iris-job')).get(this.getIndex());
this._ACTIONMENUBASEPATH = this._JOBBASEPATH
.element(by.css_sr('::sr #header'))
.element(by.css_sr('::sr iris-floating-menu'));
this._JOBFOOTERBASEPATH = this._JOBBASEPATH
.element(by.css_sr('::sr job-footer'));
this._RESULTBASEPATH = this._JOBBASEPATH
.element(by.css_sr('::sr #result'));
}
}
However, an issue arises when invoking one of the methods within this same class:
//Method in Tab class, _JOBBASEPATH is undefined
getQueryConditionButton(){
return this._JOBBASEPATH.element(by.css_sr('::sr #header')).element(by.css_sr('::sr #condition'));
}
// _JOBBASEPATH is undefined
tab.getQueryConditionButton().click();
Upon debugging, I receive the error message "No element found using locator: by.css_sr("::sr #header")", I attempted initiating this._JOBBASEPATH.click() and discovered that _JOBBASEPATH is undefined.
I came up with workarounds like implementing getters/setters or duplicated methods to achieve the same functionality but I am determined to comprehend the reason behind this issue, especially considering that it works flawlessly in other classes such as the following:
export class DetailField {
constructor(tab) {
this._tab = tab;
this._displayFieldList = [];
this._basePath = element(by.css_sr('iris-app::sr #jobs'))
.all(by.css_sr('::sr iris-job')).get(this._tab.getIndex())
.element(by.css_sr('::sr #customizer'))
.element(by.css_sr('::sr #detailField'));
}
}
//Method in DetailField class functioning perfectly
getLoadButton(){
return this._basePath.element(by.css_sr('::sr #loadButton'));
}
//works
getLoadButton().click();
Important Note: the call getIndex() returns the same value for both classes: 0 Thank you in advance!