2017-06-29 34 views
1

我试图用appium实现'By'和'Keys',就像我在硒上执行操作一样。Python Appium实现页面对象模型

硒我能做到这一点:

定位器

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?没有模块,如果我这样做:

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

回答

1
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')