I am working with two classes named:
LayerWrapper
Layer
These classes are utilized as page objects.
I am looking to revamp the following method:
export class LayerPanel {
public static layers = element.all(by.automationId('layer'));
public static findLayerByName(layerName: string): Promise<boolean> {
return this.layers.filter((elem) => {
return elem.getText().then(text => {
return text === layerName;
});
}).first().then(this.OK, this.Failed);
}
private static OK() {
return new Promise<true>();
}
private static Failed {
console.log('not found');
}
}
I aim to refactor it in a way that it returns a Layer page object:
public static findLayerByName(layerName: string): Promise<Layer> {
return this.layers.filter((elem) => {
return elem.getText().then(text => {
return text === layerName;
});
}).first().then(this.OK, this.Failed);
}
private static OK() {
return new Promise<Layer>();
}
It seems like a viable solution, but I wonder if there is a better approach for accomplishing this task?