我使用commons-text 1.2-SNAPSHOT中的RandomStringGenerator生成随机用户名和密码用于测试。在Selenium和Chrome驱动程序中使用这些生成的字符串可能会导致
org.openqa.selenium.WebDriverException:
unknown error: ChromeDriver only supports characters in the BMP
(Session info: chrome=62.0.3202.62)
(Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.13.0-16-generic x86_64) (WARNING: The server did not provide any stacktrace information)有没有办法用现有的函数生成BMP字符串,或者我必须用显而易见的方法来研究所有的BMP代码点,从它们中随机选择,冒着重新发明轮子的风险。
不是How to handle "org.openqa.selenium.WebDriverException: ChromeDriver only supports characters in the BMP" exception?的副本,因为我对用于其他目的的解决方案也很感兴趣。
发布于 2020-07-25 05:10:13
RandomStringGenerator允许您创建一个生成器,该生成器根据指定的范围和过滤函数进行过滤。下面是我用Kotlin编写的一个函数,用于生成与Selenium的chrome驱动程序兼容的随机BMP unicode字符串。
如果您不关心您的随机字符串是否包含不可打印的字符,那么您可以删除filteredBy。
private val randomBMPStringGenerator: RandomStringGenerator = RandomStringGenerator.Builder().withinRange(0x0000, 0xFFFF).filteredBy(CharacterPredicate {
c ->
val block: UnicodeBlock = UnicodeBlock.of(c)
!Character.isISOControl(c) && block !== UnicodeBlock.SPECIALS
}).build()
randomBMPStringGenerator.generate(wordLength)https://stackoverflow.com/questions/46950897
复制相似问题