Katalon Recorder插件(替代selenium IDE)使用教程实例
前言
katalon recorder是基于selenium IDE的插件,支持Chrome与Firefox浏览器。能替代selenium IDE完成Web页面录制工作,功能基本与Selenium IDE一样,脚本录制结束后,可支持多种格式导出脚本,麻雀虽小五脏俱全。
一、为何改用Katalon Recorder插件?
- 由于Firefox浏览器不断升级,Selenium IDE无法支持火狐55.0以上版本
二、插件安装步骤
1、下载安装Firefox(55.0版本以上)浏览器,目前我安装的是最新版本82.0
2、点击Firefox浏览器右上角的附件组件->插件->搜索栏输入“Katalon Recorder”
3、插件添加成功后,浏览器右上角就会出现Katalon Recorder图标
三、插件使用步骤
1、点击浏览器右上角的Katalon Recorder图标,在弹窗中点击【New】,新建一个Test Case
2、点击【Record】,录制脚本,以百度为实例 演示如下:
进入百度首页->搜索栏中输入“selenium”,点击【百度一下】按钮
3、点击【export】,导出Python格式的脚本
脚本如下:
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
class AppDynamicsJob(unittest.TestCase):
def setUp(self):
# AppDynamics will automatically override this web driver
# as documented in https://docs.appdynamics.com/display/PRO44/Write+Your+First+Script
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://www.google.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_app_dynamics_job(self):
driver = self.driver
driver.get("https://www.baidu.com/")
driver.find_element_by_id("kw").click()
driver.find_element_by_id("kw").clear()
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException as e: return False
return True
def is_alert_present(self):
try: self.driver.switch_to_alert()
except NoAlertPresentException as e: return False
return True
def close_alert_and_get_its_text(self):
try:
alert = self.driver.switch_to_alert()
alert_text = alert.text
if self.accept_next_alert:
alert.accept()
else:
alert.dismiss()
return alert_text
finally: self.accept_next_alert = True
def tearDown(self):
# To know more about the difference between verify and assert,
# visit https://www.seleniumhq.org/docs/06_test_design_considerations.jsp#validating-results
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
到此就结束了