zoukankan      html  css  js  c++  java
  • selenium-python PageObject设计模式

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from time import sleep
    from pip._vendor.distlib.locators import Page
    from selenium.webdriver.support.ui import Select#导入下拉框函数
    import unittest

    class Page(object):
        login_url = 'http://qf-uatqapp-w2/ProductApplication/Application'
        def __init__(self, selenium_driver, base_url=login_url):
            self.base_url = base_url
            self.driver = selenium_driver
            self.timeout = 30
            self.driver.maximize_window()
        def on_page(self):
            return self.driver.current_url == (self.base_url + self.url)
        def _open(self, url):
            url=self.base_url
            self.driver.get(url)
            self.driver.maximize_window()
            #assert self.on_page(), 'Did not land on %s' %url
        def open(self):
            self._open(self.url)
        def find_element(self, *loc):
            return self.driver.find_element(*loc)
        
        def switch_frame(self, loc):
            return self.driver.switch_to_frame()
        
        
    class LoginPage(Page):
        url = '/'
        username_loc = (By.ID, "Account")
        password_loc = (By.ID, "Pwd")
        submit_loc = (By.ID,"Log_Submit")
        
        def type_username(self, username):
            self.find_element(*self.username_loc).send_keys(username)
        def type_password(self,password):
            self.find_element(*self.password_loc).send_keys(password)
        def submit(self):
            self.find_element(*self.submit_loc).click()
            
    class ProductPage(Page):
        customername_loc = (By.ID, "customerName")
        customerID_loc = (By.ID,"customerIDCard")  
        applyCity_loc = (By.ID,"applyCity")
       
       # productCode_loc = (By.ID,"//option[@value='productCodesyd-6-24']")
       # productCode_value = (By.XPATH,"//option[@value='BYQSF0000']")
       # platform_loc = (By.ID,"platform")
       #platform_value = (By.XPATH,"//option[@value='BYQSF0000']")
        
        def type_customername(self, customername):
            self.find_element(*self.customername_loc).send_keys(customername)
        def type_customerID(self, customerId):
            self.find_element(*self.customerID_loc).send_keys(customerId)    
        def type_applyCity(self, applyCityvalue):
            Select(self.find_element(*self.applyCity_loc)).select_by_value(applyCityvalue)#下拉框函数
            
            
    def test_user_login(driver, username, password):
        page = LoginPage(driver)
        page.open()
        page.type_username(username)
        page.type_password(password)
        page.submit()
       
        
    def test_apply_product(driver,customername, customerID, applyCityvalue):
        page1 = ProductPage(driver)
        page1.type_customername(customername)
        page1.type_customerID(customerID)
        page1.type_applyCity(applyCityvalue)  
        
        
        
        
    def main():
        
        driver = webdriver.Chrome()
        username = 'jiahua'
        password = 'Quarkhj05'
        customername = u'huajia'
        customerId = '310104198408020057'
        applyCityvalue = '025,025'
        test_user_login(driver,username,password)
        driver.implicitly_wait(30)
        test_apply_product(driver,customername, customerId, applyCityvalue)

     
            
          
            
    if __name__ == '__main__':
        main()
        unittest.main()
     
            
        

  • 相关阅读:
    iot 表索引dump《2》
    heap表和iot表排序规则不同
    Cannot complete the install because one or more required items could not be found.
    iot表输出按主键列排序,heap表不是
    iot 表主键存放所有数据,且按数据插入顺序排序
    iot表和heap表排序规则不同
    org.eclipse.graphiti.ui.editor.DiagramEditorInput.
    Oracle 排序规则
    perl 异步超时 打印错误
    14.6.3 Grouping DML Operations with Transactions 组DML操作
  • 原文地址:https://www.cnblogs.com/jerryhua/p/5794868.html
Copyright © 2011-2022 走看看