我正在从pytest + Selenium切换到robotframework + SeleniumLibrary + Selenium。尽管SeleniumLibrary关键字设计为更易于使用,但我无法匹配从香草Selenium到SeleniumLibrary的一些简单操作。 例如,我搜索了execute_path并尝试了所有解决方案,但没有一个能正常工作。在使用pytest的同时,我可以创建一个网络驱动程序,例如:
driver = Chrome(executable_path='../drivers/chromedriver')
driver.get("https://<URL>")
使用SeleniumLibrary时,以下变体均无效:
*** Settings ***
Documentation Suite description
Library SeleniumLibrary
*** Variables ***
${URL} https://<URL>
*** Test Cases ***
Login_test
Open Browser ${URL} Chrome executable_path="/path/to/driver/chromedriver"
*** Settings ***
Documentation Suite description
Library SeleniumLibrary
Library OperatingSystem
*** Variables ***
${URL} https://<URL>
${EXECDIR} /path/to/driver/
*** Test Cases ***
Login_test
Set Environment Variable webdriver.chrome.driver ${EXECDIR}
Open Browser ${URL} Chrome
*** Settings ***
Documentation Suite description
Library SeleniumLibrary
*** Variables ***
${URL} https://<URL>
${chromedriver} /path/to/driver/chromedriver
*** Test Cases ***
Login_test
Create Webdriver Chrome chrome executable_path=${chromedriver}
Go To ${URL}
除了手动将驱动程序的路径添加到PATH变量之外,是否还有其他解决方法?
答案 0 :(得分:0)
我的原始代码带有引号:${chromedriver} "/path/to/driver/chromedriver"
,当我将其固定为${chromedriver} /path/to/driver/chromedriver
时,一切正常。因此,目前唯一正确的方法是原始帖子中的最后一个选项:
*** Settings ***
Documentation Suite description
Library SeleniumLibrary
*** Variables ***
${URL} https://<URL>
${chromedriver} /path/to/driver/chromedriver
*** Test Cases ***
Login_test
Create Webdriver Chrome chrome executable_path=${chromedriver}
Go To ${URL}