Regarding how the test results are being saved:
A) Is there any way to save each Test class results in a separate report?
B) If I have two different "test" methods that are in the same test class.
Is there any way to save the results of each method in a separate report?
C) Is there any way to see the results when all the steps inside the
"webtest" tasks finishes? (Just in case you are iterating and running
multiple webtests, see below example)
The *advantages* of this are:
1) You are able to analyse the reports quickly, saving time and being able
to take a decision.
2) It 's easier to analyse the reports because they are not merged with
other test results. (You also save time, you don't need to sort by test
name, etc)
3) If you are executing more that 3 thousand tests, when you try to open the
html and sort it (by fail, for example) then your browser will probably not
respond.
public class SomeTest extends MyWebtestCase {
>
> def provider = new BrowseAllCountriesProvider()
>
> @Test(testName = "Test1", description = "Testing Soemthing")
> public void testSomething1() {
> testName = "Test1"
> provider.countries.each {Country country ->
> webtest("Some text") {
> config(haltonerror: "false", haltonfailure: "false", browser:
> 'ff3') {
> option name: "ThrowExceptionOnScriptError", value: "false"
> }
> steps
> }
>
> }
>
>
> @Test(testName = "Test1", description = "Testing Something")
> public void testSomething2() {
> testName = "Test2"
> provider.countries.each {Country country ->
> webtest("Some text") {
> config(haltonerror: "false", haltonfailure: "false", browser:
> 'ff3') {
> option name: "ThrowExceptionOnScriptError", value: "false"
> }
> steps
> }
>
> }
>
> }
>
We have spent 3 days trying to solve this, I we couldn't
we tried:
1) Defining *ownerProject ** non static*, so it has a new instance for each
test class (Problem (A)).
2) Running the AfterTestsWorks method when the method finishes, cleaning
the ant, and project variables. And then creating a new ant Builder before a
webtest task is executed. (Problem (B))
@AfterMethod
protected doAfterTestsWork() {
ant.project.executeTarget 'wt.after.testInWork'
this.ant = null
this.ownerProject = null
}
But this didn't worked. The first test method is being executed correctly
but when it's trying to execute the second one, the following error is being
shown:
*First Test*
wt.defineTasks:
wt.webtestMonitor:
wt.htmlReports.init:
wt.defineTasks:
wt.webtestMonitor:
wt.htmlReports.init:
wt.htmlReports:
wt.openResultFile:
===============================================
*Second Test*
wt.defineTasks:
wt.webtestMonitor:
wt.createReportsFolder:
wt.htmlReports.init:
wt.htmlReports:
wt.openResultFile:
[echo] Opening result file
/home/qa/Desktop/results/hernan/qa1/today/webtest-results/test/olx/site/BrowseAllCountriesTest/Test1/index.html
with firefox
: java.util.concurrent.RejectedExecutionException
at
org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:116)
at org.apache.tools.ant.Task.perform(Task.java:348)
at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:212)
at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:147)
at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:162)
at
com.canoo.webtest.groovy.WebTestBuilder.doInvokeMethod(WebTestBuilder.java:54)
at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64)
at
org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:129)
*Any idea why this is happening? I also tried overriding the tearDown()
method but I have the same problem.*
Thanks in advance for your help. And sorry for long email.
class OlxWebtestCase extends GroovyTestCase {
>
> public ownerProject
> WebTestBuilder ant
> String testName
>
>
> Object getAnt() {
> if (!th...@ant)
> createAntBuilder()
> return th...@ant
> }
>
> void createAntBuilder() {
> ant = new WebTestBuilder(getOwnerProject())
> }
>
> /**
> * Gets the owner project where the WebTest tasks are defined. If this
> project hasn't been set previously from
> * outside, then the test case is probably run from within the IDE and
> not using webtest.xml or the maven plugin (coming).
> * In this case we create a new project an initialize it here and we
> register a shutdownHook for the JVM where the
> * test results are formatted.
> */
> public Project getOwnerProject() {
> if (!th...@ownerproject) {
> def antBuilder = new AntBuilder()
>
>
> WebtestEmbeddingUtil.copyWebTestResources(getPathFor("webtest-resources"))
>
> antBuilder.path(id: "wt.defineTasks.classpath.id")
> {
> pathelement(path: '${java.class.path}')
> }
> antBuilder.property(name: "~wt.defineTasks.defineClasspath.skip",
> value: "true")
> //antBuilder.property(name: "wt.headless", value: "true")
> antBuilder.property(name: "wt.generateDtd.skip", value: "true")
> // antBuilder.property(name: "wt.parallel.nbWorkers", value: "20")
> antBuilder.property(name: "wt.generateDefinitions.skip", value:
> "true")
> antBuilder.property(name: "wt.defineMacros.skip", value: "true")
> antBuilder.property(name: "wt.countWebtestResults.skip", value:
> "false")
> antBuilder.property(name: "wt.junitLikeReports.skip", value: "true")
> antBuilder.property(name: "wt.config.haltonerror", value: "false")
> antBuilder.property(name: "wt.config.haltonfailure", value: "false")
> antBuilder.property(name: "wt.config.browser", value: "ff3")
> antBuilder.property(name: "wt.config.resultpath", value:
> getPathFor("webtest-results"))
> def tmpWebtestXml = new File(getPathFor("webtest-resources"),
> "webtest.xml")
>
> antBuilder.'import'(file: tmpWebtestXml) // sets properties into
> current ant project
> antBuilder.project.executeTarget 'wt.before.testInWork'
>
>
> this.ownerProject = antBuilder.project
> }
> th...@ownerproject
> }
>
> /**
> * Called by a shutdown hook to perform actions that have to be performed
> once all
> * tests have been executed (ie generation of HTML reports)
> */
> @AfterMethod
> protected doAfterTestsWork() {
> ant.project.executeTarget 'wt.after.testInWork'
> this.ant = null
> this.ownerProject = null
>
> }
>
>
> protected File getPathFor(String path) {
> String generalPath = Settings.getResultsPath()
> String testRelativePath = this.class.name.replace('.', File.separator)
> return new File(generalPath + File.separator + path + File.separator +
> testRelativePath + File.separator + testName)
> }
>
>
> void webtest(String name, Closure yield) {
> createAntBuilder()
> ant.webtest(name: name)
> {
> config()
> yield.delegate = ant
> yield()
> }
> }
>
>
> void config() {
> // default implementation does nothing
> }
>
>
> }
>
> class WebtestAntBuilderLocator implements org.xml.sax.Locator {
> String systemId
> String publicId
> int columnNumber = -1
> int lineNumber = -1
> }
>