3

このコードはすべて申し訳ありませんが、問題の原因がわからないので、ここで説明します。

JUnitで機能テストを実行するようにgebプラグインを構成しました。だから私は私の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
   }
}

そして、confフォルダーにGebConfig.groovyがあります。

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() }
  }
}

ログインの機能テストがあります:

class LoginTests extends GebReportingTest {


    @Test
    void login() {
        to LoginPage
        at LoginPage

        username = "SERGIO"
        password = "SERGIO"

        loginButton.click()

        assert at(IndexPage)

        link.click()

    }

}

そしてこれは私の2ページです:

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') } 
    }

}

何らかの理由で、私の機能テストは2回実行され、これをどのように開始してもかまいません。

grails test-app :functional

grails test-app -functional
4

2 に答える 2

3

GebプラグインはGrails2.3.xと完全には互換性がないようです。何らかの理由で、Gebプラグイン0.9.2にアップグレードした後、テストが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

これが、機能テストが2回実行される理由です。

これが、Geb 0.9.2/0.9.3バージョンで問題を回避した方法です。

grails test-app functional:spock

Gebバージョン0.9.1はテストを2回実行しなかったようです。

違いはこのコミットによって引き起こされているようです: https ://github.com/geb/geb/commit/9c71e820

また、Grails 2.3.x/2.4.xにSpockプラグインをインストールしてはならないことにも注意してください。

于 2014-07-22T06:34:25.780 に答える
0

こんにちはRuby上のSeleniumWebDriverはそれほど多くありませんが、Firefoxを2回起動しているようです。そのため、テストは2つのインスタンスで実行されます。

于 2013-01-24T14:49:43.057 に答える