标签: spock

如何在geb中的模块中截取屏幕截图

嗨,我们在 Spock 框架上运行 Geb 测试。我正在尝试使用报告“屏幕截图”在模块中截取屏幕截图。它不像在规范上那样识别报告功能。我应该如何在模块中截取屏幕截图。

这是一个模块中的示例代码。

try{
    $(By.xpath("//button[@ng-click=\"ok()\"]")).click()
   }
catch (Throwable t){
                                                                  failures.add("\n Could not click on the Ok button after the Ticket created successfully message appeared")

report "Failure"
}
Run Code Online (Sandbox Code Playgroud)

spock geb

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

在同一测试中使用 Geb & Spock 重启浏览器

我希望能够使用 Geb 和 Spock 框架重新启动我的浏览器会话中期测试。我不知道如何关闭浏览器并在测试完成等之后更新,但是当我在测试期间关闭并尝试重新使用浏览器对象时,我收到了 selenium 抛出的会话错误。以下是我正在尝试执行的基本大纲。NB 从不允许我导航到新的 StoreHome,如果我尝试只使用浏览器,我会抛出错误。

@Category(High.class)
def "TC1: Verify Browser Restart"() {
    when: "On my StoreFront HP wait until title displayed"
    to StoreHomePage
    waitFor { homepagetitle.displayed }

    then: "Update your site picker"
    mySitePicker.click()
    waitFor { myNewHomePageTitle.displayed }

    when: "Close the browser and insure on restart new page is loaded"
    browser.close()
    browser.quit()

    def nb = new Browser()
    nb.to(NewStoreHomePage)

    then: "Validate on New HP"
    asset myNewHomePageTitle.displayed
}
Run Code Online (Sandbox Code Playgroud)

selenium spock geb

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

预期和实际未显示在控制台日志中 - Groovy Spock

当我使用 testResponse.code == 401 时,我可以从控制台日志中看到“预期”和“实际”。但是当我使用 checkResponseCode(testResponse, 401) 时,我得到以下信息:

 Condition not satisfied:

checkResponseCode(testResponse, 401)
|         |
false     testpackage.project1.hs.unittestspack.utils.TestClass@17d88132
Run Code Online (Sandbox Code Playgroud)

如何修复 checkResponseCode() 方法以使其产生预期和实际结果?这是 checkResponseCode() 的实现:

 static def checkResponseCode(resp, code) {
     resp.code == code
}
Run Code Online (Sandbox Code Playgroud)

这是我想要实现的日志:

Condition not satisfied:

testResponse.code == 401
|                |    |
|                500  false
testpackage.project1.hs.unittestspack.utils.TestClass@5b367418

Expected :401

Actual   :500

 <Click to see difference>
Run Code Online (Sandbox Code Playgroud)

java groovy spock

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

如何使用 spring boot 和 spock 运行测试容器

我想在我的 Spring Boot 应用程序上使用带有 spock 的测试容器。

这些是我的依赖项:

dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-redis')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile 'org.testcontainers:spock:1.8.3'
    runtime('org.springframework.boot:spring-boot-devtools')
    compile 'org.codehaus.groovy:groovy-all:2.4.15'
    compileOnly('org.projectlombok:lombok')

    compile 'org.testcontainers:testcontainers:1.8.3'
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile "org.spockframework:spock-core:1.1-groovy-2.4-rc-4"
    testCompile "org.spockframework:spock-spring:1.1-groovy-2.4-rc-4"
    testCompile 'com.github.testcontainers:testcontainers-spock:-SNAPSHOT'
}
Run Code Online (Sandbox Code Playgroud)

我已经初始化了我的测试,如下所示:

@SpringBootTest
@Testcontainers
class ProductRedisRepositoryTest extends Specification {

    @Autowired
    ProductRedisRepository productRedisRepository

    @Autowired
    TestComponent testComponent


    static Consumer<CreateContainerCmd> cmd = { -> e.withPortBindings(new PortBinding(Ports.Binding.bindPort(6379), new ExposedPort(6379)))}

    @Shared
    public static GenericContainer redis =
            new GenericContainer("redis:3.0.2")
                    //.withExposedPorts(6379)
                    .withCreateContainerCmdModifier(cmd)

    def "check redis repository save and get"(){

        given:
            Product product = Product.builder()
                    .brand("brand")
                    .id("id")
                    .model("model")
                    .name( "name")
                    .build()
        when: …
Run Code Online (Sandbox Code Playgroud)

spring spock docker testcontainers

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

如何在groovy中调用另一个类的方法?

对于Instance,我有一个这样的类:

class firstOne{

    ....
    def A (){

    }

}

class secondOne{

    // I need to call and use method A from class firstOne
    // even I get error if I try to follow Java like calls
    // firstOne method = new firstOne();
    // method.A()   
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试过http://groovy.codehaus.org/Scripts+and+Classeshttp://groovy.codehaus.org/Groovy+Beans但是没办法.任何建议或示例都会非常有用.

groovy spock geb

-2
推荐指数
1
解决办法
7700
查看次数

标签 统计

spock ×5

geb ×3

groovy ×2

docker ×1

java ×1

selenium ×1

spring ×1

testcontainers ×1