写点东西:《自动化测试插件Katalon Recoder》

今天发现了一个可以录自动化测试python selenium库脚本的插件,分享给大家。

用法如下:↓
  1. 下载,安装chrome插件《Katalon Recoder》
    去哪下载?如何安装?请参考>>[这里](Chrome插件会被杀软干掉!)(http://www.cnplugins.com/zhuanti/newinstall.html)<<
  2. 点击录制按钮写点东西:《自动化测试插件Katalon Recoder》_第1张图片
  3. 开始执行自动化测试操作
  4. 操作完毕后点击stop
    写点东西:《自动化测试插件Katalon Recoder》_第2张图片
  5. 点击play,即可执行刚刚录入的操作
  6. 点击“{}Export”即可导出自动化测试代码
    写点东西:《自动化测试插件Katalon Recoder》_第3张图片

关于python selenium代码的简要说明:(见如下代码,只做展示不可执行)

# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
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 Lm(unittest.TestCase):
    def setUp(self):
        #==============================================self.driver = webdriver.Firefox()
        #chromedriver.exe的绝对路径,chromedriver需要与当前chrome浏览器版本一致,可从https://npm.taobao.org/mirrors/chromedriver/下载
        path = "D://chromedriver.exe"
        chrome_options = Options()
        # 无头模式启动
        chrome_options.add_argument('--headless')
        # 谷歌文档提到需要加上这个属性来规避bug
        chrome_options.add_argument('--disable-gpu')
        # 初始化实例
        self.browser = webdriver.Chrome(executable_path=path,chrome_options=chrome_options)
        self.driver = webdriver.Chrome()
        #==============================================
        self.driver.implicitly_wait(30)
        self.base_url = "https://www.katalon.com/"
        self.verificationErrors = []
        self.accept_next_alert = True
    
    def test_lm(self):
        driver = self.driver
        driver.get("http://www.baidu.com")
        #获取页面innerText为x的元素并点击
        driver.find_element_by_link_text("X").click()
     	#根据XPATH获取页面元素并点击driver.find_element_by_xpath("//a[@οnclick='closeFdDiv();']").click()
     	#根据ID获取页面元素并点击
        driver.find_element_by_id("id").click()
        time.sleep(1)
        #切换浏览器tab页签
        driver.switch_to.window(driver.window_handles[1])
    
    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):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

结束

你可能感兴趣的:(测试,写点东西,python,python,自动化测试,selenium,Katalon,Recoder)