- [笔记]Selenium Testing Tools Cookb
- [笔记]Selenium Testing Tools Cookb
- [笔记]Selenium Testing Tools Cookb
- [笔记]Selenium Testing Tools Cookb
- [笔记]Selenium Testing Tools Cookb
- [笔记]Selenium Testing Tools Cookb
- [笔记]Selenium Testing Tools Cookb
- [笔记]Selenium Testing Tools Cookb
- [笔记]Selenium Testing Tools Cookb
- [笔记]Selenium Testing Tools Cookb
Chapter8 Using the Page Object Model
Implementing the Page Object model in Python
We will design 2 classes, which are Page
class and Test
class
Page
class
from selenium.webdriver.chrome.options import Options
class JianShuPage(object):
def __init__(self,driver):
chrome_options = Options()
chrome_options.add_argument('--no-sandbox') #让chrome在root权限下跑
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_experimental_option('useAutomationExtension',False)
self.driver = driver
self.url = 'https://www.jianshu.com'
@property
def is_loaded(self):
return self.driver.title == self.title
def open(self):
self.driver.get(self.url)
def search(self):
search_area = self.driver.find_element_by_id("q")
search_area.clear()
search_area.send_keys("abc")
button = self.driver.find_element_by_class_name("search-btn")
button.click()
def close(self):
self.driver.quit()
Test
class
import unittest
from selenium import webdriver
from JianShu_Page import JianShuPage
class JianShuTest(unittest.TestCase):
def testSearch(self):
driver = webdriver.Chrome(executable_path='D:/elf_private/test/chromedriver')
test_search = JianShuPage(driver)
test_search.open()
test_search.search()
test_search.close()
if __name__ == '__main__':
unittest.main()
网友评论