Fitnesse + Xebium环境搭建
1.在搭建Fitnesse + Xebium环境之前先将selenium基础环境搭建完成并调试成功
参照:http://www.cnblogs.com/moonpool/p/5480724.html
2.把Xebium集成到Fitnesse中
a. 搭建Fitnesse环境
参照:http://www.cnblogs.com/moonpool/p/5765307.html
b.下载Xebium
下载地址:http://xebia.github.io/Xebium/
c. 导入eclipse,如下图,Import->Maven->Existing Maven Projects方式导入Xebium项目
d.将xebium项目中src/main/java下文件拷贝到Fitnesse项目的src下面
在eclipse中刷新Fitnesse项目
e. 导入依赖包,在Fitnesse中新建一个libs目录(和lib目录平级),在libs中放入下面的jar包,并导入Fitnesse项目,下面的jar包都可以在selenium-java-2.53.0.zip和Xibum项目中找到。
下面的jar包也可以在http://pan.baidu.com/s/1kUZajOV直接下载
f. 配置build.gradle文件,添加下面红色字体部分内容
1 /* Plan: 2 - Create multi-module repo: 3 - fit (deps: common) 4 - slim (deps: common, networking) 5 - common 6 - networking 7 - ant 8 - fitnesse, the wiki server 9 - Move file creation to plugin 10 */ 11 12 buildscript { 13 repositories { 14 mavenCentral() 15 } 16 dependencies { 17 classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.1.9' 18 } 19 } 20 21 plugins { 22 id 'java' 23 id "maven-publish" 24 id "com.jfrog.bintray" version "1.6" 25 } 26 27 apply plugin: "info.solidsoft.pitest" 28 29 30 version = new Date().format('yyyyMMdd') 31 32 println "Building FitNesse v${project.version}..." 33 34 repositories { 35 mavenCentral() 36 } 37 38 configurations { 39 lesscss 40 optional 41 compile { 42 transitive = false 43 extendsFrom optional 44 } 45 runtime { 46 transitive = false 47 } 48 } 49 50 sourceSets { 51 main { 52 java.srcDir 'src' 53 resources.srcDir 'src' 54 output.resourcesDir output.classesDir 55 } 56 test { 57 java.srcDir 'test' 58 } 59 } 60 61 sourceCompatibility = '1.7' 62 targetCompatibility = '1.7' 63 64 dependencies { 65 compile "org.htmlparser:htmlparser:2.1" 66 compile "org.htmlparser:htmllexer:2.1" 67 compile "org.apache.velocity:velocity:1.7" 68 compile "commons-lang:commons-lang:2.6" 69 compile "commons-collections:commons-collections:3.2.2" 70 compile "org.json:json:20151123" 71 compile "com.googlecode.java-diff-utils:diffutils:1.3.0" 72 optional "org.apache.ant:ant:1.9.6" 73 optional "junit:junit:4.12" 74 75 testCompile "junit:junit:4.12" 76 testCompile "org.mockito:mockito-core:1.10.19" 77 testCompile "org.hamcrest:hamcrest-all:1.3" 78 testCompile "net.javacrumbs.json-unit:json-unit:1.1.6" 79 80 /*compileOnly files('libs/joda-time-2.3.jar')*/ 81 /*compile fileTree(dir: 'dependencies/compile/archive', include: '*.jar', exclude: 'management.jar')*/ 82 /*compile(files('dependencies/compile/archive/management.jar')){ notPackaged = true } // Excludes it from all publications*/ 83 84 compile fileTree(dir: 'libs', include: '*.jar') 85 86 lesscss "org.mozilla:rhino:1.7.7.1" 87 } 88 89 task fitNesseVersion { 90 def versionFile = new File("${sourceSets.main.output.resourcesDir}/META-INF/FitNesseVersion.txt") 91 versionFile.parentFile.mkdirs() 92 versionFile.text="v${version}" 93 } 94 95 task compileBootstrap(type: LessCompiler) { 96 inputDir file('src/fitnesse/resources/bootstrap/less') 97 mainLessFile = 'fitnesse-bootstrap.less' 98 cssFile file("${sourceSets.main.output.resourcesDir}/fitnesse/resources/bootstrap/css/fitnesse-bootstrap.css") 99 classpath configurations.lesscss 100 } 101 102 task createUpdateLists(type: WikiFileListBuilderTask) { 103 outputDirectory = "${sourceSets.main.output.resourcesDir}/Resources" 104 doNotReplaceFiles = [ 105 "FitNesseRoot/FrontPage/content.txt", 106 "FitNesseRoot/FrontPage/properties.xml", 107 "FitNesseRoot/PageHeader/content.txt", 108 "FitNesseRoot/PageHeader/properties.xml", 109 "FitNesseRoot/PageFooter/content.txt", 110 "FitNesseRoot/PageFooter/properties.xml", 111 "FitNesseRoot/PageFooter/properties.xml", 112 "FitNesseRoot/TemplateLibrary/content.txt", 113 "FitNesseRoot/TemplateLibrary/properties.xml", 114 "FitNesseRoot/TemplateLibrary/StaticPage/content.txt", 115 "FitNesseRoot/TemplateLibrary/StaticPage/properties.xml", 116 "FitNesseRoot/TemplateLibrary/SuitePage/content.txt", 117 "FitNesseRoot/TemplateLibrary/SuitePage/properties.xml", 118 "FitNesseRoot/TemplateLibrary/TestPage/content.txt", 119 "FitNesseRoot/TemplateLibrary/TestPage/properties.xml" ] 120 mainDirectories = [ 121 "FitNesseRoot/FitNesse", 122 "FitNesseRoot/FrontPage", 123 "FitNesseRoot/PageFooter", 124 "FitNesseRoot/PageHeader", 125 "FitNesseRoot/TemplateLibrary" ] 126 } 127 128 processResources.dependsOn "fitNesseVersion", "compileBootstrap", "createUpdateLists" 129 130 task copyRuntimeLibs(type: Copy) { 131 into "lib" 132 from configurations.runtime 133 } 134 135 test { 136 dependsOn copyRuntimeLibs 137 maxParallelForks 1 138 } 139 140 pitest { 141 targetClasses = ['fit.*', 'fitnesse.*'] 142 pitestVersion = "1.1.10" 143 threads = 1 // We can not deal with parallel execution yet 144 outputFormats = ['XML', 'HTML'] 145 } 146 147 task run(type: JavaExec) { 148 dependsOn classes, copyRuntimeLibs 149 classpath = sourceSets.main.runtimeClasspath 150 main "fitnesseMain.FitNesseMain" 151 args "-p", "8001", "-e", "0" 152 } 153 154 jar { 155 dependsOn createUpdateLists 156 into('Resources') { 157 from('.') { 158 include 'FitNesseRoot/FitNesse/**/content.txt' 159 include 'FitNesseRoot/FitNesse/**/properties.xml' 160 include 'FitNesseRoot/FrontPage/**/content.txt' 161 include 'FitNesseRoot/FrontPage/**/properties.xml' 162 include 'FitNesseRoot/PageFooter/**/content.txt' 163 include 'FitNesseRoot/PageFooter/**/properties.xml' 164 include 'FitNesseRoot/PageHeader/**/content.txt' 165 include 'FitNesseRoot/PageHeader/**/properties.xml' 166 include 'FitNesseRoot/TemplateLibrary/**/content.txt' 167 include 'FitNesseRoot/TemplateLibrary/**/properties.xml' 168 } 169 } 170 manifest { 171 attributes("Main-Class": "fitnesseMain.FitNesseMain", 172 "Implementation-Version": version) 173 } 174 } 175 176 task standaloneJar(type: Jar, dependsOn: jar) { 177 baseName = 'fitnesse' 178 classifier = 'standalone' 179 from { 180 (configurations.compile - configurations.optional).collect { zipTree(it) } 181 } { 182 exclude 'META-INF/**' 183 } 184 from jar.outputs.files.collect { 185 zipTree(it) 186 } 187 manifest { 188 attributes("Main-Class": "fitnesseMain.FitNesseMain", 189 "Implementation-Version": version) 190 } 191 } 192 193 task acceptanceTest(type: JavaExec) { 194 mustRunAfter test 195 onlyIf { dependsOnTaskDidWork() } 196 classpath = standaloneJar.outputs.files 197 main "fitnesseMain.FitNesseMain" 198 args "-o", "-c", "FitNesse.SuiteAcceptanceTests?suite&format=text" 199 } 200 201 check.dependsOn acceptanceTest 202 203 task javadocJar(type: Jar) { 204 mustRunAfter check 205 classifier = 'javadoc' 206 from javadoc 207 } 208 209 task sourcesJar(type: Jar) { 210 mustRunAfter check 211 classifier = 'sources' 212 from sourceSets.main.allSource 213 } 214 215 clean{ 216 delete "lib" 217 } 218 219 publishing { 220 publications { 221 FitNesseRelease(MavenPublication) { 222 from components.java 223 artifact sourcesJar 224 artifact javadocJar 225 artifact standaloneJar 226 groupId 'org.fitnesse' 227 artifactId 'fitnesse' 228 pom.withXml { 229 asNode().get('version') + { url('http://fitnesse.org') } 230 asNode().appendNode('description', 'The fully integrated standalone wiki, and acceptance testing framework.') 231 asNode().append(pomLicenses()) 232 asNode().append(pomScm()) 233 asNode().append(pomDevelopers()) 234 235 // Clean up scope entries added by the pom generator: 236 asNode().dependencies.'*'.findAll() { 237 if (it.scope.text() == 'runtime') { 238 it.remove(it.scope) 239 } 240 } 241 } 242 } 243 } 244 } 245 246 bintray { 247 user = System.getenv("BINTRAY_USER") ?: 'Define your Bintray user name in BINTRAY_USER' 248 key = System.getenv("BINTRAY_API_KEY") ?: 'Define your Bintray BINTRAY_API_KEY' 249 publications = ['FitNesseRelease'] 250 publish = true 251 pkg { 252 repo = System.getenv("BINTRAY_API_KEY") ?: 'edge' 253 name = 'fitnesse' 254 userOrg = 'fitnesse' 255 licenses = ['CPL-1.0'] 256 websiteUrl = 'http://fitnesse.org' 257 vcsUrl = 'https://github.com/unclebob/fitnesse.git' 258 publicDownloadNumbers = true 259 githubRepo = 'unclebob/fitnesse' 260 version { 261 name = project.version 262 desc = "FitNesse release ${project.version}" 263 vcsTag = project.version 264 gpg { 265 sign = true 266 } 267 } 268 } 269 } 270 271 wrapper { 272 gradleVersion = '2.13' 273 } 274 275 def pomLicenses() { 276 new NodeBuilder().licenses { 277 license { 278 name 'Common Public License version 1.0' 279 url 'http://www.opensource.org/licenses/cpl1.0' 280 distribution 'repo' 281 } 282 } 283 } 284 285 def pomScm() { 286 new NodeBuilder().scm { 287 connection 'scm:git:git://github.com/unclebob/fitnesse.git' 288 developerConnection 'scm:git:git@github.com:unclebob/fitnesse.git' 289 url 'scm:git:http://github.com/unclebob/fitnesse' 290 } 291 } 292 293 def pomDevelopers() { 294 new NodeBuilder().developers { 295 developer { 296 id 'unclebob' 297 name 'Robert C. Martin' 298 email 'unclebob@cleancoder.com' 299 } 300 } 301 }
g. 重新启动Fitnesse,通过命令行进入fitnesse-master并使用下面的命令运行:
.\gradlew run
3. 在Fitnesse中新建一个test输入下面内容
1 !***< Hidden 2 !*< Classpath setup 3 !define TEST_SYSTEM {slim} 4 !path libs/*.jar 5 *! 6 7 8 9 10 '''此处导入后台代码包名''' 11 !|import | 12 |com.xebia.incubator.xebium| 13 14 15 *! 16 17 18 '''测试脚本''' 19 !| script |selenium driver fixture | 20 |start browser|firefox|on url |http://www.baidu.com/ | 21 |ensure |do |open |on|/ | 22 |ensure |do |type |on|!-//*[@id="kw"]-! |with |Xebium | 23 |ensure |do |click |on|!-//*[@id="su"-!] | 24 |ensure |do |waitForElementPresent|on|!-link=Get your webtests in FitNesse with Xebium | Xebia Blog-!| 25 |stop browser|
测试结果
本文来自博客园,作者:月色深潭,交流群:733423266,转载请注明原文链接:https://www.cnblogs.com/moonpool/p/5769248.html