SeleniumIDE 自动化用例录制、测试用例结构分析

news2024/9/29 23:37:30

1、SeleniumIDE用例录制

SeleniumIDE用例录制使用场景

  • 刚开始入门UI自动化测试
  • 团队代码基础较差
  • 技术成长之后学习价值不高

SeleniumIDE的下载以及安装

  • 官网:https://www.selenium.dev/
  • Chrome插件:https://chrome.google.com/webstore/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd
  • Firefox插件:Selenium IDE – Get this Extension for Firefox (en-US)
  • github release:Releases · SeleniumHQ/selenium-ide · GitHub
  • 其它版本:Selenium IDE version history - 1 version – Add-ons for Firefox (en-GB) 注意:Chrome插件在国内无法下载,Firefox可以直接下载。

启动

  • 安装完成后,通过在浏览器的菜单栏中点击它的图标来启动它:
  • 如果没看到图标,首先确保是否安装了Selenium IDE扩展插件
  • 通过以下链接访问所有插件
    • Chrome: chrome://extensions
    • Firefox: about:addons

SeleniumIDE常用功能

  1. 新建、保存、打开
  2. 开始和停止录制
  3. 运行8中的所有的实例
  4. 运行单个实例
  5. 调试模式
  6. 调整案例的运行速度
  7. 要录制的网址
  8. 实例列表
  9. 动作、目标、值
  10. 对单条命令的解释
  11. 运行日志

其他常用功能

  • 用例管理
  • 保存和回放

SeleniumIDE脚本导出

  • Java
  • Python

2、自动化测试用例结构分析

目录

  • 用例结构
  • 录制用例分析
  • 录制用例优化

标准的用例结构

  • 用例标题
  • 前提条件
  • 用例步骤
  • 预期结果
  • 实际结果

 

用例结构对比

IDE录制脚本

  • 脚本步骤:
    • 访问搜狗网站
    • 搜索框输入“霍格沃兹测试开发”
    • 点击搜索按钮
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

class Test():
  def setup_method(self, method):
    self.driver = webdriver.Chrome()
    self.vars = {}
  
  def teardown_method(self, method):
    self.driver.quit()
  
  def test_sougou(self):
    # 打开网页,设置窗口
    self.driver.get("https://www.sogou.com/")
    self.driver.set_window_size(1235, 693)
    # 输入搜索信息
    self.driver.find_element(By.ID, "query").click()
    self.driver.find_element(By.ID, "query").send_keys("霍格沃兹测试开发")
    # 点击搜索
    self.driver.find_element(By.ID, "stb").click()
    element = self.driver.find_element(By.ID, "stb")
    actions = ActionChains(self.driver)
    actions.move_to_element(element).perform()

 

脚本优化

import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

class TestDemo01():
  def setup_method(self, method):
    # 实例化chromedriver
    self.driver = webdriver.Chrome()
    # 添加全局隐式等待
    self.driver.implicitly_wait(5)
  
  def teardown_method(self, method):
    # 关闭driver
    self.driver.quit()
  
  def test_demo01(self):
    # 访问网站
    self.driver.get("https://www.baidu.com/")
    # 设置窗口
    self.driver.set_window_size(1330, 718)
    # 点击输入框
    self.driver.find_element(By.ID, "kw").click()
    # 输入框输入信息
    self.driver.find_element(By.ID, "kw").send_keys("霍格沃兹测试开发")
    # 点击搜索按钮
    self.driver.find_element(By.ID, "su").click()
    # 等待界面加载
    time.sleep(5)
    # 元素定位后获取文本信息
    res = self.driver.find_element(By.XPATH,"//*[@id='1']/h3/a").get_attribute("text")
    # 打印文本信息
    print(res)
    # 添加断言
    assert "霍格沃兹测试开发" in res
    # 查看界面展示
    time.sleep(5)

IDE 录制脚本(Java)

