IDP自动化项目

 

 

 

 

 

-pageObject

--mobileLoginPage

import { adbInput } from "../../../utils/adbHelper"
import { UiSelector } from "../../../utils/andriodSelector"
import { ocr } from "../../../utils/ocrService/ocr"
import ProfilePage from "./profilePage"

class MobileLoginPage {
    get SignInButton() { return android.$(UiSelector('text','Sign in')()) }
    //get SignInWithEmailButton() { return android.$(UiSelector('text','Sign in with email')()) }
    //get SignInWithEmailButton() {return android.$(new UiSelector().className("android.widget.RelativeLayout").index(2)())}
    get SignInWithEmailButton() { return android.$(UiSelector('className','android.widget.RelativeLayout')('index','2')())}
    get EmailInput() { return android.$(UiSelector('resourceId','email')()) }
    get PasswordInput() { return android.$(UiSelector('resourceId','password')()) }
    get SignInWithGoogleButton() { return android.$(UiSelector('text','Sign in with Google')()) }
    get SignInWithMicrosoftButton() { return android.$(UiSelector('text','Sign in with Microsoft')()) }
    get YesButton() { return android.$(UiSelector('text','Yes')()) }

    async signInWithEmail(email,password) {
        await this.SignInButton.waitForExist({timeout: 10000})
        await this.SignInButton.click()
        await browser.pause(10000)
        await this.SignInWithEmailButton.waitForDisplayed()
        await this.SignInWithEmailButton.click()
        await this.EmailInput.setValue(email)
        await this.PasswordInput.setValue(password)
        await this.SignInButton.click()
        await ProfilePage.ProfileButton.waitForExist({timeout: 20000})
    }

    async googleSignInFlow(email, password){
        await ocr.waitUntilTextInScreen('android','prometheanproduct.com',{top:400,height:200})
        adbInput.text(androidID, email)
        adbInput.keyevent(androidID, 'KEYCODE_ENTER')
        await ocr.waitUntilTextInScreen('android',email,{top:400,height:200})
        adbInput.text(androidID, password)
        adbInput.keyevent(androidID, 'KEYCODE_ENTER')
        await ProfilePage.ProfileButton.waitForExist({timeout: 20000})
    }

    async signInWithGoogle(email,password) {
        await this.SignInButton.waitForExist({timeout: 10000})
        await this.SignInButton.click()
        await this.SignInWithGoogleButton.waitForDisplayed()
        await browser.pause(3000)
        await this.SignInWithGoogleButton.click()
        await this.googleSignInFlow(email,password)
    }

    async googleSSOSignIn(email,password){
        await this.SignInButton.waitForExist({timeout: 10000})
        await this.SignInButton.click()
        await this.SignInWithGoogleButton.waitForDisplayed()
        await browser.pause(3000)
        await this.SignInWithGoogleButton.click()
        try {
            await ocr.waitUntilTextInScreen('android','ActivPanel',{height:700})
        } catch (error) {
            await this.googleSignInFlow(email,password)
        }
        
    }

    async microsoftSignInFlow(email,password){
        await ocr.waitUntilTextInScreen('android','Microsoft',{area:['top']})
        adbInput.text(androidID, email)
        adbInput.keyevent(androidID, 'KEYCODE_ENTER')
        await ocr.waitUntilTextInScreen('android',email,{top:300,height:200})
        adbInput.text(androidID, password)
        adbInput.keyevent(androidID, 'KEYCODE_ENTER')
        await this.YesButton.waitForExist()
        await this.YesButton.click()
        await ProfilePage.ProfileButton.waitForExist({timeout: 20000})
    }

    async signInWithMicrosoft(email,password) {
        await this.SignInButton.waitForExist({timeout: 10000})
        await this.SignInButton.click()
        await this.SignInWithMicrosoftButton.waitForDisplayed()
        await browser.pause(3000)
        await this.SignInWithMicrosoftButton.click()
        await this.microsoftSignInFlow(email,password)
    }

    async checkSignedIn(){
        if (await this.SignInButton.isExisting()){
            return false
        }else{
            return true
        }
    }

}

export default new MobileLoginPage()

 

posted @ 2022-08-09 17:54  陈晓猛  阅读(49)  评论(0编辑  收藏  举报