01.Selenium IDE用例录制与常见API讲解
selenium核心组件
(1)Selenium Core:核心,是JavaScript代码组成的资源库,是Selenium IDE和Selenium RC的引擎。
(2)Selenium IDE:是Firefox的插件,有图形化界面,支持录制和回放,是初学者使用的组件。
(3)Selenium RC: Romote Control,支持“三多”,是一个代码库,没有图形化界面。是Selenium 1.0版本的最主要组件。
(4)Selenium WebDriver:支持“三多”,是Selenium 2.0和3.0的最主要组件。
(5)Selenium Grid:用于做分布式测试,可以并行执行多个测试任务,提升测试效率。
Selenium IDE
-selenium
-katalon recorder
1 # -*- coding: utf-8 -*- 2 from selenium import webdriver 3 from selenium.webdriver.common.by import By 4 from selenium.webdriver.common.keys import Keys 5 from selenium.webdriver.support.ui import Select 6 from selenium.common.exceptions import NoSuchElementException 7 from selenium.common.exceptions import NoAlertPresentException 8 import unittest, time, re 9 10 class AppDynamicsJob(unittest.TestCase): 11 def setUp(self): 12 # AppDynamics will automatically override this web driver 13 # as documented in https://docs.appdynamics.com/display/PRO44/Write+Your+First+Script 14 self.driver = webdriver.Firefox() 15 self.driver.implicitly_wait(30) 16 self.base_url = "https://www.google.com/" 17 self.verificationErrors = [] 18 self.accept_next_alert = True 19 20 def test_app_dynamics_job(self): 21 driver = self.driver 22 driver.get("https://testerhome.com/") 23 driver.find_element_by_link_text(u"MTSC2020 深圳站,谁是你心中的最佳!").click() 24 driver.find_element_by_xpath("//div[@id='navbar-header']/a/b").click() 25 driver.find_element_by_link_text(u"MTSC2020 深圳大会集中问答帖").click() 26 27 def is_element_present(self, how, what): 28 try: self.driver.find_element(by=how, value=what) 29 except NoSuchElementException as e: return False 30 return True 31 32 def is_alert_present(self): 33 try: self.driver.switch_to_alert() 34 except NoAlertPresentException as e: return False 35 return True 36 37 def close_alert_and_get_its_text(self): 38 try: 39 alert = self.driver.switch_to_alert() 40 alert_text = alert.text 41 if self.accept_next_alert: 42 alert.accept() 43 else: 44 alert.dismiss() 45 return alert_text 46 finally: self.accept_next_alert = True 47 48 def tearDown(self): 49 # To know more about the difference between verify and assert, 50 # visit https://www.seleniumhq.org/docs/06_test_design_considerations.jsp#validating-results 51 self.assertEqual([], self.verificationErrors) 52 53 if __name__ == "__main__": 54 unittest.main()
元素定位
chrome的定位技巧,在console下可以执行两个特别的函数
'''
$x('xpath表达式')
$x('//*[@data-toggle="dropdown" and @class="btn btn-default"]')
$x('//*[contains(text(),"粉丝")]')
$('css表达式‘)
$('.toc-container .btn btn-default')

'''
js定位
document.getElementByld
document.getElementsByXXX

浙公网安备 33010602011771号