Java 检查url当前位于正确位置,id格式正确
假设我有一个像这样的urlJava 检查url当前位于正确位置,id格式正确,java,selenium,Java,Selenium,假设我有一个像这样的url http://localhost:3300/district/applications/e8533067-e9cd-4888-b4f3-0cdc60a14c40 我想检查用户是否是正确的url,例如/district/applications/ 我还检查url的最后一部分是否是uuid。我不想检查确切的值,只是它是一个uuid 我可以说: assertThat(getDriver().getCurrentUrl(),包含字符串('/district/applicat
http://localhost:3300/district/applications/e8533067-e9cd-4888-b4f3-0cdc60a14c40
我想检查用户是否是正确的url,例如/district/applications/
我还检查url的最后一部分是否是uuid。我不想检查确切的值,只是它是一个uuid
我可以说:
assertThat(getDriver().getCurrentUrl(),包含字符串('/district/applications')代码>
我可以得到url的最后一部分
String id=url.substring(url.lastIndexOf('/')+1)代码>
但是我怎样才能测试它是uuid,或者在selenium中有没有人可以帮助我做这类事情。我会说,做一些类似的事情:
try{
UUID uuid = UUID.fromString(someUUID);
//do something
} catch (IllegalArgumentException exception){
//do whatever you want here if its not a uuid
}
您可以对id.id.matches(“/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/”)对UUID返回true或false。正则表达式用于测试字符串是否为UUID。matches方法是string类的一部分,它接受一个正则表达式并检查字符串是否与模式匹配。