在Selenium服务器上运行Python

在Selenium服务器上运行Python

本文介绍了在Selenium服务器上运行Python RC时,无法从user-extensions.js文件执行自定义Selenium断言功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Selenium IDE将Selenium脚本导出到Python.我虽然使用了一些user-extension.js函数(在Selenium IDE中有效).导出到Python后,生成的脚本如下所示:

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()

请注意,最有趣的行是我的用户扩展代码(函数"assert_something",它映射到user-extensions.js文件中的函数"assertSomething"),已被注释掉.当我激活该行并像这样对Selenium服务器运行脚本时:

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

我收到这样的错误:

AttributeError: 'selenium' object has no attribute 'assert_something'

您知道为什么Selenium IDE注释掉我的自定义调用,以及为什么它不从Python执行吗?

Any idea why Selenium IDE comments out my custom call, and why it does not execute it from Python?

请注意,我已经像这样启动了Selenium服务器:

Note that I have started the Selenium server like this:

java -jar selenium-server-standalone-2.0rc2.jar -userExtensions /path/user-extensions.js

感谢您的帮助!

推荐答案

您需要使用Python重写自定义JavaScript函数,如下所述:

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

它无法将Python对象连接到您的自定义JS,因此该注释保留在那里,提醒您在Python中实现它.

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.

这篇关于在Selenium服务器上运行Python RC时,无法从user-extensions.js文件执行自定义Selenium断言功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 10:19