【问题标题】:Selenium - running a test suite of test suites?Selenium - 运行测试套件的测试套件?
【发布时间】:2011-10-15 11:33:37
【问题描述】:

我正在运行这样的 HTML 测试套件:

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

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

【问题讨论】:

    标签: selenium jenkins selenium-webdriver selenium-ide test-suite


    【解决方案1】:

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

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

    【讨论】:

    • 不涉及语言。我正在直接运行 HTML 文件。
    【解决方案2】:

    我创建了一个 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)
    

    【讨论】:

    • 只是为了澄清这里发生了什么,因为我面临同样的情况。这只是创建一个带有嵌套套件的套件吗?
    • 是的。忽略 clearCache.html,这是为每个单独的 .html 测试文件创建一行,可以作为单个 testSuite 文件加载。进一步进行硒测试后,我发现与 cucumber 和 rspec 配对时,ruby 绑定非常好。 HTML 测试有时会崩溃,而 cucumber + rspec 对我来说效果很好。使用“chromedriver”是救命稻草,它确实是 UI 测试移动 Web 应用程序的唯一方法。
    【解决方案3】:

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

    【讨论】:

    • 我不会使用 maven,也不会。
    猜你喜欢
    • 1970-01-01
    • 2019-08-22
    • 1970-01-01
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多