Geb Firefox驱动程序:为什么我的测试运行两次? [英] Geb Firefox Driver: why my test runs twice?

查看:136
本文介绍了Geb Firefox驱动程序:为什么我的测试运行两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,所有这些代码,但我不知道是什么使我的问题,所以在这里。



我配置了geb插件运行功能用JUnit进行测试。所以我在我的 buildConfig.groovy 中:

  def seleniumVersion =2.29.0
def gebVersion =0.7.0

dependencies {
//指定依赖关系在'build','compile','runtime','test'或'provided'范围例如。
$ b $ //运行时mysql:mysql-connector-java:5.1.5'

provided('com.oracle:oracle:11.1.0.7.0')
provided('com.oracle:i18n:10.2.0.5')


test(org.seleniumhq.selenium:selenium-chrome-driver:$ seleniumVersion){
export = false

test(org.seleniumhq.selenium:selenium-firefox-driver:$ seleniumVersion){
不包括commons-io
export = false

test(org.seleniumhq.selenium:selenium-ie-driver:$ seleniumVersion){
export = false
}

test(org.seleniumhq.selenium:selenium-support:$ seleniumVersion){
export = false
}
test(org.seleniumhq.selenium:selenium-remote-driver:$ seleniumVersion){
export = false
}

test(org.codehaus.geb:geb-junit4:$ gebVersion){
export = false
}

}

plugins {
build(:tomcat:$ grai lsVersion){
export = false
不包括'svn'
}
compile(:hibernate:$ grailsVersion){
export = false
不包括'svn'
}

build(:release:2.0.0){
不包括'commons-io','http-builder'
export =false


compile(:spring-security-core:1.2.7.3){excludes'svn'}
compile(:spring-security-ldap: (:remote-control:1.3){
export = false
}

test :$ gebVersion){
export = false
}
}



<

  driver = {$ b 

GebConfig.groovy $ b // def driver = new HtmlUnitDriver()
//driver.javascriptEnabled = true
// driver
def driver = new FirefoxDriver()
driver
}

environments {
//作为grails -Dgeb.env = chrome test-app运行
//请参阅:http://code.google.com/p/ selenium / wiki / ChromeDriver
chrome {
driver = {new ChromeDriver()}
}

//作为grails -Dgeb.env = firefox test- app
//请参阅:http://code.google.com/p/selenium/wiki/FirefoxDriver
firefox {
driver = {new FirefoxDriver()}
}



$ b $ p
$ b

我有一个登录功能测试:

  class LoginTests extends GebReportingTest {

$ b @Test
void login(){
to LoginPage
at LoginPage

username =SERGIO
password =SERGIO

loginButton.click()

(IndexPage)

link.click()

}

}

这是我的两页:

  class LoginPage extends Page {

static url =login / auth

static at = {
title ==〜/ Efetuar登录/
}

static content = {
loginForm {$(form,id:loginForm)}
username {$(input,type:text, id:username)}
password {$(input,type:password,id:password)}
loginButton {$(input,type:submit, id:submit)}
}

}

class IndexPage extends Page {

static at = {
title ==〜/ Security Service Index View /
}

static content = {
description {$('h1')}
link {$('a ')}
}

}

功能测试运行两次,无论如何开始这个:

  grails测试应用程序:功能

grails test-app -functional


解决方案

Geb插件与Grails 2.3.x不完全兼容。由于某些原因,测试在升级到Geb插件0.9.2后得到两次执行。



我相信这个问题与 https://jira.grails.org/browse/GRAILS-10552 和作为 https://jira.grails.org/browse/GRAILS-6352



<在Grails 2.3.x +中,GrailsS​​pecTestType负责Junit和Spock测试:
https://github.com/grails/grails-core/blob/bce298f0/grails- test / src / main / groovy / org / codehaus / groovy / grails / test / spock / GrailsS​​pecTestType.groovy#L33


它看起来像Geb插件将不推荐使用的JUnit4GrailsTestType添加到执行中:
https://github.com/geb/geb/blob/584738cb/integration/geb-grails/scripts/_Events.groovy#L60 -L67



这就是为什么功能测试会执行两次。



这就是我得到的Geb 0.9.2 / 0.9.3版本的问题。

  grails测试应用程序功能:spock 

看起来Geb版本0.9.1没有执行两次测试。



差异似乎是由这个提交引起的:
https:// github.com/geb/geb/commit/9c71e820



您还应该知道,您不应该在Grails 2.3.x中安装Spock插件/2.4.x。


Sorry for all this code, but I don't have a clue what's making my issue, so here it goes.

I configured the geb plugin to run functional tests with JUnit. So I have in my buildConfig.groovy:

def seleniumVersion = "2.29.0"
def gebVersion = "0.7.0"

dependencies {
    // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

    // runtime 'mysql:mysql-connector-java:5.1.5'

    provided('com.oracle:oracle:11.1.0.7.0')
    provided('com.oracle:i18n:10.2.0.5')


    test ("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion") {
        export = false
    }
    test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"){ 
        excludes "commons-io"
        export = false
    }
    test ("org.seleniumhq.selenium:selenium-ie-driver:$seleniumVersion") {
        export = false
    }

    test ("org.seleniumhq.selenium:selenium-support:$seleniumVersion") {
        export = false
    }
    test ("org.seleniumhq.selenium:selenium-remote-driver:$seleniumVersion") {
        export = false
    } 

    test ("org.codehaus.geb:geb-junit4:$gebVersion") {
        export = false
    }

}

plugins {
  build(":tomcat:$grailsVersion") {
  export = false
  excludes 'svn'
  }
  compile (":hibernate:$grailsVersion") {
  export = false
  excludes 'svn'
  }

  build (":release:2.0.0") {
  excludes 'commons-io','http-builder'
  export = false
  }

   compile(":spring-security-core:1.2.7.3") { excludes 'svn' }
   compile(":spring-security-ldap:1.0.6")

   compile (":remote-control:1.3") {
  export = false
   }

   test(":geb:$gebVersion") {
     export = false
   }
}

And I have a GebConfig.groovy in my conf folder:

driver = {
//def driver = new HtmlUnitDriver()
//driver.javascriptEnabled = true
//driver
def driver = new FirefoxDriver()
driver
} 

environments {
   // run as "grails -Dgeb.env=chrome test-app"
   // See: http://code.google.com/p/selenium/wiki/ChromeDriver
   chrome {
     driver = { new ChromeDriver() }
   }

   // run as "grails -Dgeb.env=firefox test-app"
   // See: http://code.google.com/p/selenium/wiki/FirefoxDriver
   firefox {
    driver = { new FirefoxDriver() }
  }
}

I have a functional test for the login:

class LoginTests extends GebReportingTest {


    @Test
    void login() {
        to LoginPage
        at LoginPage

        username = "SERGIO"
        password = "SERGIO"

        loginButton.click()

        assert at(IndexPage)

        link.click()

    }

}

And this are my two pages:

class LoginPage extends Page {

    static url = "login/auth"

    static at = {
        title ==~ /Efetuar Login/
    }

    static content = {
        loginForm { $("form", id: "loginForm") }
        username { $("input", type:"text", id:"username") }
        password { $("input", type:"password", id:"password") }
        loginButton{ $("input", type:"submit", id:"submit") }
    }

}

class IndexPage extends Page {

    static at = {
        title ==~ /Security Service Index View/
    }

    static content = {
        description { $('h1') }
        link { $('a') } 
    }

}

For some reason my functional test run twice and don't matter how I start this:

grails test-app :functional

grails test-app -functional

解决方案

It looks like the Geb plugin isn't fully compatible with Grails 2.3.x . For some reason tests get executed twice after upgrading to Geb plugin 0.9.2 .

I believe this problem is related to https://jira.grails.org/browse/GRAILS-10552 and changes made as part of https://jira.grails.org/browse/GRAILS-6352 .

In Grails 2.3.x+, the GrailsSpecTestType takes care of both Junit and Spock tests: https://github.com/grails/grails-core/blob/bce298f0/grails-test/src/main/groovy/org/codehaus/groovy/grails/test/spock/GrailsSpecTestType.groovy#L33

It looks like the Geb plugin is adding the deprecated JUnit4GrailsTestType to execution: https://github.com/geb/geb/blob/584738cb/integration/geb-grails/scripts/_Events.groovy#L60-L67

This is why functional tests get executed twice.

This is how I got around the problem in Geb 0.9.2 / 0.9.3 versions.

grails test-app functional:spock

It looks like Geb version 0.9.1 didn't execute the tests twice.

The difference seems to be caused by this commit: https://github.com/geb/geb/commit/9c71e820

You should also be aware that you shouldn't have the Spock plugin installed in Grails 2.3.x/2.4.x .

这篇关于Geb Firefox驱动程序:为什么我的测试运行两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