Robot Framework:如何从Robot Framework库中访问类属性

huangapple go评论111阅读模式
英文:

Robot Framework: How to access a class property from a Robot Framework library

问题

To implement a custom function, I am trying to access the driver property from the SeleniumLibrary which looks like below in the python package:

  1. class SeleniumLibrary(DynamicCore):
  2. ROBOT_LIBRARY_SCOPE = "GLOBAL"
  3. ROBOT_LIBRARY_VERSION = __version__
  4. @property
  5. def driver(self) -> WebDriver:
  6. """Current active driver.
  7. :rtype: selenium.webdriver.remote.webdriver.WebDriver
  8. :raises SeleniumLibrary.errors.NoOpenBrowser: If browser is not open.
  9. """
  10. if not self._drivers.current:
  11. raise NoOpenBrowser("No browser is open.")
  12. return self._drivers.current

I have created the webdriver using the Open Browser command like Open Browser url=${url} browser=${browser} alias=Test options=${options} executable_path=${driverPath}.

I have tried multiple commands in the robot script to access the @property driver but it is not working:

  • Log ${SeleniumLibrary.driver}
  • ${driver}= SeleniumLibrary.driver
  • ${driver}= Evaluate SeleniumLibrary.driver

Error Message: Evaluating expression 'SeleniumLibrary.driver' failed: AttributeError: module 'SeleniumLibrary' has no attribute 'driver'

Reference: https://github.com/robotframework/SeleniumLibrary/blob/master/docs/extending/extending.rst#id14

英文:

To implement a custom function, I am trying to access the driver property from the SeleniumLibary which looks like below in the python package:

  1. class SeleniumLibrary(DynamicCore):
  2. ROBOT_LIBRARY_SCOPE = "GLOBAL"
  3. ROBOT_LIBRARY_VERSION = __version__
  4. @property
  5. def driver(self) -> WebDriver:
  6. """Current active driver.
  7. :rtype: selenium.webdriver.remote.webdriver.WebDriver
  8. :raises SeleniumLibrary.errors.NoOpenBrowser: If browser is not open.
  9. """
  10. if not self._drivers.current:
  11. raise NoOpenBrowser("No browser is open.")
  12. return self._drivers.current

I have create the webdriver using the Open Browser command like Open Browser url=${url} browser=${browser} alias=Test options=${options} executable_path=${driverPath}.

I have tried multiple commands in the robot script to access the @property driver but it is not working:

  • Log ${SeleniumLibrary.driver}
  • ${driver}= SeleniumLibrary.driver
  • ${driver}= Evaluate SeleniumLibrary.driver

Error Message: Evaluating expression 'SeleniumLibrary.driver' failed: AttributeError: module 'SeleniumLibrary' has no attribute 'driver'

Reference: https://github.com/robotframework/SeleniumLibrary/blob/master/docs/extending/extending.rst#id14

答案1

得分: 1

我能够使用Robot Framework找到解决方案。

  1. ${SeleniumLibrary} Get Library Instance SeleniumLibrary
  2. ${driver}= Set Variable ${SeleniumLibrary.driver}
英文:

I was able to find the solution using Robot Framework.

  1. ${SeleniumLibrary} Get Library Instance SeleniumLibrary
  2. ${driver}= Set Variable ${SeleniumLibrary.driver}

huangapple
  • 本文由 发表于 2023年6月6日 02:22:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76409064.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定