嗨,我们在 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) 我希望能够使用 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) 当我使用 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) 我想在我的 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) 对于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+Classes和http://groovy.codehaus.org/Groovy+Beans但是没办法.任何建议或示例都会非常有用.