Paget Object设计模式,不多说,但在接触了poium测试库后,个人感觉BasePage都是多余的。。但在次还是做个记录

 1 class Page():
 2
 3     def __init__(self, driver):
 4         self.driver = driver
 5
 6     def open(self, url=None):
 7         if url is None:
 8             self.driver.get(self.url)
 9         else:
10             self.driver.get(url)
11
12     '''对定位方法的封装,利用时直接调用函数'''
13     def by_id(self, id_):
14         return self.driver.find_element_by_id(id_)
15
16     def by_name(self, name):
17         return self.driver.find_element_by_name(name)
18
19     def by_class(self, class_name):
20         return self.driver.find_element_by_class_name(class_name)
21
22     def by_xpath(self, xpath):
23         return self.driver.find_element_by_xpath(xpath)
24
25     def by_css(self, css):
26         return self.driver.find_element_by_css_selector(css)
27
28     '''封装js'''
29     def js(self, script):
30         self.driver.execute_script(script)
BasePage
01-31 19:42