一,开篇
自动化测试对测试人员来说,是一个觉得有技术含量的活,可当写不到20个场景,超不过1000行的代码时就觉得枯燥乏味没有什么技术含量了,每天都是F12,右键复制full xpath定位来定位去,最多写点基本的逻辑判断预约,剩下80%的工作在不停的定位元素。
有没有好的定位工具呢,
对于:Selenium类型的工具有 :
Selenium IDE 录制工具 要对应firefox浏览器。
katalon recorder for chrome插件,比较好用。
下载地址:
https://download.csdn.net/download/lovingsoft/19651948
二,安装及使用
1.在chrome浏览器中,打开扩展工具,把已经解压的插件,拖进去即可。
2.在插件浏览器控制点击:
3.选择你要录制的网页,点击 Record就可以录制脚本,同时可以点击Play支持回放,是不是很简单,一个自动化脚本就这样做成了。
4.导出脚本:点击export,可以导出各种类型的脚本。
5.生成对应的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(u"测试数据")
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()