Selenium - 运行测试套件的测试套件?

发布于 2024-11-26 21:16:24 字数 279 浏览 0 评论 0原文

我正在运行一个 HTML 测试套件,如下所示:

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

有没有办法可以运行目录中的所有测试套件,或者创建测试套件的测试套件?

I'm 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

笑咖 2024-12-03 21:16:24

我对 Selenium 非常陌生,而且真的只知道 Selenium2。我使用“TestNG”作为我的测试框架,它确实支持使用 xml 文件的套件和套件套件,该 xml 文件指定哪些带有特定注释的测试是套件的一部分。

如果您正在寻找运行套件的套件,并且您专门使用 Java(据我所知,TestNG 不支持 Java 以外的任何内容),那么您可能会找到您正在寻找的东西。

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.

晚雾 2024-12-03 21:16:24

我创建了一个 grails 脚本来自动创建超级测试套件。需要修改测试套件是添加测试的又一步,每一级障碍都会增加开发人员拒绝编写测试的可能性。

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)

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)
霞映澄塘 2024-12-03 21:16:24

查看 Selunit。它提供了一个 Maven 插件来批量执行 Selenese 套件并将报告转换为 Junit 格式。最后一个对于将测试执行集成到像 Jenkins 这样的 CI 服务器中非常有用,它会生成漂亮的图表并在出现测试错误时发出通知。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文