I was checking how i can use existing selenium scripts written in python for JMeter. There are suggestions to use Jython. i have installed jython by putting jython jar file in lib.
Using JSR223 Sampler, when I tried to give the existing selenium script file it is giving me below error while hitting run
> Data type ("text"|"bin"|""):text Response code:500 Response
> message:javax.script.ScriptException: ImportError: No module named selenium in <script> at line number 1
Do i need to use third party tool to convert existing scripts to JMX file?
My second question is :- I checked the documentation and found that it works on python2.7 version. Is that really correct? How come it is not updated to python3
No module named selenium in
It looks like you didn't install selenium module, you need to install it in order to be able to use it like:
jython -m pip install selenium
More information: How can I install various Python libraries in Jython?
However if you want to use existing Python UI tests for performance testing it's better to consider converting them to JMeter's HTTP Request samplers, as each thread (virtual user) needs to run a real browser and a real browser needs 1 CPU core and a couple of gigabytes of RAM so you can simulate thousands of users on HTTP protocol level using the hardware allowing to launch several browsers only.
See How to Convert Selenium Scripts into the JMX Converter article for more details.
Related
We are using phantomjs browser in robot script and have a requirement to set the phantomjs custom header as a part of capability. Below is the code snippet we have tried
${dc} Evaluate sys.modules['selenium.webdriver'].DesiredCapabilities.PHANTOMJS sys, selenium.webdriver
Set To Dictionary ${dc} phantomjs.page.customHeaders.Authorization=Basic <Credentials>
${service args}= Create List --proxy=localhost:8080 --web-security=false --ignore-ssl-errors=yes --ssl-protocol=ANY --load-images=yes
Create Webdriver PhantomJS service_args=${service args} executable_path=/usr/sap/ljs/webapps/s4c/WEB-INF/classes/WebDriver/phantomjs desired_capabilitie=${dc}
This is code is failing to launch the browser. We didn't find concrete documentation for setting capability to phantomjs in robot. If anyone tried setting custom header to phantomjs in robot framework please suggest us.
Perhaps stating the obvious: none of your end users are using the system under test with PhantomJS which significantly lowers confidence of the achieved results. So for that reason I strongly suggest putting effort in getting the right environment setup so that the test mimic end user situation as close as possible.
It is very likely that you're using a modern version of Selenium that no longer supports PhantomJS as it is Deprecated as of Selenium 3.6.0 and removed as of 3.7.0. Releases.
So if your pip list shows a Selenium Module version of 3.6.0 or higher you may want to downgrade.
I have a strange problem, which I'm unable to solve for sometime. I have a selenium WDS for Firefox browser. I tried to execute the code in JMeter UI, everything works fine. But when I try to execute the same in a server (using XVFB driver), I get the error:
rm="sun.org.mozilla.javascript.EvaluatorException: Can't find method org.openqa.selenium.remote.RemoteWebDriver.executeScript(string,org.openqa.selenium.remote.RemoteWebElement). (<Unknown source>#17) in <Unknown source> at line number 17"
All the required drivers are the same as the one I locally try. Yet, I get the error only when I run in the server but not locally. Please help
Most probably you have different versions of either WebDriver Sampler or dependency libraries, I don't see any other ways for the same script to work on one machine and don't work on another.
Install the same version of JMeter onto both machines (use JMeter 3.2 or later, whatever is available at JMeter Downloads Page)
Install latest version of the WebDriver Sampler plugin using JMeter Plugins Manager
Your test should now be running fine.
I have built a Polymer based application. I'd like to write some end-to-end tests (not unit tests, but user behavior integration tests) for it. How do I do this currently (May 2015)?
I spent the past few days looking into this problem. Despite the vast number of pages devoted to one related topic or another on the web, nothing documents a solution to this problem. I was able to piece together something that works. So here it is. Hope this is useful for those looking to write end-to-end tests for Polymer apps. I am sure a better solution will come about as Polymer, web components, and shadow DOM technologies mature.
Some details: Linux, want automate testing in a script (ideally headless), app consists of many Polymer elements and is served by and loads data from a Django server.
Failed attempt with PhantomJS
First, I tried using casperjs and phantomjs. phantomjs is headless and casperjs has very good navigation support, so I thought those would be a good combination to end up with. Unfortunately, phantomjs does not support HTML5 imports and the webcomponents.js polyfill does not seem to work on phantomjs.
Using Selenium
I ended up with a Selenium/ChromeDriver based solution, using the selenium python client. I did not test this with Firefox driver so I don't know if that works. Here is what you need to do:
To make things easier, create a directory to put stuff in:
mkdir selenium
Install google chrome. I did this via the Google website and downloaded the linux version. Then, download selenium server 2.45 and chromedriver 2.15, into the selenium directory. E.g.
$ ls selenium/
chromedriver selenium-server-standalone-2.45.0.jar
Then, install Python Selenium API
$ pip install selenium
Run a simple test:
$ cd selenium
$ cat > test.py
from selenium import webdriver
driver = webdriver.Chrome('./chromedriver')
driver.get("http://localhost:8000/myapp/")
driver.implicitly_wait(3)
print driver.title
content = driver.find_element_by_css_selector('myelement::shadow h3')
print content.text
driver.close()
$ xvfb-run python test.py
(xvfb is necessary to make the running of test.py headless)
test.py prints out the content of the h3 element in a custom Polymer element called myelement. E.g. if DOM looks like
<myelement>
<h3>Hello World</h3>
</myelement>
Then test.py prints "Hello World".
The h3 element appears in the shadow DOM of myelement. Chrome dev tool lists the CSS selector for this h3 as "myelement #shadow-root h3". Using Selenium, you can access this h3 using "myelement::shadow h3" as the CSS selector.
Tests and Test Data
I organized my tests as Python unittest test cases, and wrote a test driver script. The driver script forks, creates a Django dev server in the child process, and runs "python -m unittest" in the parent process. Each test case uses Python selenium API to connect to the Django dev server. In the setUp and tearDown methods of each test case, I inject test data into the database using my Django model classes.
I run the driver script under xvfb -- "xvfb-run python driver.py" -- to make it headless.
Dealing with Ajax and two-way bindings
My Polymer app uses ajax to load data and two-way bindings to render HTML templates. Polymer also renders templates and updates the DOM asynchronously. In my test cases, I depend on Selenium's conditional wait to detect when data loading completes and DOM re-renders. Implicit waiting (which isn't a good idea anyways) did not work for me for some reason; the implicit wait just returns immediately. I also updated my HTML templates to be more testable -- adding DOM IDs and unique text or CSS selectors to differentiate different stages of the app.
Caveats
A button with only as its inner HTML becomes un-clickable using Selenium. If you have such a button, use ActionChains to click it:
chain = ActionChains()
chain.move_to_element(element)
chain.click()
chain.perform()
I am using phantomjs to build a web crawler. My current crawler is a Python script using selenium, which requires a running Firefox browser. While Selenium is good for debugging scripts (as I can use firebug to inspect the webpage), it cannot be deployed on linux servers without GUI. So I am trying to translate my Python script to phantomjs.
To debug phantomjs scripts, I save the page source html and render a png screenshot to disk, and open it in Firefox to inspect the source page. I am wondering if there is a better way to do this, e.g. a plugin for phantomjs, etc.
This little hack is using a simple technique: It grabs the screen as PhantomJS or CasperJS sees it with captureBase64('png') and then it is POSTing the image into the receiving server which then sends it via socket.io to the browser which displays it is as inline image.
The source code is available on github:
https://github.com/maciejjankowski/flaming-octo-puss
I'm not sure if PhantomJS has it, but CasperJS does (and the latter adds some extra functions to PhantomJS)
and use remote debugging as others suggest
As for most of the JS scripts, it's not so trivial to debug phantomjs script, because there is no IDE/compiler behind this.
First, I higly suggest you to read the Troubleshooting section.
As said by torazaburo, your best option is to use Remote Debugging : scripts can be run in a Web Inspector interface-like console : step-in, step-out, break points, local variables... many classic debugger features are available. If you're familliar with Chrome developpers tools, it's pretty the same.
Though not a solution to your Phantomjs troubles,I think Selenium with Python bindings can be used very efficiently as a headless scraper in a Linux environment.
You can use PyVirtualDisplay, a Python wrapper for Xvfb and Xephyr to fake a display.PyVirtualDisplay needs Xvfb as a dependency. On Ubuntu, first install Xvfb:
sudo apt-get install xvfb
then install PyVirtualDisplay from Pypi:
pip install pyvirtualdisplay
Sample Selenium script in Python in a headless mode with PyVirtualDisplay:
#!/usr/bin/env python
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
# now Firefox will run in a virtual display.
# you will not see the browser.
browser = webdriver.Firefox()
browser.get('http://www.google.com')
print browser.title
browser.quit()
display.stop()
I am able to run python scripts throgh selenium rc.
I dont know to run these scripts in selenium grid.I am not able to get the correct answer from anywhere.is it possible to run python scripts from selenium eclipse.
Please anyone provide me the solution as soon as possible.
Thx.
first of all you have to install selenium with this code:
pip install -U selenium
Alternately, you can download the source distribution from PyPI (e.g. selenium-2.53.1.tar.gz), unarchive it, and run:
python setup.py install
both of the methods described above install selenium as a system-wide package That will require administrative/root access to there machine. You may consider using a virtualenv to create isolated Python environments instead.
You're asking a lot of things that don't really make sense. E.g., there is no such thing as "selenium eclipse." Anyway, I'll try to answer the best I can.
Your Python scripts should have the client connect to the Selenium Grid Hub instead of a specific RC Server. The hub is then responsible for dispatching the request to any registered nodes in the grid. There is nothing Python-specific involved with grid.