festselenium项目背景:

基于浏览器的Applet使用开源方法进行自动化测试一直是一个难题。希望这篇文章能够为你提供一个开源的参考方案。

如果你使用Java Swing进行Applet或者GUI开发,你就可能使用过fest进行单元测试或者Acceptance测试。fest简单易用,它的用户包括:Google, Square, Eclipse Foundation, Oracle, IBM, Guidewire等等。同时许多公司都在使用Selenium进行网页方面的测试。如何能够把两者结合起来,就是我们讨论的话题。有老外开发了一个.net 的FEST-Selenium,能从一定程度上解决这个问题,他有以下不足之处:

1,不支持java,只能使用.net

2,我们不能重用fest简单的语法。

这个festselenium项目就是能够重用以前fest的测试代码,差不多不要修改就能通过selenium进行远端控制。festselenium自动实现client<->selenium<->fixture<->SUT的最终交互。

这是我以前写的一个自动测试框架,通过http://code.google.com/p/festselenium/ 能访问源代码。

Fest和Festselenium testcase代码比较

Fest示例:

dialog.comboBox("domain").select("Users");
dialog.textBox("username").enterText("alex.ruiz");
dialog.button("ok").click();

festselenium示例:

除了要新建一个selenium连接,用户几乎感觉不到中间已经多了selenium这一层

// selenium setup
selenium = new DefaultJavaSelenium("localhost",4444, browserString , url);
selenium.start();
selenium.open(url);// get the appletfixure to control fest JAppletFixture
AppletFixture dialog = selenium.applet(LIST_APPLET_ID)// fest similar API for autmation testing
dialog.comboBox("domain").select("Users");
dialog.textBox("username").enterText("alex.ruiz");
dialog.button("ok").click();

完整流程Demo

step1~3和6和以前fest进行applet一样。4除了要新建一个selenium连接之外和fest测试代码是一样的。4到5就是这个项目的核心,完成festselenium测试代码-〉selenium调用-〉fest fixture的自动转换。

1, 被测Applet代码:

package com.nemo.festselenium.demo;import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;import javax.swing.*;
import javax.swing.text.JTextComponent;public class DemoApplet extends JApplet implements AdjustmentListener{private static final long serialVersionUID = 1L;JScrollBar slider;              JTextComponent text;            JPanel panel;public void adjustmentValueChanged(AdjustmentEvent e) {text.setText(new Integer(slider.getValue()).toString());} public DemoApplet(){slider = new JScrollBar(JScrollBar.HORIZONTAL, 0, 1, 0, 100);text = new JTextArea("0");panel = new JPanel();panel.add(text);panel.add(slider);add(panel);slider.addAdjustmentListener(this);}
}

2, 被测试对象fixture

package com.nemo.festselenium.demo;import org.fest.swing.fixture.JAppletFixture;public class JTestFixture extends DemoApplet {JAppletFixture fixture;public JTestFixture() {super();setName("demo_applet");fixture=new JAppletFixture(this);}public JAppletFixture getTestFixture() {return fixture;}
}

3, 新建一个HTML,ID=demo_applet

<html>
<head>
<title>Test</title>
</head>
<body>
<div>
<object id="demo_applet" width="300" height="150" type="application/x-java-applet"><param name="java_code" value="com.nemo.festselenium.demo.JTestFixture.class" /><param name="java_archive" value="fest-swing-1.2a3.jar,fest-assert-1.1.jar,fest-util-1.1.jar,fest-reflect-1.2-SNAPSHOT.jar" />
</object>
</div>
</body>
</html>

4,festselenium驱动selenium进行单元测试代码:

package com.nemo.festselenium.demo;import static org.junit.Assert.*;import org.junit.*;
import com.nemo.festselenium.fixture.*;
import com.nemo.festselenium.selenium.*;public class DemoTest {DefaultJavaSelenium selenium;@Beforepublic void setUp() {selenium = new DefaultJavaSelenium("localhost",4444, "*iexplore" , "http://localhost:8080");            }@Afterpublic void tearDown() {selenium.stop();}@Testpublic void test() {selenium.start();selenium.open("demo_applet.html");selenium.windowMaximize();AppletFixture fixture = selenium.applet("demo_applet");ScrollBarFixture scrollbar = fixture.scrollBar();TextComponentFixture text = fixture.textBox();scrollbar.scrollUnitUp();assertEquals(text.text(), "1");         }       }

5,把远端对象请求转化为Selenium的调用:

