/**
 * Locator is a class that supports searching for specific element (E), list
 * (L), and void (V) types by various strategies.
 *
 * Note that this class includes JSONWireProtocol strategies. W3C Webdriver
 * only understands 4 strategies:
 *
 * 1. css selector
 * 2. link text
 * 3. partial link text
 * 4. xpath
 */ abstract class Locator < E , L , V > { abstract find ( strategy , value ) ; abstract findAll ( strategy , value ) ; abstract findDisplayed ( strategy , value ) ; abstract waitForDeleted ( strategy , value ) ; param className findByClassName ( className ) { return this . find ( 'class name' , className ) ; } param selector findByCssSelector ( selector ) { return this . find ( 'css selector' , selector ) ; } param id findById ( id ) { return this . find ( 'id' , id ) ; } param name findByName ( name ) { return this . find ( 'name' , name ) ; } param text findByLinkText ( text ) { return this . find ( 'link text' , text ) ; } param text findByPartialLinkText ( text ) { return this . find ( 'partial link text' , text ) ; } param tagName findByTagName ( tagName ) { return this . find ( 'tag name' , tagName ) ; } param path findByXpath ( path ) { return this . find ( 'xpath' , path ) ; } param className findAllByClassName ( className ) { return this . findAll ( 'class name' , className ) ; } param selector findAllByCssSelector ( selector ) { return this . findAll ( 'css selector' , selector ) ; } param name findAllByName ( name ) { return this . findAll ( 'name' , name ) ; } param text findAllByLinkText ( text ) { return this . findAll ( 'link text' , text ) ; } param text findAllByPartialLinkText ( text ) { return this . findAll ( 'partial link text' , text ) ; } param tagName findAllByTagName ( tagName ) { return this . findAll ( 'tag name' , tagName ) ; } param path findAllByXpath ( path ) { return this . findAll ( 'xpath' , path ) ; } since param className findDisplayedByClassName ( className ) { return this . findDisplayed ( 'class name' , className ) ; } since param selector findDisplayedByCssSelector ( selector ) { return this . findDisplayed ( 'css selector' , selector ) ; } since param id findDisplayedById ( id ) { return this . findDisplayed ( 'id' , id ) ; } since param name findDisplayedByName ( name ) { return this . findDisplayed ( 'name' , name ) ; } since param text findDisplayedByLinkText ( text ) { return this . findDisplayed ( 'link text' , text ) ; } since param text findDisplayedByPartialLinkText ( text ) { return this . findDisplayed ( 'partial link text' , text ) ; } since param tagName findDisplayedByTagName ( tagName ) { return this . findDisplayed ( 'tag name' , tagName ) ; } since param path findDisplayedByXpath ( path ) { return this . findDisplayed ( 'xpath' , path ) ; } param className waitForDeletedByClassName ( className ) { return this . waitForDeleted ( 'class name' , className ) ; } param selector waitForDeletedByCssSelector ( selector ) { return this . waitForDeleted ( 'css selector' , selector ) ; } param id waitForDeletedById ( id ) { return this . waitForDeleted ( 'id' , id ) ; } param name waitForDeletedByName ( name ) { return this . waitForDeleted ( 'name' , name ) ; } param text waitForDeletedByLinkText ( text ) { return this . waitForDeleted ( 'link text' , text ) ; } param text waitForDeletedByPartialLinkText ( text ) { return this . waitForDeleted ( 'partial link text' , text ) ; } param tagName waitForDeletedByTagName ( tagName ) { return this . waitForDeleted ( 'tag name' , tagName ) ; } param path waitForDeletedByXpath ( path ) { return this . waitForDeleted ( 'xpath' , path ) ; } } export default Locator ; export const w3cStrategies = { 'css selector' : true , 'link text' : true , 'partial link text' : true , xpath : true } ; export type W3cStrategy = keyof typeof w3cStrategies ; export interface W3cLocator { using : W3cStrategy ; value : string ; } export const strategies = { ... w3cStrategies , 'class name' : true , id : true , name : true , 'partial link text' : true , 'tag name' : true } ; export type Strategy = keyof typeof strategies ; export function toW3cLocator ( using , value ) { switch ( using ) { case 'id' : using = 'css selector' ; value = `#${ value }` ; break ; case 'class name' : using = 'css selector' ; value = `.${ value }` ; break ; case 'name' : using = 'css selector' ; value = `[name="${ value }"]` ; break ; case 'tag name' : using = 'css selector' ; break ; } return { using , value } ; }