pythonseleniumappiumpython-appium

Python Appium implementing Page Object Model


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

On selenium i could do this:

Locators

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"]')

functions

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)

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

Solution

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