// Generated by Selenium IDE
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;
import java.util.*;
import java.net.MalformedURLException;
import java.net.URL;
public class TestSogouTest {
  private WebDriver driver;
  private Map<String, Object> vars;
  JavascriptExecutor js;
  @Before
  public void setUp() {
    driver = new ChromeDriver();
    js = (JavascriptExecutor) driver;
    vars = new HashMap<String, Object>();
  }
  @After
  public void tearDown() {
    driver.quit();
  }
  @Test
  public void testSogou() {
    driver.get("https://www.sogou.com/");
    driver.manage().window().setSize(new Dimension(1671, 1417));
    driver.findElement(By.id("query")).sendKeys("霍格沃兹测试开发");
    driver.findElement(By.id("query")).sendKeys(Keys.ENTER);
  }
}

pom依赖(Java)

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>beginner</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>11</java.version>
        <!-- 使用 Java 11 语言特性 ( -source 11 ) 并且还希望编译后的类与 JVM 11 ( -target 11 )兼容,您可以添加以下两个属性,它们是默认属性插件参数的名称-->
        <maven.compiler.target>11</maven.compiler.target>
        <!-- 对应junit Jupiter的版本号;放在这里就不需要在每个依赖里面写版本号,导致对应版本号会冲突-->
        <junit.jupiter.version>5.8.2</junit.jupiter.version>
        <maven.compiler.version>3.8.1</maven.compiler.version>
        <maven.surefire.version>3.0.0-M5</maven.surefire.version>
        <hamcrest.version>2.2</hamcrest.version>
        <!-- plugins -->
        <maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
        <!-- log日志 -->
        <slf4j.version>2.0.0-alpha7</slf4j.version>
        <logback.version>1.3.0-alpha16</logback.version>

    </properties>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.2.1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>${junit.jupiter.version}</version>
        </dependency>
        <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version>${junit.jupiter.version}</version>
        </dependency>
    </dependencies>
    <build>
        <!-- maven 运行的依赖插件 -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <parameters>true</parameters>
                    <source>11</source>
                    <target>11</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M7</version>
                <configuration>
                    <includes>
                        <include>**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

脚本优化(Java)

  • 隐式等待(了解即可)
  • 断言信息
// Generated by Selenium IDE
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Alert;
import org.openqa.selenium.Keys;

import java.time.Duration;
import java.util.*;
import java.net.MalformedURLException;
import java.net.URL;

import static org.junit.Assert.assertEquals;

public class TestSogouTest {
  private WebDriver driver;
  private Map<String, Object> vars;
  JavascriptExecutor js;
  @Before
  public void setUp() {
    //  实例化chromedriver
    driver = new ChromeDriver();
    //  添加全局隐式等待
    js = (JavascriptExecutor) driver;
    vars = new HashMap<String, Object>();
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));

  }
  @After
  //  关闭driver
  public void tearDown() {
    driver.quit();
  }
  @Test
  public void testSogou() {
    // 打开网页
    driver.get("https://www.sogou.com/");
    // 设置窗口
    driver.manage().window().setSize(new Dimension(1671, 1417));
    // 输入霍格沃兹测试开发
    driver.findElement(By.id("query")).sendKeys("霍格沃兹测试开发");
    // 回车搜索
    driver.findElement(By.id("query")).sendKeys(Keys.ENTER);
    // 获取搜索的文本结果
    String text = driver.findElement(By.cssSelector("#sogou_vr_30000000_0 > em")).getText();
    // 断言是否包含期望文本
    assertEquals("霍格沃兹测试开发", text);

  }
}

最后:下面是配套学习资料,对于做【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴我走过了最艰难的路程,希望也能帮助到你!【100%无套路免费领取】

软件测试面试小程序

被百万人刷爆的软件测试题库!!!谁用谁知道!!!全网最全面试刷题小程序,手机就可以刷题,地铁上公交上,卷起来!

涵盖以下这些面试题板块:

1、软件测试基础理论 ,2、web,app,接口功能测试 ,3、网络 ,4、数据库 ,5、linux

6、web,app,接口自动化 ,7、性能测试 ,8、编程基础,9、hr面试题 ,10、开放性测试题,11、安全测试,12、计算机基础

  全套资料获取方式:点击下方小卡片自行领取即可

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1073114.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

对音频切分成小音频(机器学习用)

