自动化测试框架AutoTest

来源:互联网 发布:vim c语言插件 编辑:程序博客网 时间:2024/05/18 00:17
  • 介绍

这里介绍一个基于Selenium实现的一个web自动化测试框架,本框架主要是通过对Selenium的封装实现降低学习自动化测试框架的难度。 如果,您还对Selenium不了解的话,可以先参考《Selenium学习建议》。
  • 入门知识

Java基础、XML基础
  • 进阶知识

Java、Spring、Eclipse插件开发、Maven、Archetype、Selenium、XML、XSD
  • 环境

jdk1.7、Eclipse、Maven
  • 特色

支持元素模型;把HTML页面元素都抽象为一些列的模型。支持多种元素选择策略(优先级、循环、区域);通过一些列策略来定位元素,效率更高,使用更加方便。支持iFrame中的元素定位支持多种数据源支持多种浏览器支持浏览器参数配置(宽度、高度等)支持Selenium引擎参数配置支持文件上传;基于autoit3支持XML配置文件格式校验;这里使用XSD来进行格式的规定以及校验。支持在Eclipse中编写配置文件时的自动提示;需要添加XSD配置。[caption id="attachment_4785" align="aligncenter" width="844"]autotest.web.framework.config autotest.web.framework.config[/caption]支持Eclipse插件;自动生成Page类,无需记忆过多的API。支持Maven骨架;通过骨架来创建工程效率更高,避免不必要的错误。
  • 入门

Selenium学习视频:基于Selenium的UI自动化测试框架讲解链接:http://pan.baidu.com/s/1kV8qRWF 密码:0s1b基于Selenium的UI自动化测试框架百度搜索实战链接:http://pan.baidu.com/s/1slvTuLf 密码:r1e5本项目采用Maven进行管理,使用的话,需要在您的工程pom.xml文件中添加以下信息:[codesyntax lang="xml"]
<repositories><repository><id>autotest.web.framework.surenpi.com</id><url>http://maven.surenpi.com/nexus/content/repositories</url></repository></repositories><dependencies><dependency><groupId>org.suren.autotest</groupId><artifactId>autotest.web.framework</artifactId><version>0.0.2-SNAPSHOT</version></dependency></dependencies>
[/codesyntax]
  • 示例

使用本框架,只需要继承Page类实现对测试页面的封装、Page类信息描述xml文件、测试类即可。如果您需要使用数据源的话,支持xml格式的数据源。更多示例请访问下面的码云链接(愿意给框架贡献示例的请留言):http://git.oschina.net/surenpi/autotest.web.framework.demo下面是测试类:[codesyntax lang="java"]
package org.suren.autotest.web.framework.test;import org.suren.autotest.web.framework.settings.SettingUtil;import org.suren.autotest.web.framework.surenpi.HomePage;public class SuRenPiTest {public static void main(String[] args) throws Exception {SettingUtil util = new SettingUtil();try {util.readFromClassPath("surenpi_website.xml");HomePage homePage = util.getPage(HomePage.class);homePage.open();homePage.getHomeBut().click();for(int i = 0; i < 18; i++) {homePage.getNextBut().click();Thread.sleep(1000);}homePage.getArchivesSelector().selectByText(" 2015年五月  (15)");Thread.sleep(3000);homePage.close();} finally {}}}
[/codesyntax]下面是Page类:[codesyntax lang="java"]
package org.suren.autotest.web.framework.surenpi;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import org.suren.autotest.web.framework.core.ui.Button;import org.suren.autotest.web.framework.core.ui.Selector;import org.suren.autotest.web.framework.page.Page;@Component("surenpi.home.page")public class HomePage extends Page {@Autowiredprivate Button homeBut;@Autowiredprivate Selector archivesSelector;@Autowiredprivate Button nextBut;public Button getHomeBut() {return homeBut;}public void setHomeBut(Button homeBut) {this.homeBut = homeBut;}public Selector getArchivesSelector() {return archivesSelector;}public void setArchivesSelector(Selector archivesSelector) {this.archivesSelector = archivesSelector;}public Button getNextBut() {return nextBut;}public void setNextBut(Button nextBut) {this.nextBut = nextBut;}}
[/codesyntax]下面是Page类描述文件:[codesyntax lang="xml"]
<autotest><engine driver="chrome" timeout="30" fullScreen="true" width="1286" height="768"></engine><pages><page class="org.suren.autotest.web.framework.surenpi.HomePage"url="http://surenpi.com"><field name="homeBut" byLinkText="素人派" type="button" /><field name="archivesSelector" byId="archives-dropdown-2" type="select" /><field name="nextBut" byLinkText="下一个 →" byCss="next page-numbers" type="button" /></page></pages></autotest>
[/codesyntax]1470290549603下面是360云盘中的demo工程文件下载地址:https://yunpan.cn/c6fve2wK7reW9  访问密码 7053
  • API介绍

org.suren.autotest.web.framework.core.ui.Text 文本框或者其他需要输入值的元素org.suren.autotest.web.framework.core.ui.Button 按钮org.suren.autotest.web.framework.core.ui.Selector 下拉列表org.suren.autotest.web.framework.core.ui.FileUpload 文件上传按钮org.suren.autotest.web.framework.core.ui.CheckBoxGroup 复选框组org.suren.autotest.web.framework.page.Page 是所有页面类的根org.suren.autotest.web.framework.settings.SettingUtil 入口类
  • 骨架

本框架支持使用骨架(archetype)来创建Maven工程。更多信息请查看《Maven骨架archetype》中介绍的如何在Eclipse中添加骨架。要使用本站提供的Maven私服的话,需要根据《开源项目》中的提示来进行配置settings.xml。http://maven.surenpi.com/nexus/content/groups/public/archetype-catalog.xml[codesyntax lang="xml"]
<mirror><id>mirror.maven.surenpi.com</id><mirrorOf>maven.surenpi.com</mirrorOf><url>http://maven.surenpi.com/nexus/content/repositories/public/</url></mirror><mirror><id>nexus-gboat</id> <mirrorOf>external:*,!mirror.maven.surenpi.com</mirrorOf> <url>http://maven.gboat.cn/nexus/content/groups/public/</url> </mirror>
[/codesyntax]
  • Eclipse插件

在线安装地址http://plugin.surenpi.com/autotest如果您不清楚如何在Eclipse中安装或者更新插件,请查阅《Eclipse插件使用篇》。
  • 代码托管

开源中国 https://git.oschina.net/surenpi/autotest.web.frameworkGithub https://github.com/LinuxSuRen/autotest.web.framework
  • 现存问题

2016.9.23定位元素需要很多时间不支持条件判断(title、元素值)根据判断来决定自流程身份证、手机号、邮件等格式数据的动态生成
  • 更新日志

2016.7.27增加了选择iframe中元素的功能增加了根据元素value查找的功能增加了单选按钮组件解决了浏览器引擎总是无法退出的问题
  • 备注

由于本框架还处于内测阶段,如有感兴趣的童鞋可以留言交流(QQ群:52492046)!对本框架感兴趣的童鞋加入到框架的开源行动中!

查看原文:http://surenpi.com/2016/07/18/autotest_web_framework_base_selenium/
0 0
原创粉丝点击