【WebDriver.io】使用xpath通配符的定位方式

 

 

1.面对经常变动代码的dom结点,可以变换元素的定位方式从前面的方式变成下面的通配符定位方式

await expect($(`h4=${appTitle}`)).toExist()

 

某个class下的文本定位
await expect(browser.$(`//*[contains(@class,"EmbersTemplate-table")]//*[text()="${appTitle}"]`)).toExist()

 

2.对于大小写的通配定位

 

 

 

import { keyboard } from "../../../utils/deviceInput"
const path = require('path');
/**
 * main page object that provide all the commonly used methods.
 */
const fs = require('fs')
const assert = require('assert')
export default class CommonPage {
    get betaVersionSwitch() { return $('.MuiSwitch-input')}
    get profileDropdown() { return $('.EmbersHeader-avatar-root') }
    get orgDropdown() { return $('.EmbersHeader-OrgDropdown-root') }
    get LoginHeader() { return browser.$('.EmbersHeader-avatar-root') }
    get searchInput() { return browser.$('//input[contains(@placeholder,"Search")]') }
    get searchIcon() { return $('.ant-input-search-icon') }
    get cancelButton() { return $('button=CANCEL') }
    get saveButton()  { return $('button=Save') }
    // get cancelButton() { return $('button=CANCEL') }
    // get CancelButton() { return browser.$('button=Cancel') }
    get CancelButton() { return browser.$("//*[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'cancel')]") }
    // get saveButton()  { return $('button=Save') }
    get saveButton() { return browser.$("//*[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'save')]") }
    get modalSaveButton()  { return $$('button=Save')[1] }
    get deleteButton()  { return $('button=Delete') }
    get removeButton() { return $('button=Remove')}
    get loadingContent() { return $('.icon-loading') }
    get loadingCircle() { return $('.ls-circular__large') }
    get successMessage(){ return  $('.EmbersMessage-success')}
    get errorMessage() { return $('.portal-error-modal-content') }
    get appsIcon() { return $('.EmbersHeader-app') }
    get signOutButton() { return browser.$('//*[text()="Sign out"]') }
    get closeIcon() { return $('.icon-close') }
    get backIcon() { return $('.icon-arrow-left') }
    get actionsButton() { return $('button=Actions') }
    get orgDropDownIcon(){ return  $('.EmbersHeader-OrgDropdown-OrgName-content') }
    get orgNameList() { return $('.EmbersPopper-root') }
    SwitchOrgTo(orgName){ return $(`p=${orgName}`)}
    get devicesSpan() { return $$('.EmbersNav-label-text')[1] }
    get CookieGotItButton() { return $('.cookie-got-it') }
    get closeButton() { return $('.MuiDialog-paper').$('.MuiIconButton-root') }
    get allowCookies() { return $('#CybotCookiebotDialogBodyButtonAccept') }
    get clearAllButton(){ return $('.MuiButton-endIcon')}
    get cancleButton(){ return $('a=Cancle')}
    // get cancleButton(){ return $('a=Cancle')}
    get titleSpan(){ return $$('.EmbersNav-label-text')}
    get adminToolsTitle(){ return $('h1=Admin Tools')}
    get showOtherOptions(){ return $$('.EmbersLink')[0]}
    get prometheanSupportLink(){ return $$('.EmbersLink')[1]}
    get installChromeExtension(){ return $$('.EmbersLink')[0]}
    get downloadForMac(){ return $$('.EmbersLink')[1]}
    get policiesLinkButton(){ return $('#footer-policy')}
    get deviceMessageIconButton(){ return $('.EmbersTitle-tooltip-iconContainer')}
    get refreshButton(){ return $('.EmbersRefreshButton-root')}
    get backButton(){return $('.EmbersTitle-back')}
        await this.appsIcon.click()
    }

    async checkNowOrgNameIsCorrect(expectedOrgName){
        const actualOrgName = await this.nowOrgName.getText()
        assert.equal(actualOrgName,expectedOrgName)
    }

    async switchApp(app){
        await this.acceptCookie()
        await this.appsIcon.waitForClickable()
        await this.appsIcon.waitForClickable({timeout:60000})
        await this.appsIcon.click()
        console.log('open app icon',app)
        await browser.pause(5000)
        await $(`span=${app}`).waitForClickable({timeout:60000})
        await $(`span=${app}`).click()
        await $(`span=${app}`).waitForExist({timeout:60000})
        await browser.pause(1000)
        await browser.execute((el)=>
                el.click(),
            await browser.$(`span=${app}`)
        )
        await browser.pause(1000)
        console.log('open the app',app)
        await browser.pause(20000)
    }

    async clickRefreshButton(){
        this.refreshButton.waitForExist()
        this.refreshButton.click()
    }

    async clickDeviceMessageIcon(){
    
    async changeToFilterOption(){
        await this.betaVersionSwitch.click()
        await browser.pause(5000)
    }

    async clearAllFilters(){
        await this.clearAllButton.click()
    }

    async clickCancle(){
        await this.cancleButton.click()
    }
    // async clickCancle(){
    //     await this.cancleButton.click()
    // }
    
    async clickBack(){
        await this.backButton.click()
    }

    async checkThePositionOfSpan(spanName,position){
        await this.adminToolsTitle.waitForExist({timeout: 5000})
        const spanActualName = await this.titleSpan[position].getText()
        console.log('spanActualName',spanActualName)
        assert.equal(spanActualName,spanName)

 

posted @ 2023-12-12 15:33  陈晓猛  阅读(103)  评论(0编辑  收藏  举报