问题
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!
回答1:
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.
来源:https://stackoverflow.com/questions/6747441/cannot-execute-custom-selenium-assert-function-from-user-extensions-js-file-whe