1. 程式人生 > 其它 >Katalon Recorder錄製自動化測試指令碼

Katalon Recorder錄製自動化測試指令碼

1.在Chrome瀏覽器上安裝Katalon Recorder外掛

2.操作

3.點選匯出後

4.PyCharm開啟,執行加修改程式碼

5.程式碼示例:

 1 # -*- coding: utf-8 -*-
 2 from selenium import webdriver
 3 from selenium.webdriver.chrome.service import Service
 4 from selenium.webdriver.common.by import By
 5 from selenium.webdriver.common.keys import Keys
6 from selenium.webdriver.support.ui import Select 7 from selenium.common.exceptions import NoSuchElementException 8 from selenium.common.exceptions import NoAlertPresentException 9 import unittest, time, re 10 11 class TestCase1(unittest.TestCase): 12 def setUp(self): 13 s = Service("
chromedriver.exe") 14 self.driver = webdriver.Chrome(service=s) 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_case1(self): 21 driver = self.driver
22 driver.get("https://www.baidu.com/") 23 time.sleep(2) 24 driver.find_element(By.XPATH,"//form[@id='form']/span/input").click() 25 driver.find_element(By.ID,"kw").clear() 26 time.sleep(2) 27 driver.find_element(By.ID,"kw").send_keys(u"你好李煥英") 28 time.sleep(2) 29 driver.find_element(By.XPATH,"//form[@id='form']/span[2]/input").click() 30 time.sleep(2) 31 32 def is_element_present(self, how, what): 33 try: self.driver.find_element(by=how, value=what) 34 except NoSuchElementException as e: return False 35 return True 36 37 def is_alert_present(self): 38 try: self.driver.switch_to_alert() 39 except NoAlertPresentException as e: return False 40 return True 41 42 def close_alert_and_get_its_text(self): 43 try: 44 alert = self.driver.switch_to_alert() 45 alert_text = alert.text 46 if self.accept_next_alert: 47 alert.accept() 48 else: 49 alert.dismiss() 50 return alert_text 51 finally: self.accept_next_alert = True 52 53 def tearDown(self): 54 self.driver.quit() 55 self.assertEqual([], self.verificationErrors) 56 57 if __name__ == "__main__": 58 unittest.main()