标签: geb

如何在Geb模块中获取基本元素属性

鉴于HTML:fooLink

和页面对象

class FooPage extend geb.Page {
    static content = {
        foo = { Module FooModule, $('.foo') }
    }
}
Run Code Online (Sandbox Code Playgroud)

将@href元素从模块中取出的正确实现是什么?

class FooModule extends geb.module {
    static content = { 
        smartField = { doSomethingSmartWith(?.@href) }
    }
}
Run Code Online (Sandbox Code Playgroud)

我试过,这个,委托,基础,$和@,它们都没有用.

grails groovy module geb

1
推荐指数
1
解决办法
1372
查看次数

使用Geb进行测试之间的Mantain会话

我正在使用Geb测试我的应用程序,我想在测试之间保持会话,这样我就可以避免在每次测试中登录(这在浏览器中观看测试时很烦人).

有没有办法保持会议?

grails geb

1
推荐指数
1
解决办法
1564
查看次数

Geb - 如何查询页面请求参数

我使用Geb进行了Grails Cucumber测试.

如何获取为当前页面定义的请求参数?

例如,鉴于当前页面网址是 www.foo.com/list?sort=name&order=asc

如何测试sortorderparams 的值是什么?

grails geb

1
推荐指数
1
解决办法
1728
查看次数

如果断言在Geb测试中失败,如何保持浏览器窗口打开?

如果Geb测试失败,最好使用浏览器的开发人员工具检查页面.是否有可能以某种方式配置Geb,它会在失败时停止但是保持浏览器窗口打开?

selenium geb selenium-webdriver

1
推荐指数
1
解决办法
1172
查看次数

从Geb测试中调用GORM方法

在我的Grails应用程序中,我有一套Geb测试,其中我调用各种GORM方法来保存/检索数据.这工作正常,直到最近.但是现在,每当我尝试从Geb测试中调用GORM方法时,我都会收到以下错误:

类[com.example.MyDomainClass]上的方法在Grails应用程序之外使用.如果在测试的上下文中使用模拟API或正确引导Grails运行.

我知道在某些情况下你需要使用远程控制插件在Geb测试中使用GORM方法.但是,在我的情况下,我通过运行测试grails test-app functional,我没有配置任何JVM分叉Config.groovy.换句话说,测试应该在与正在测试的应用程序相同的JVM中运行,因此我应该能够在没有远程控制插件的情况下使用GORM方法.

我使用的是Grails 2.3.11和Geb 0.10.0.

grails geb

1
推荐指数
1
解决办法
355
查看次数

Geb选择器未选择

我注意到在某些情况下,geb选择器无法按预期工作。当我从开发人员控制台复制css selecor,css路径或xpath并将其用作geb中的选择器时,它们将无法工作。无论如何,在此示例中,我无法选择我想要的:

网站:https//money.cnn.com/data/fear-and-greed/

<div id="needleChart" style="background-image:url('//money.cnn.com/.element/img/5.0/data/feargreed/1.png');">
    <ul>
        <li>Fear & Greed Now: 72 (Greed)</li><li>Fear &amp; Greed Previous Close: 72 (Greed)</li>
        <li>Fear & Greed 1 Week Ago: 69 (Greed)</li><li>Fear &amp; Greed 1 Month Ago: 58 (Greed)</li>
        <li>Fear & Greed 1 Year Ago: 8 (Extreme Fear)</li>
   </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

现在,我想从第一个li-tag 获取文本,这是我的代码:

public class MoneyCnnFearAndGreed extends Page {
    static url = 'https://money.cnn.com/data/fear-and-greed'
    static content = {
        fearAndGreed { $("#needleChart").$("ul li")[0].text() }
    }
}

Browser.drive {
    to MoneyCnnFearAndGreed
    println fearAndGreed
} …
Run Code Online (Sandbox Code Playgroud)

groovy selenium web-scraping geb

1
推荐指数
1
解决办法
92
查看次数

如何与HtmlUnit共享MockMvc会话?

我正在使用Spring Test MVC HtmlUnit和Geb来为我的Spring MVC应用程序驱动功能测试.我想检查在交互过程中是否正确保存了一些会话变量.我尝试创建一个测试控制器来返回这些变量,但HtmlUnit并mvc.perform()使用不同的会话.有没有办法在它们之间使用单个共享会话?

司机设置:

MockMvc mvc = MockMvcBuilders.webAppContextSetup(ctx)
    .apply(SecurityMockMvcConfigurers.springSecurity())
    .build()

HtmlUnitDriver driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(mvc).javascriptEnabled(true).build()
Run Code Online (Sandbox Code Playgroud)