15:19:56.179 INFO - Command request: getNewBrowserSession[*iexplore, http://loca
15:20:04.659 INFO - Command request: open[demo_applet.html, ] on session a84fc32
15:20:08.223 INFO - Command request: windowMaximize[, ] on session a84fc3216d6c4
1f1865ab7a710189814
15:20:08.847 INFO - Command request: getEval[navigator.userAgent, ] on session a
84fc3216d6c41f1865ab7a710189814
15:20:09.378 INFO - Command request: getEval[window.document.getElementById("dem
o_applet").getTestFixture().scrollBar().scrollUnitUp(), ] on session a84fc3216d6
c41f1865ab7a710189814
15:20:10.205 INFO - Command request: getEval[window.document.getElementById("dem
o_applet").getTestFixture().textBox().text(), ] on session a84fc3216d6c41f1865ab
7a710189814

6,fest fixture继续完成后面的工作

fest + selenium进行In-browser Applet自动化测试相关推荐

  1. python怎么做界面自动化_mac+python3+selenium做pc的界面自动化测试

    首先安装环境大家可以参考这篇文章https://www.zhihu.com/question/30496889 如果想直接安装到python3路径中可使用命令:sudo pip3 install se ...

  2. Selenium 凭什么成为 Web 自动化测试的首选?(内附源码)

    <自动化>工具 1.QTP QTP是一个商业化的功能测试工具,收费,支持web,桌面自动化测试. 2. Selenium(文章重点讲) Selenium是一个开源的web自动化测试工具,免 ...

  3. docker+robot framework+selenium并发web应用UI自动化测试实践

    自己在日常测试中,会搭建UI自动化测试框架来进行web应用的回归测试,在这过程中遇到了许多问题,如测试脚本和执行机不分离,串行测试效率低下,环境搭建麻烦等问题.在这个过程中,自己也在网上看一些前辈的搭 ...

  4. nightwatch + selenium 基于浏览器的web自动化测试 教程(一)

    目录 什么是nightwatch nightwatch的实现原理 安装与配置 安装nodejs 安装nightwatch Selenium Server Setup Selenium Server 下 ...

  5. Python + Selenium,分分钟搭建 Web 自动化测试框架!

    在程序员的世界中,一切重复性的工作,都应该通过程序自动执行.「自动化测试」就是一个最好的例子. 随着互联网应用开发周期越来越短,迭代速度越来越快,只会点点点,不懂开发的手工测试,已经无法满足如今的业务 ...

  6. Python + Selenium,分分钟搭建 Web 自动化测试框架

    在程序员的世界中,一切重复性的工作,都应该通过程序自动执行. 「自动化测试」就是一个最好的例子. 随着互联网应用开发周期越来越短,迭代速度越来越快,只会点点点,不懂开发的手工测试,已经无法满足如今的业 ...

  7. 【Selenium+Pytest+allure报告生成自动化测试框架】附带项目源码和项目部署文档

    目录 前言 [文章末尾给大家留下了大量的福利] 测试框架简介 首先管理时间 添加配置文件 conf.py config.ini 读取配置文件 记录操作日志 简单理解POM模型 简单学习元素定位 管理页 ...

  8. Selenium基于Python 进行 web 自动化测试

    配置使用环境 下载相应的浏览器驱动, Firefox 是默认的  本文以 chrome 为主 ,放在scripts目录下 ChromeDriver 官方下载地址 : 所有版本的 ChromeDrive ...

  9. python selenium自动化获取oracle_Python+selenium2 自动化测试登录

    from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from se ...

最新文章

  1. AI研发新药登上Nature子刊:46天合成潜在新药候选分子,比传统方法快15倍 | 开源...
  2. alientek ministm32液晶显示程序_佳显12864中文字库液晶专业生产液晶显示模块
  3. unity python_Unity引擎内嵌python
  4. 【操作系统】高速缓存和缓冲区
  5. 第1章 ASP.NET 3.5与开发工具
  6. 误区30日谈21-24
  7. 燃烧我的卡路里 ---- Flutter瘦内存瘦包之图片组件
  8. 关于自然排序Comparable 和 比较器排序Comparator
  9. php object 对象不存在。增加对象_《相亲者女》:找一个匹配的对象,但永远不存在...
  10. 贝叶斯定理决策规则及Bayes思想总结
  11. php 字符串合并,如何在PHP中将两个字符串组合在一起?
  12. 俄罗斯方块中方块的旋转变形
  13. CSS的repeating-radial-gradient()属性-径向渐变
  14. 再生龙移植ubuntu硬盘大小限制解决方案
  15. 网易互娱2017实习生招聘在线笔试--源代码编译
  16. 【小程序】766- 一文看懂小程序分享到朋友圈
  17. SAP 固定资产日期
  18. 哪款蓝牙耳机的音质好?盘点四款高颜值蓝牙耳机
  19. Git(5) SourceTree安装使用
  20. 高通平台SSC架构-sensor学习

热门文章

  1. NUCLEO-F767ZI以太网功能实现笔记本电脑不开盖开机
  2. 西西吹雪:从程序员到项目经理(一)
  3. UPC 2020年夏混合个人训练第六十四场【ACDG】
  4. Mac 32/64位平面、3d设计软件集子
  5. 机动车缉查布控即席分析引擎
  6. android基础--canvas绘图
  7. 谈谈对K8S CNI、CRI和CSI插件的理解
  8. 四级地址库 国家标准的行政区划代码 省市区街道
  9. 笔记本软件页面分辨率低_笔记本分辨率降低怎么办_笔记本电脑电脑分辨率低怎么解决-win7之家...
  10. x2检验(chi-square test)/ 卡方检验