开发者

Selenium - running a test suite of test suites?

I'm 开发者_StackOverflow社区running an HTML test suite as such:

java -jar /var/lib/selenium/selenium-server.jar -browserSessionReuse -htmlSuite *firefox http://$HOST ./test/selenium/html/TestSuite.html ./target/selenium/html/TestSuiteResults.html

Is there a way I can run all test suites in a directory, or create a test suite of test suites?


I'm very new to Selenium and really only Selenium2. I'm using "TestNG" as my test framework, and it does support suites and suites of suites using an xml file that specifies which tests carrying a particular annotation are part of the suite.

If running suites of suites is what you are looking for, and you are using Java exclusively (TestNG does not, as I understand it, support anything other than Java), then you may find what you're looking for.


I created a grails script to create a super-testsuite automatically. Needing to modify test suites is one more step in adding a test, and each level of barrier increases the likelihood of developers refusing to write tests.

import groovy.io.FileType

includeTargets << grailsScript("Init")

target(main: "Auto-generates the TestSuite.html file needed for selenium based on selenium html tests in test/selenium/html/**") {
    File testSuiteOutputFile = new File("test/selenium/html/TestSuite.html")
    testSuiteOutputFile.delete()

    String testRows = buildTestRows()
    testSuiteOutputFile << 
"""
<?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>
  <meta content="text/html; charset=UTF-8" http-equiv="content-type" />
  <title>Test Suite</title>
</head>
<body>
<table id="suiteTable" cellpadding="1" cellspacing="1" border="1" class="selenium"><tbody>
<tr><td><b>Test Suite</b></td></tr>
$testRows
</tbody></table>
</body>
</html>
"""


}

private def buildTestRows() {
    String testRows = ""
    List<File> testFiles = getAllTestFilesInSeleniumDirectory()
    testFiles.each { file ->
        def relativePath = buildFilePathRelativeToTestSuite(file)
        println "Adding $relativePath to TestSuite"
        testRows += "<tr><td><a href='${relativePath}'>${file.name}</a></td></tr>"
        testRows += "<tr><td><a href='clearCache.html'>Clear Cache</a></td></tr>"
    }
    testRows
}

private List<File> getAllTestFilesInSeleniumDirectory() {
    File testsDirectory = new File("test/selenium/html")
    def files = []
    testsDirectory.eachFileRecurse(FileType.FILES) { files << it }
    files
}

private String buildFilePathRelativeToTestSuite(File file){
    File parentDirectory = new File("test/selenium/html")

    String relativePath = file.name
    file = file.parentFile
    while( file != parentDirectory ){
        relativePath = file.name + "/" + relativePath;
        file = file.parentFile
    }
    relativePath
}

setDefaultTarget(main)


Look at Selunit. It provides a Maven plugin to execute Selenese suites in batch and transforms reports to Junit format. The last is very usefull for integration of test execution into a CI server like Jenkins, which generates nice charts and notifies in case of test errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