zoukankan      html  css  js  c++  java
  • selenium IDE--录制和回放脚本

    1 selenium IDE--录制脚本 

    准备工作:firefox 浏览器安装了selenium IDE 插件

    实例:打开百度搜索“软件测试”

    1. firefox浏览器打开网址:https://www.baidu.com/
    2. 点击浏览器插件【selenium】图标,弹出selenium IDE 录入界面,Base URL设置为:https://www.baidu.com/(默认为录制状态)
    3. 在步骤1中,直接输入“软件测试”关键字,点击【百度一下】进行搜索
    4. selenium IDE 点击【停止录制】红点,如下图:table中记录了我们刚才的操作

    2 selenium IDE--回放脚本

    1. 回放脚本时需要先开启selenium服务,进入jar包目录,输入cmd命令:java -jar selenium-server-standalone-2.40.0.jar
    2. selenium IDE 点击【回放用例】按钮,如下图1:
    3. 保存为baidu_search.py脚本(附录脚本),如下图2:

     

    # -*- coding: utf-8 -*-

    '''
    时间:2015.04.16
    作者:chenfenping
    功能:百度搜索软件测试实例演示selenium IDE的使用
    '''


    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 baidu_search(unittest.TestCase): def setUp(self): self.driver = webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url = "https://www.baidu.com/" self.verificationErrors = [] self.accept_next_alert = True def test_11(self): driver = self.driver # open | / | driver.get(self.base_url + "/") # click | id=kw | driver.find_element_by_id("kw").click() # type | id=kw | 软件测试 driver.find_element_by_id("kw").clear() driver.find_element_by_id("kw").send_keys(u"软件测试") # click | id=su | 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, e: return False return True def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException, 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()
  • 相关阅读:
    Centos7 Apache 2.4.18编译安装
    Centos7 mysql-community-5.7.11编译安装
    Centos7 安装MPlayer过程详解
    Vmware虚拟机克隆的网卡问题
    虚拟机VMware新增硬盘无法识别问题
    python推导式
    Python迭代器和生成器
    Python装饰器
    Python函数初识二
    Python函数初识
  • 原文地址:https://www.cnblogs.com/nzyjlr/p/4432479.html
Copyright © 2011-2022 走看看