测试:

when:
    via ProtectedPage

then:
    // this uses session A
    at LoginPage

and:
    // this uses session B
    println mvc.perform(get('/test/sessionAttributes')).andReturn().response.contentAsString
Run Code Online (Sandbox Code Playgroud)

spring spring-mvc spring-test htmlunit geb

0
推荐指数
1
解决办法
878
查看次数

使用Geb/Spock记录失败测试时的自定义消息?

我正忙着在Geb/Spock中进行e2e测试,我想知道如何添加自定义消息.现在我只得到这样的堆栈跟踪:

geb.error.RequiredPageContentNotPresent: The required page content 'pages.patientConversation.PcModal -> contact: geb.navigator.EmptyNavigator' is not present
    at geb.content.TemplateDerivedPageContent.require(TemplateDerivedPageContent.groovy:60)
    at geb.content.PageContentTemplate.create_closure1(PageContentTemplate.groovy:63)
    at geb.content.PageContentTemplate.create_closure1(PageContentTemplate.groovy)
Run Code Online (Sandbox Code Playgroud)

等......

这是我测试的一个例子:

 def "allow for searching contacts"() {
    when:
    to LoginPage
    login(emailAddress, defaultPassword)
    then:
    at QuickBar
    when:
    startButton.click()
    then:
    at Modal
    when:
    selectContactButton.click()
    contactSearchField.value(context.pcUser2.surname)
    then: "the contact is shown in the search results"
    contact.isDisplayed()
}
Run Code Online (Sandbox Code Playgroud)

我认为文本"联系人显示在搜索结果中"将出现在错误消息中,但显然它没有.是否可能有另一种方式在Spock的Geb中打印自定义消息以获得更清晰的信息?

特别是对于'跳棋'我想要自定义消息,因为当检查失败时,你只会得到:

java.lang.NoSuchMethodError: geb.error.GebAssertionError.<init>(Ljava/lang/Object;Ljava/lang/Throwable;)V

at geb.waiting.WaitTimeoutException.<init>
Run Code Online (Sandbox Code Playgroud)

等等

编辑:嗯,我现在意识到,测试失败了,因为它还会在执行"then"之前检查所需的页面内容.我仍然希望能够添加自定义消息(特别是'在跳棋')...有人知道这是否可能?

spock geb

0
推荐指数
1
解决办法
591
查看次数

Geb Test Framework - 获取原始页面内容

有没有办法使用Geb获取原始页面内容?

例如,下面的测试应该可以工作(但是PhantomJS似乎很糟糕,使用HTML代码的JSON响应):

def "Get page content example -- health check"() {
        given:
        go "https://status.github.com/api/status.json"

        expect:
        assert driver.pageSource.startsWith('{"status":"(good)"')
    }
Run Code Online (Sandbox Code Playgroud)

请注意,是的,我明白我可以不使用Geb,只是在Groovy中进行URL调用,但由于多种原因我想明确使用Geb(其中一个原因是处理重定向).

groovy geb phantomjs

0
推荐指数
1
解决办法
418
查看次数

如何使用PhamtomJS在Geb/Selenium中设置cookie

你如何在Geb中设置cookie?我遇到了给定示例的以下错误:

org.openqa.selenium.InvalidCookieDomainException:{"errorMessage":"只能为当前域设置Cookie"....

..我也尝试使用Cookie生成器显式设置cookie多米诺骨牌虽然这只会导致另一个异常:org.openqa.selenium.UnableToSetCookieException:{"errorMessage":"无法设置Cookie"}

请注意,我曾经在GebConfig.groovy文件中有一个baseURL ..但我也删除了它..除了PhantomJS驱动程序配置之外,配置文件中没有设置.

我在OSX上使用PhantomJS最新版本(1.3.0 jar和2.1.1驱动程序OSX).

请注意,示例DOES因某些原因使用Chrome Webdriver.

import geb.spock.GebSpec
import org.openqa.selenium.Cookie

class SetCookieIT extends GebSpec {
    def "Cookie example"() {
        given:
        def options = driver.manage()

        when:
        go "https://www.wikipedia.org/"
        then:
        !options.getCookieNamed("my-geb-cookie")

        when:
        options.addCookie(new Cookie("my-geb-cookie", "foobar"))
        go "https://www.wikipedia.org/"
        then:
        title == "Wikipedia"
        options.getCookieNamed("my-geb-cookie").value == "foobar"
    }
}
Run Code Online (Sandbox Code Playgroud)

groovy selenium geb phantomjs

0
推荐指数
1
解决办法
895
查看次数