运行测试时出现groovy.lang.MissingMethodException

时间:2019-06-27 20:20:24

标签: groovy geb

当我尝试运行.groovy测试时,控制台将反踢此错误:

  

捕获:groovy.lang.MissingMethodException:方法的无签名:GebConfig.waiting()适用于参数类型:(GebConfig $ _run_closure1)值:[GebConfig $ _run_closure1 @ 659499f1]   可能的解决方案:wait(),wait(long),toString(),toString(),wait(long,int),main([Ljava.lang.String;)   groovy.lang.MissingMethodException:方法的无签名:GebConfig.waiting()适用于参数类型:(GebConfig $ _run_closure1)值:[GebConfig $ _run_closure1 @ 659499f1]   可能的解决方案:wait(),wait(long),toString(),toString(),wait(long,int),main([Ljava.lang.String;)       在GebConfig.run(GebConfig.groovy:28)

     

以退出代码1完成的过程

我的GebConfig.groovy设置如下:


    import geb.driver.BrowserStackDriverFactory
    import org.openqa.selenium.WebDriver
    import org.openqa.selenium.chrome.ChromeDriver
    import org.openqa.selenium.firefox.FirefoxDriver
    import org.openqa.selenium.remote.DesiredCapabilities
    import org.openqa.selenium.remote.RemoteWebDriver


    baseUrl = "https://ourtestingurl.com/"

    /*driver = 'chrome'
     environments {
     'chrome' {
     def chromeDriver = new File('src/test/resources/chromedriver.exe')
     System.setProperty('webdriver.chrome.driver', chromeDriver.absolutePath)
     driver = { new ChromeDriver() }
     driver.manage().window().maximize()
     }
     'firefox' {
     def FirefoxDriver = new File('src/test/resources/geckodriver.exe')
     System.setProperty('webdriver.gecko.driver', geckoDriver.absolutePath)
     driver = { new FirefoxDriver() }
     }
     }
     */
    reportsDir = new File("target/geb-reports1")

    waiting {
        timeout = 50
        retryInterval = 0.5
        slow { timeout = 52 }
        reallyslow { timeout = 80}
    }

    String USERNAME = "username";
    String AUTOMATE_KEY = "niceTry";
    String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";
    driver = {
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("os", "Windows");
        caps.setCapability("os_version", "10");
        caps.setCapability("browser", "Chrome");
        caps.setCapability("browser_version", "75.0");
        caps.setCapability("browserstack.local", "false");
        caps.setCapability("browserstack.debug", "true");
        caps.setCapability("browserstack.selenium_version", "3.14.0");
        WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
    }

我完全不知所措,整整一整天都在努力解决这个问题。

2 个答案:

答案 0 :(得分:0)

最近,在将现有项目混合到groovy和Java中的intellij中时,我遇到了类似的问题。 Intellij只识别Java源文件夹,因此我不得不修改项目以使用src / main / groovy文件夹。您是否正在使用任何想法查看项目设置?

答案 1 :(得分:0)

我没有机会检查这是否是原因,但是可以在这里找到适当的等待块语法-> https://gebish.org/manual/current/#waiting-presets

因此,您的等待块应如下所示->

waiting {
   timeout = 50
   retryInterval = 0.5
   presets {
     slow { timeout = 52 }
     reallyslow { timeout = 80}
   }
 }