针对 Selenium 服务器运行 Python RC 时,无法从 user-extensions.js 文件执行自定义 Selenium 断言函数

发布于 2024-11-25 04:35:43 字数 1240 浏览 0 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉城メ夜风 2024-12-02 04:35:44

您需要用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文