Python Appium 实现页面对象模型 [英] Python Appium implementing Page Object Model

查看:22
本文介绍了Python Appium 实现页面对象模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 appium 实现By"和Keys",就像我在 selenium 上的实现方式一样.

I'm trying to implement 'By' and 'Keys' with appium just like how I do it on selenium.

在硒上我可以这样做:

定位器

from selenium.webdriver.common.by import By

class LoginPageLocators(object):
    HEADING = (By.CSS_SELECTOR, 'h3[class="panel-title"]')
    USERNAME = (By.NAME, 'username')
    PASSWORD = (By.NAME, 'password')
    LOGIN_BTN = (By.CSS_SELECTOR, 'input[value="Login"]')

功能

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from base import Page
from locators.locators import *

class LoginPage(Page):

    def __init__(self, context):
        Page.__init__(
            self,
            context)

    def goto_login_page(self, url):
        self.open(url)

    def enter_username(self, username):
        uname = self.find_element(*LoginPageLocators.USERNAME)
        uname.send_keys(username)

    def enter_password(self, password):
        pword = self.find_element(*LoginPageLocators.PASSWORD)
        pword.send_keys(password)

    def click_login(self):
        login = self.find_element(*LoginPageLocators.LOGIN_BTN)
        login.click()

    def verify_dashboard_page(self, page):
        self.verify_page(page)

在 appium 中有没有办法做到这一点?如果我这样做,就没有模块:

Is there a way to this in appium? there is no module if i do this:

 from appium.webdriver.common.by import By
 from appium.webdriver.common.keys import Keys

推荐答案

from appium.webdriver.common.mobileby import By
from appium.webdriver.common.mobileby import MobileBy

class FirstPageLocators(object):
    LOCATOR_ONE = (MobileBy.ACCESSIBILITY_ID, 'id')
    LOCATOR_TWO = (MobileBy.XPATH, 'xpath_value')

这篇关于Python Appium 实现页面对象模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