[英]Robot: Backslash in EXECDIR, Windows path
Underlying problem: I want to enable running robot tests using selenium 2 in a portable Firefox that's stored within EXECDIR. 潜在问题:我想在EXECDIR中存储的便携式Firefox中启用使用硒2运行机器人测试。
${firefox_binary}= Evaluate sys.modules['selenium.webdriver.firefox.firefox_binary'].FirefoxBinary('${EXECDIR}${/}Firefox${/}App${/}Firefox${/}Firefox.exe') sys, selenium.webdriver
${firefox_profile}= Evaluate sys.modules['selenium.webdriver.firefox.firefox_profile'].FirefoxProfile('${EXECDIR}${/}Lib${/}SeleniumFirefoxProfile') sys, selenium.webdriver
Create Webdriver Firefox firefox_binary=${firefox_binary} firefox_profile=${firefox_profile}
That works fine if, instead of ${EXECDIR}, I use the actual path. 如果我使用实际路径而不是$ {EXECDIR},那将很好用。
EXECDIR is something like C:\\Users\\bart.simpson\\workspace\\projectname
here. EXECDIR类似于
C:\\Users\\bart.simpson\\workspace\\projectname
。 The issue is that a backslash, when followed by the b, is converted to the ASCII backslash character. 问题在于,反斜杠(后跟b)将转换为ASCII反斜杠字符。 The test log then says:
然后,测试日志显示:
Evaluating expression 'sys.modules['selenium.webdriver.firefox.firefox_profile'].FirefoxProfile('C:\Users\bart.simpson\workspace\projectname\Lib\SeleniumFirefoxProfile')' failed: OSError: [Errno 20047] Unknown error: 20047: 'C:\\Users\x08art.simpson\\workspace\\projectname\\Lib\\SeleniumFirefoxProfile'
Of course I've tried using ${fixedExecDir}= Replace String ${EXECDIR} '\\' '/'
and such, but nothing ever changes the outcome. 当然,我曾尝试使用
${fixedExecDir}= Replace String ${EXECDIR} '\\' '/'
等等,但是没有任何改变。
Ideas? 有想法吗? Thanks.
谢谢。
Try treating the path as a raw string literal, by putting an "r" before the quote immediately before ${EXECDIR}
: 尝试将路径视为原始字符串文字,方法是在
${EXECDIR}
之前的引号前放置一个“ r”:
${firefox_binary}= Evaluate ....FirefoxBinary(r'${EXECDIR}${/}Firefox...')
This should work because the robot variables are substituted before the string is passed to python, so the python interpreter only ever sees the complete string. 这应该起作用,因为在将字符串传递给python之前已替换了机械手变量,因此python解释器仅能看到完整的字符串。
If you are unfamiliar with python raw string literals, see this question: 如果您不熟悉python原始字符串文字,请参见以下问题:
What exactly do “u” and “r” string flags do in Python, and what are raw string literals? Python中的“ u”和“ r”字符串标志到底做了什么,什么是原始字符串文字?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.