首页 > 解决方案 > Geb If Else 或尝试捕获处理

问题描述

我是 Geb 语音测试的新手,我有一个 ui 发送消息和接收文本或电子邮件的测试,我有一个获取发送的电子邮件/文本的 api 调用,我需要使用该响应并继续进行 UI 测试。但是该响应已过期,因为 api 速度很快,并且它获取了先前发送的消息(在我的 ui 发送该电子邮件/文本之前)并且最后发送的消息使之前的消息过期。所以我的问题是,如果消息已过期,我需要再次调用该 API,我尝试了 if else 和 waitFor 方法但无法提出解决方案,我使用页面对象和测试规范,我无法将其创建为一种方法,因为在一页和一个 def 类中发生,我什至不能在我的测试类中执行 waitFor 导致 IllegalMonitorStateException

when: "I enter text code"
String text = response.getText()
testPage.enterCode << text
testpage.pager.clickNext() // here is happening the code expiration and couldn't get to the next page,

then: "I am in next page"
at nextPage // if am not on the next page I need to make a new api call to get the newest response

我试过了

when: "I enter text code"
String text = response.getText()
testPage.enterCode << text
testpage.pager.clickNext() 
def erroHappened = testPage.errorAlert.isdisplayed

then: "I am in next page"
!errorHappened && testPage.enterCode << response.getText()

我如何使用等待或尝试捕获或其他方法来解决此问题,提前谢谢

标签: geb

解决方案


推荐阅读