paul
paul

Reputation: 4487

Invoke browser in Geb is not working

Using Groovy, TestNG, Geb, I am trying to write setup() and teardown() methods. To test that, I have tried this:

package Rough


import geb.Browser
import geb.spock.GebSpec
import org.openqa.selenium.firefox.FirefoxDriver
import org.testng.annotations.Test;

@Test //TestNG
class InvokeBrowserTest extends GebSpec {


    //@Test
    def setup() {
       // browser.driver.javascriptEnabled = false
        browser = new Browser(driver: new FirefoxDriver())

    }

   /* def cleanup() {
        CachingDriverFactory.clearCache()
    }
*/
    def "can access The Book of Geb via homepage"() {
        when:
        to GebHomePage

        and:
        highlights.jQueryLikeApi.click()

        then:
        sectionTitles == ["Navigating Content", "Form Control Shortcuts"]
        highlights.jQueryLikeApi.selected
    }
}

Error

FAILED: 
groovy.lang.MissingFieldException: No such field: $spock_sharedField__browser for class: org.codehaus.groovy.runtime.NullObject
    at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:2823)
    at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:3759)
    at org.codehaus.groovy.runtime.InvokerHelper.getAttribute(InvokerHelper.java:145)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getField(ScriptBytecodeAdapter.java:306)
    at geb.spock.GebSpec.get_browser(GebSpec.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty.java:76)
    at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:85)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
    at geb.spock.GebSpec.getBrowser(GebSpec.groovy:42)
    at geb.spock.GebSpec.propertyMissing(GebSpec.groovy:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaClassImpl.invokeMissingProperty(MetaClassImpl.java:880)
    at groovy.lang.MetaClassImpl$12.getProperty(MetaClassImpl.java:2026)
    at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:85)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
    at Rough.InvokeBrowser.$spock_feature_1_0(InvokeBrowserTest.groovy:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
    at org.testng.TestRunner.privateRun(TestRunner.java:782)
    at org.testng.TestRunner.run(TestRunner.java:632)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
    at org.testng.SuiteRunner.run(SuiteRunner.java:268)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.run(TestNG.java:1064)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)

Upvotes: 0

Views: 936

Answers (2)

Optimworks
Optimworks

Reputation: 2547

In Geb, we have to add a file called "GebConfig.groovy" under resources folder as Geb automatically search for this file under resources folder

GebConfig.groovy file is where we do following: 1. Instantiate browser 2. Set up presets for browser timeouts

Browser Instantiation as follows:

def browserDriver = new ChromeDriver(capabilities)
browserDriver.manage().window().maximize()

Upvotes: 1

erdi
erdi

Reputation: 6954

You're mixing TestNG (org.testng.annotations.Test) with Spock (geb.spock.GebSpec). Given that they are both unit test frameworks you should use one or the other.

Upvotes: 0

Related Questions