Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 检查url当前位于正确位置,id格式正确_Java_Selenium - Fatal编程技术网

Java 检查url当前位于正确位置,id格式正确

Java 检查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

假设我有一个像这样的url

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类的一部分,它接受一个正则表达式并检查字符串是否与模式匹配。