Selenium (3) —— Selenium IDE + Firefox录制登录脚本(101 Tutorial)


selenium IDE版本: 2.9.1

firefox版本: 39.0.3

参考来源:

Selenium官方下载

Selenium IDE

Understanding Selenium IDE vs Selenium RC

Selenium IDE Tutorial – Part 1

主要内容

Selenium IDE 是一个为进行Selenium测试的集成开发环境工具。Selenium测试可以用HTML table编写,也可以用其他语言来编写,比如C#,PHP,Perl,Python。IDE可以为我们录制,编辑和调试测试。目前IDE以addon的形式只支持Firefox。

安装

可以到以下地址安装

http://selenium-ide.openqa.org/download.jsp

https://addons.mozilla.org/en-US/firefox/addon/2079

安装完毕后需要重启firefox,注意当前最新的IDE 2.9.1与Firefox 40+不太兼容,建议使用40以下的版本,我这里使用的是39.0.3

录制

以登录cnblogs为例

IDE启动时,默认状态下是正在录制的

如果没有处于录制状态,需要点击右上角的红色按钮

  • 我们在浏览器上一次进行以下操作

    1. 输入URL地址http://passport.cnblogs.com/user/signin,并访问
    2. 输入用户名、密码
    3. 点击登录

  • HTML table格式

    保存测试文件

    查看录制文件

      	<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head profile="http://selenium-ide.openqa.org/profiles/test-case">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="selenium.base" href="http://passport.cnblogs.com/" />
    <title>cnblogs</title>
    </head>
    <body>
    <table cellpadding="1" cellspacing="1" border="1">
    <thead>
    <tr><td rowspan="1" colspan="3">cnblogs</td></tr>
    </thead><tbody>
    <tr>
    <td>open</td>
    <td>/user/signin?AspxAutoDetectCookieSupport=1</td>
    <td></td>
    </tr>
    <tr>
    <td>type</td>
    <td>id=input1</td>
    <td>weizhe_2008</td>
    </tr>
    <tr>
    <td>type</td>
    <td>id=input2</td>
    <td>********</td>
    </tr>
    <tr>
    <td>clickAndWait</td>
    <td>id=signin</td>
    <td></td>
    </tr> </tbody></table>
    </body>
    </html>
  • 导出其他格式(Java,Ruby)

    同样在文件菜单下,我们可以选择导出java或其他语言(File-> Export Test Case As...)

    • Java(Java / TestNG / WebDriver)

        package com.example.tests;
      
        import java.util.regex.Pattern;
      import java.util.concurrent.TimeUnit;
      import org.testng.annotations.*;
      import static org.testng.Assert.*;
      import org.openqa.selenium.*;
      import org.openqa.selenium.firefox.FirefoxDriver;
      import org.openqa.selenium.support.ui.Select; public class Cnblogs {
      private WebDriver driver;
      private String baseUrl;
      private boolean acceptNextAlert = true;
      private StringBuffer verificationErrors = new StringBuffer(); @BeforeClass(alwaysRun = true)
      public void setUp() throws Exception {
      driver = new FirefoxDriver();
      baseUrl = "http://passport.cnblogs.com/";
      driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      } @Test
      public void testCnblogs() throws Exception {
      driver.get(baseUrl + "/user/signin?AspxAutoDetectCookieSupport=1");
      driver.findElement(By.id("input1")).clear();
      driver.findElement(By.id("input1")).sendKeys("weizhe_2008");
      driver.findElement(By.id("input2")).clear();
      driver.findElement(By.id("input2")).sendKeys("********");
      driver.findElement(By.id("signin")).click();
      } @AfterClass(alwaysRun = true)
      public void tearDown() throws Exception {
      driver.quit();
      String verificationErrorString = verificationErrors.toString();
      if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
      }
      } private boolean isElementPresent(By by) {
      try {
      driver.findElement(by);
      return true;
      } catch (NoSuchElementException e) {
      return false;
      }
      } private boolean isAlertPresent() {
      try {
      driver.switchTo().alert();
      return true;
      } catch (NoAlertPresentException e) {
      return false;
      }
      } private String closeAlertAndGetItsText() {
      try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
      alert.accept();
      } else {
      alert.dismiss();
      }
      return alertText;
      } finally {
      acceptNextAlert = true;
      }
      }
      }
    • Ruby(Ruby / RSpec / WebDriver)

        	require "json"
      require "selenium-webdriver"
      require "rspec"
      include RSpec::Expectations describe "Cnblogs" do before(:each) do
      @driver = Selenium::WebDriver.for :firefox
      @base_url = "http://passport.cnblogs.com/"
      @accept_next_alert = true
      @driver.manage.timeouts.implicit_wait = 30
      @verification_errors = []
      end after(:each) do
      @driver.quit
      @verification_errors.should == []
      end it "test_cnblogs" do
      @driver.get(@base_url + "/user/signin?AspxAutoDetectCookieSupport=1")
      @driver.find_element(:id, "input1").clear
      @driver.find_element(:id, "input1").send_keys "weizhe_2008"
      @driver.find_element(:id, "input2").clear
      @driver.find_element(:id, "input2").send_keys "********"
      @driver.find_element(:id, "signin").click
      end def element_present?(how, what)
      ${receiver}.find_element(how, what)
      true
      rescue Selenium::WebDriver::Error::NoSuchElementError
      false
      end def alert_present?()
      ${receiver}.switch_to.alert
      true
      rescue Selenium::WebDriver::Error::NoAlertPresentError
      false
      end def verify(&blk)
      yield
      rescue ExpectationNotMetError => ex
      @verification_errors << ex
      end def close_alert_and_get_its_text(how, what)
      alert = ${receiver}.switch_to().alert()
      alert_text = alert.text
      if (@accept_next_alert) then
      alert.accept()
      else
      alert.dismiss()
      end
      alert_text
      ensure
      @accept_next_alert = true
      end
      end

