python selenium page object_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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值