TA的每日心情 | 无聊 4 天前 |
---|
签到天数: 530 天 连续签到: 2 天 [LV.9]测试副司令
|
1测试积点
在做查询封装的时候,运行代码,浏览器启动了三次,页面对象层出现selenium.common.exceptions.WebDriverException: Message: chrome not reachable
base层的代码
- import unittest
- from time import sleep
- from selenium import webdriver
- from pywinauto import Desktop
- from pywinauto.keyboard import send_keys
- from selenium.webdriver import ActionChains
- from selenium.webdriver.common.by import By
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.support import expected_conditions as Ec
- from selenium.webdriver.support.wait import WebDriverWait
- from selenium.webdriver.support.select import Select
- class BasePage:
- definit(self):
- global browser
复制代码 # 声明浏览器对象化
- self.browser = webdriver.Chrome()
复制代码 # 设置等待时间
# 加载网页
- self.browser.get('http://127.0.0.1/index.php/Admin/Admin/login')
复制代码 #定位元素的关键字
- def locator_element(self,loc=(By.NAME, 'username')):
- return self.browser.find_element(*loc)
复制代码 #设置值的关键字
- def send_keys(self,loc,value):
- self.locator_element(loc).send_keys(value)
复制代码 #单击的关键字
- def click_up(self,loc):
- self.locator_element(loc).click()
复制代码 #点击商城
- def click_shop(self,loc):
- self.locator_element(loc).click()
- def exit_to_frame(self):
- self.browser.switch_to.default_content()
- def go_to_frame(self,frame_name):
复制代码 #进入框架
- browser.switch_to.frame(frame_name)
复制代码 #封装下拉框关键字
- def encapsulation_choice(self,loc,value):
- sel = Select(self.locator_element(loc))
- sel.select_by_index(value)
- def look_up(self,loc):
- self.locator_element(loc).click()
复制代码 #获取文本值
页面对象层
- from selenium import webdriver
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.select import Select
- from 练习.base.base_page import BasePage
- from 练习.pageproject.login_page import LoginPage
- class ProductManage_page(BasePage):
复制代码 #页面元素
- product_list_loc = (By.LINK_TEXT,'商城')
- cat_id_loc = (By.NAME, 'cat_id')
- botton_loc = (By.CLASS_NAME, 'btn')
复制代码 #页面动作 登录
- def select_product(self):
- sign_in = LoginPage()
- sign_in.login_ecshop()
复制代码 # 点击商城
- self.click_shop(ProductManage_page.product_list_loc)
复制代码 # 退出框架
# 进入框架
- self.go_to_frame('workspace')
- # 选取下拉框元素
- self.encapsulation_choice(ProductManage_page.cat_id_loc,'7')
- # 点击查询
- self.look_up(ProductManage_page.botton_loc)
- PM=ProductManage_page()
- PM.select_product()
复制代码
|
|