针对 Selenium 服务器运行 Python RC 时,无法从 user-extensions.js 文件执行自定义 Selenium 断言函数
我正在尝试从 Selenium IDE 将 Selenium 脚本导出到 Python。我正在使用一些 user-extension.js 函数(它们在 Selenium IDE 中工作)。导出到 Python 后,生成的脚本如下所示:
from selenium import selenium
import unittest, time, re
class new_selenium_test(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*chrome", "http://localhost/")
self.selenium.start()
def test_selenium_assert_something(self):
sel = self.selenium
# sel.assert_something("abc=1", "x=126")
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
请注意,最有趣的行是,我在其中调用用户扩展代码(函数“assert_something”,它映射到 user-extensions.js 文件中的函数“assertSomething”)是注释掉了。当我激活该行并针对 Selenium 服务器运行脚本时,如下所示:
py.test new-selenium-test.py
我收到如下错误:
AttributeError: 'selenium' object has no attribute 'assert_something'
知道为什么 Selenium IDE 注释掉我的自定义调用,以及为什么它不从 Python 执行它吗?
请注意,我已经像这样启动了 Selenium 服务器:
java -jar selenium-server-standalone-2.0rc2.jar -userExtensions /path/user-extensions.js
感谢您的帮助!
I'm trying to export a Selenium script to Python from the Selenium IDE. I am using a few user-extension.js functions though (which are working in Selenium IDE). After exporting to Python, the generated script looks like this:
from selenium import selenium
import unittest, time, re
class new_selenium_test(unittest.TestCase):
def setUp(self):
self.verificationErrors = []
self.selenium = selenium("localhost", 4444, "*chrome", "http://localhost/")
self.selenium.start()
def test_selenium_assert_something(self):
sel = self.selenium
# sel.assert_something("abc=1", "x=126")
def tearDown(self):
self.selenium.stop()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
Note that the most interesting line, where I call my user extension code (function "assert_something", which maps on function "assertSomething" in my user-extensions.js file), is commented out. When I activate that line and run the script against Selenium server like this:
py.test new-selenium-test.py
I get an error like this:
AttributeError: 'selenium' object has no attribute 'assert_something'
Any idea why Selenium IDE comments out my custom call, and why it does not execute it from Python?
Note that I have started the Selenium server like this:
java -jar selenium-server-standalone-2.0rc2.jar -userExtensions /path/user-extensions.js
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要用 Python 重写自定义 JavaScript 函数,如下所述:
http://groups.google.com/group/selenium-users/browse_thread/thread/e927dad7e6cb2944/1712b997934cece5
它无法将Python对象连接到您的自定义JS,因此它留下了在那里评论提醒你用Python实现它。
You need to rewrite your custom JavaScript functions in Python, as described here:
http://groups.google.com/group/selenium-users/browse_thread/thread/e927dad7e6cb2944/1712b997934cece5
It can't connect the Python object to your custom JS, so it leaves that comment there to remind you to implement it in Python.