我正在尝试用otp号自动测试登录场景&我正在使用twilio短信。但由于某种原因,我收到的是前一条短信,而不是最后一条。这是我的密码。
会安抚任何帮助谢谢!
public class OTPHandle extends CommonOps{
public static final String ACCOUNT_SID = System.getenv("XXX");
public static final String AUTH_TOKEN = System.getenv("XXX");
public static String getMessage() {
return getMessages().filter(m -> m.getDirection().compareTo(Message.Direction.INBOUND) == 0)
.filter(m -> m.getTo().equals("+XXX")).map(Message::getBody).findFirst()
.orElseThrow(IllegalStateException::new);
}
private static Stream<Message> getMessages() {
ResourceSet<Message> messages = Message.reader(ACCOUNT_SID).read();
return StreamSupport.stream(messages.spliterator(), false);
}
public static String getOTP(){
Twilio.init(ACCOUNT_SID,AUTH_TOKEN);
String smsBody = getMessage();
String OTPNumber = smsBody.replaceAll("[^-?0-9]+", " ").substring(1,7);
return OTPNumber;
}
}
public class WebPortalLoginFlow extends CommonOps {
@Test
public void test01_verifyLobbyHeader(){
System.out.println(OTPHandle.getOTP()); //gets the previous sms
WebFlows.login(String idNumber,String prefixNum,String phoneNumber, OTPHandle.getOTP());//gets the previous sms
System.out.println(OTPHandle.getOTP());//gets the updated right sms
}
}
暂无答案!
目前还没有任何答案,快来回答吧!