回放

点击Selenium IDE菜单栏上的绿色按钮

执行结果

结束

Selenium (3) —— Selenium IDE + Firefox录制登录脚本(101 Tutorial)的更多相关文章

  1. Selenium IDE脚本录制步骤简介

    录制脚本步骤: 1.打开Selenium IDE,输入需要录制脚本的地址,然后启动Firefox,输入selenium IDE需录制的地址,根据实际需求,做相关操作: 2.录制过程中,会发现做的相关操 ...

  2. Selenium (4) —— Selenium是什么? WebDriver是什么?做什么?(101 Tutorial)

    Selenium (4) -- Selenium是什么? WebDriver是什么?做什么?(101 Tutorial) selenium版本: v2.48.0 (Standalone Seleniu ...

  3. Selenium (2) —— Selenium WebDriver + Grid2(101 Tutorial)

    Selenium (2) -- Selenium WebDriver + Grid2(101 Tutorial) jvm版本: 1.8.0_65 selenium版本: v2.48.0 (Standa ...

  4. Selenium (1) —— Selenium安装与测试(101 Tutorial)

    Selenium (1) -- Selenium安装与测试(101 Tutorial) jvm版本: 1.8.0_65 selenium版本: v2.48.0 (Standalone Selenium ...

  5. Selenium+python+shell+crontab+firefox

    最近在尝试一个自动打卡的脚本,发现了几个问题,特此记录一下. 环境: Ubuntu 12.04.4 LTS selenium 2.43.0 firefox 32.0.3 1 本来机器上selenium ...

  6. 【selenium】- selenium简介

    本文由小编根据慕课网视频亲自整理,转载请注明出处和作者. 1. Selenium的来历 2. Selenium家庭成员 Selenium RC: Selenium 1 Selenium Webdriv ...

  7. JMeter (3) —— JMeter录制脚本并压力测试用户登陆场景以CAS SSO为例(101 Tutorial)

    JMeter (3) -- JMeter录制脚本并压力测试用户登陆场景以CAS SSO为例(101 Tutorial) 主要内容 JMeter录制脚本并进行压力测试用户登陆场景,并以CAS SSO单点 ...

  8. selenium - 查看selenium版本信息

    1. pip list 2. pip show selenium 3. cmd>>python >>> import selenium>>> help( ...

  9. Selenium(一)---Selenium的安装和使用

    一.前言 最近在帮一个老师爬取网页内容,发现网页是动态加载的,为了拿到全部的网页数据,这里使用到了Selenium.Selenium 是一个用于Web应用程序测试的工具,它可以模拟真实浏览器,支持多种 ...

随机推荐

  1. 使用 http 请求方式获取 eureka server的服务信息

    对于一些系统不能接入 eureka server,又需要访问接入eureka server 的服务. 方法一:直接调用服务的地址是一种实现方式,弊端就是地址是写死的,万一服务地址变更则访问不到. 方法 ...

  2. jeecg删除菜单导致角色权限设置点不开的问题解决

    在JEECG中经常需要删除一些菜单,但是由于当前使用版本jeecg3.7.1功能不够完善,需要手动去删除角色对应目录表的没删除干净的数据,要删除的数据查询SQL语句如下: select * from ...

  3. 不要随便使用 runAllManagedModulesForAllRequests="true" 来解决问题

    在 IIS 7.0 中,对于使用 Url 路由 访问页面的 ASP.NET 应用程序,IIS可能会不能出 Url 是对 ASP.NET 的请求. 会显示404啊,403啊之类的错误代码(因为路径不存在 ...

  4. 一个里表世界切换的shader效果

    之前GGJ实现了一个,但是实现方式上有很多冗余.今天正好在做一个类似的东西,重新做了一个版本 还是当时美术画的素材: 由于里表世界是不同的内容,是两张材质.所以拆分成不同Layer之后,里世界单独渲染 ...

  5. Golang 新手可能会踩的 50 个坑

    前言 Go 是一门简单有趣的编程语言,与其他语言一样,在使用时不免会遇到很多坑,不过它们大多不是 Go 本身的设计缺陷.如果你刚从其他语言转到 Go,那这篇文章里的坑多半会踩到. 如果花时间学习官方 ...

  6. 数据库的硬迁移和mysql 5.5.38源码安装

    场景:一台服务器出现了故障,需要把数据库迁移到另一台服务器上,由于数据效大,直接压缩数库的数据目录(在数据库DOWN的情况下)数据库版本mysql 5.5.38安装方式:源码安装思路:在另一台服务器上 ...

  7. mydqldump 备份数单库 然后还原数据的时候报:ERROR 1881 (HY000) at line 52: Operation not allowed when innodb_forced_recovery > 0.

    修改my.cnf innodb_force_recovery = 1 修改为: innodb_force_recovery = 0

  8. c#多线程 Invoke方法的使用

    在多线程编程中,我们经常要在工作线程中去更新界面显示,而在多线程中直接调用界面控件的方法是错误的做法,Invoke 和 BeginInvoke 就是为了解决这个问题而出现的,使你在多线程中安全的更新界 ...

  9. 每日英语:China to Move Slowly on One-Child Law Reform

    BEIJING—China's family-planning agency is projecting a slow rollout for an easing of its one-child p ...

  10. 20、uwp打包失败(All app package manifests in a bundle must declare the same values under the XPath *[local-name()='Package']/*[local-name()='Dependencies'])

    在给 uwp工程打商店包的时候,遇到了一个异常: Error info: error 80080204: All app package manifests in a bundle must decl ...