我是把so-vits中小工具&#xff0c;分析源码然后提取出来了。以后可以写在自己的程序里。 -------流程&#xff08;这是我做的流程&#xff0c;你可以不用看&#xff09; 从开源代码中快速获取自己需要的东西 如果有界面f12看他里面的接口&#xff0c;然后在源码中全局搜索&…

英国/法国/意大利/德国/西班牙,电动交通设备合规政策更新!

英国/法国/意大利/德国/西班牙&#xff0c;电动交通设备合规政策更新&#xff01; 产品安全 合规政策更新&#xff01;或加昵称咨询 NOTICE 尊敬的卖家&#xff1a; 您好&#xff01; 我们此次联系您是因为您正在销售需要审批流程的商品。为此&#xff0c;亚马逊正在实施审…

九大装修收纳空间的设计,收藏备用!福州中宅装饰,福州装修

如果房子面积不大&#xff0c;收纳设计就显得非常重要。其实装修房子中很多地方都可以做收纳&#xff0c;九大空间每一处都可以放下你的东西&#xff0c;让你摆脱收纳烦恼。 收纳空间少的话&#xff0c;装修完后住久了怕会乱成一窝&#xff0c;因此装修的时候&#xff0c;收纳…

google hack常用语法介绍

Google hacker (Google黑客)是利用GOOGLE提供的搜索功能查找黑客们想找到的信息.一般是查找网站后台,网管的个人信息,也可以用来查找某人在网络上的活动. Google hacker 一般是做为黑客在入侵时的一个手段.在入侵过程中有时需要查找后台的登陆口就需要用到GOOGLE HACKER.有…

在asp.net中,实现类似安卓界面toast的方法(附更多弹窗样式)

最近在以前的asp.net网页中&#xff0c;每次点击确定都弹窗&#xff0c;然后还要弹窗点击确认&#xff0c;太麻烦了&#xff0c;这次想升级一下&#xff0c;实现类似安卓toast的弹窗提示方式。于是百度了一下&#xff0c;目前看到有两种&#xff0c;sweetalert和toastr。 这里…

Python接口自动化测试实战详解,你想要的全都有

前言 接口自动化测试是当前软件开发中最重要的环节之一&#xff0c;可以提高代码质量、加速开发周期、减少手工测试成本等优点。Python语言在接口自动化测试方面应用广泛&#xff0c;因为它具有简单易学、开发效率高、库丰富等特点。 一、接口自动化测试概述 接口自动化测试…

六个交易日市值蒸发20亿港元,第四范式难逃AI大模型“魔咒”

AI独角兽第四范式终于敲钟了。 北京第四范式智能技术股份有限公司(06682.HK&#xff0c;下称“第四范式”)于9月28日正式挂牌港交所&#xff0c;发行价为55.60港元/股&#xff0c;IPO首日报收58.50港元/股。 上市后6个交易日&#xff0c;截至10月6日港股收盘&#xff0c;第四…

【无监控,不运维!这份监控建设总结太赞了!】

运维行业有句话&#xff1a;“无监控、不运维”&#xff0c;是的&#xff0c;一点也不夸张&#xff0c;监控俗称“第三只眼”。没了监控&#xff0c;什么基础运维&#xff0c;业务运维都是“瞎子”。所以说监控是运维这个职业的根本。 尤其是在现在DevOps这么火的时候&#xf…

【网络安全】网络安全的最后一道防线——“密码”

网络安全的最后一道防线——“密码” 前言超星学习通泄露1.7亿条信息事件武汉市地震监测中心遭境外网络攻击事件 一、密码起源1、 古代密码2、近代密码3、现代密码4、量子密码 二、商密专栏推荐三、如何利用密码保护账号安全&#xff1f;1、账号安全的三大危险&#xff1f;&…

LLaMA Adapter和LLaMA Adapter V2

LLaMA Adapter论文地址&#xff1a; https://arxiv.org/pdf/2303.16199.pdf LLaMA Adapter V2论文地址&#xff1a; https://arxiv.org/pdf/2304.15010.pdf LLaMA Adapter效果展示地址&#xff1a; LLaMA Adapter 双语多模态通用模型 为你写诗 - 知乎 LLaMA Adapter GitH…

PSN 两步验证解除2023.10.9经验贴

背景 本人10月1号收到Sony邮件&#xff0c;说是不规律登录&#xff0c;需修改密码后登录&#xff0c;然后我10月8日登录PS4的时候&#xff0c;提示两步验证。当时就想坏了&#xff0c;然后找B站相关经验贴&#xff0c;10月9号电话香港客服&#xff0c;解除了两步验证&#xff0…

IOT 围炉札记

文章目录 一、蓝牙二、PAN1080三、IOT OS四、通讯 一、蓝牙 树莓派上的蓝牙协议 BlueZ 官网 BlueZ 官方 Linux Bluetooth 栈 oschina 二、PAN1080 pan1080 文档 三、IOT OS Zephyr 官网 Zephyr oschina Zephyr github 第1章 Zephyr简介 第2章 Zephyr 编译环境搭建&#…

云管理平台基本功能有哪些?适配国产化平台吗?

随着云计算的大力发展&#xff0c;越来越多的企业需要云管理平台了。但很多其他对于云管理平台不是很了解&#xff0c;有小伙伴问&#xff0c;云管理平台基本功能有哪些&#xff1f;适配国产化平台吗&#xff1f;这里我们小编就给大家解答一下。 云管理平台基本功能有哪些&am…

【Java】中小学智慧校园管理系统源码 SaaS模式+电子班牌系统

智慧校园电子班牌系统&#xff0c;主要针对中小学校园研发&#xff0c;为校园管理提供智慧管理方案&#xff0c;提供校园智慧管理平台&#xff0c;在大数据平台下&#xff0c;对应用系统进行统一、集中管理&#xff0c;囊括校园管理全方面&#xff0c;实现对校园、班级、教师、…

商城系统选型:Java商城系统还是PHP商城系统好?

电子商务的不断发展&#xff0c;商城系统成为了企业建设在线销售平台的重要组成部分。 可是在选择合适的商城系统时&#xff0c;许多企业面临着一个重要的决策&#xff1a;是选择Java商城系统还是PHP商城系统呢&#xff1f;下面就对这两种常见的商城系统进行比较&#xff0c;并…

jump server是什么

Jump Server&#xff08;跳板服务器&#xff09;是一种安全的中间服务器&#xff0c;用于管理和控制对其他服务器的访问。它提供了一种安全的方式&#xff0c;允许管理员通过跳板服务器来管理和连接其他服务器&#xff0c;而无需直接从外部网络访问内部服务器。 跳板服务器的主…

seata分布式事务理论概述

分布式事务产生的原因&#xff1a; 数据库分库分表 应用的SOA化。就是业务的服务化(面向服务架构) 分布式事务的解决方案&#xff1a; 1、两阶段提交协议2PC 这里的两阶段提交和redolog binlog的两阶段提交不是一个东西&#xff0c;redo log和bin log的两阶段提交保证的是…

vulnhub靶场 Kioptrix-level-1

简介&#xff1a; vulnhub是一个提供靶场环境的平台。而Kioptrix-level-1就是一个对新手比较友好的靶场。初学渗透的同学可以做做试试看&#xff0c;项目地址如下。 项目地址&#xff1a;Kioptrix: Level 1 (#1) ~ VulnHub 信息收集 查看本机IP&#xff0c;靶机跟kali都是使用…

sqli-lab靶场通关

文章目录 less-1less-2less-3less-4less-5less-6less-7less-8less-9less-10 less-1 1、提示输入参数id&#xff0c;且值为数字&#xff1b; 2、判断是否存在注入点 id1报错&#xff0c;说明存在 SQL注入漏洞。 3、判断字符型还是数字型 id1 and 11 --id1 and 12 --id1&quo…

C++中的对象切割(Object slicing)问题

在C中&#xff0c;当我们把派生类对象向上强制转型为基类对象时&#xff0c;会造成对象切割&#xff08;Object slicing&#xff09;问题。  请看下面示例代码&#xff1a; #include <iostream> using namespace std;class CBase { public:virtual ~CBase() default;v…