UI自动化测试—PO设计模式

Posted snailrunning

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UI自动化测试—PO设计模式相关的知识,希望对你有一定的参考价值。

写博起因:想把自己所学所做的,分享出去。

目录结构

--pages
    --base_page.py

base_page.py

#coding:utf8
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By

class BasePage(object):
    def __init__(self,driver,path=None):
        self.driver = driver
        # self.driver = webdriver.Chrome()
        self.url = ‘https://www.tapd.cn/‘
        self.time_out = 10
        self.poll_frequency = 0.3
        self.open_web_page(path)
        self.driver.maximize_window()

    def open_web_page(self,path):
        if path != None:
            url = self.url + path
        else:
            url = None
        if url != None:
            self.driver.get(url)
        else:
            pass

    def wait(self,*locator):
        WebDriverWait(self.driver,self.time_out,self.poll_frequency).until(EC.visibility_of_element_located(locator))

    def wait_text(self,text=None,*locator):
        WebDriverWait(self.driver,self.time_out,self.poll_frequency).until(EC.text_to_be_present_in_element((locator),text))

    def wait_all(self,text=None,*locator):
        if text == None:
            self.wait(*locator)
        else:
            self.wait_text(text,*locator)

    def by_css(self,css,text=None):
        locator = (By.CSS_SELECTOR,css)
        self.wait_all(text,*locator)
        return self.driver.find_element(*locator)




if __name__ == ‘__main__‘:
    driver = webdriver.Chrome()
    test_base_page = BasePage(driver,‘cloud_logins/login‘)
    test_base_page.by_css(‘#username‘).send_keys(‘XXXXXX‘)
    test_base_page.by_css(‘#password_input‘).send_keys(‘XXXXXX‘)
    test_base_page.by_css(‘#tcloud_login_button‘).click()

以上是关于UI自动化测试—PO设计模式的主要内容,如果未能解决你的问题,请参考以下文章

Page Object 设计模式 与 实战

UI自动化测试—PO设计模式

Appium PO模式UI自动化测试框架——设计与实践

基于Puppeteer前端自动化框架PO模式,断言(如何更简便逻辑的写测试代码)

Selenium WebUI自动化测试--PO中传递driver

web自动化PO模式初探