Last active
March 21, 2018 13:08
-
-
Save RomkeVdMeulen/1451cbb3866d4eaf501115cc2f9e6065 to your computer and use it in GitHub Desktop.
Add a `by.marker` locator to Protractor to match elements marked with an "e2e" attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Locator} from "protractor/built/locators"; | |
declare module "protractor/built/locators" { | |
export interface ProtractorBy { | |
marker(marker: string, parentElement?: Node): Locator; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
by.addLocator("marker", (marker: string, parentElement?: Element) => { | |
const scope = parentElement || document; | |
const matches = scope.querySelectorAll(`[e2e="${marker}"]`); | |
if (matches.length === 0) { | |
return null; | |
} else if (matches.length === 1) { | |
return matches[0]; | |
} | |
return matches; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment