slimerjs - open webpage that is passed via stdin? - phantomjs

Can slimerjs take a webpage as input via stdin?
E.g. generateHtmlFileAndWriteToStdOut | slimerjs
I want to use slimerjs in a script pipeline.

The present version does not support stdin.
When version 1.0 is released, the product will have api parity with phantom js and support stdin.

Related

JMeter with Python Selenium

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.

Error popup appears when trying to open script in jmeter recorder by Blazemeter chrome extension

I recorded a script using blazemeter and it was showing me to save in 2 formats: Selenium only, Jmeter and selenium combined.
I downloaded both formats and tried opening in JMeter 4.0 but that shows an error popup with no details.
Please let me know how to go ahead with jmx extension.
You can open only JMX files in JMeter, make sure to choose JMeter only (JMX) option when saving your recorded script:
This type of recording can be normally opened with JMeter.
With regards to Selenium only (YAML) and JMeter & Selenium combined (YAML) - you can open them using Taurus tool.
If you need to convert Taurus YAML file into .jxm you can do the following:
Install Taurus
Invoke the following command:
bzt /path/to/recorded/test.yml -gui
Taurus will open the recorded script in JMeter GUI where you will be able to debug it, edit or save as .jmx script.
More information: Navigating your First Steps Using Taurus

Sending keys using Selenium and headless Chrome

Using headless chrome and selenium I can succesfully send keys to websites on my Mac. When I port the same code to my Linux machine it crashes however. The offending line is the following one:
driver.find_element_by_xpath('//input[#id="username"]').send_keys(username)
And I get the following error message:
"an X display is required for keycode conversions, consider using Xvfb"
Why is this not working on Linux?
This is a bug in chromedriver that is detailed here.
According to the new lead for chrome driver
The issue is in ChromeDriver. As its name implies, the sendKey command sends simulated key strokes to Chrome, and ChromeDriver is responsible for converting the input text string into corresponding keystrokes to send to Chrome. On Linux, ChromeDriver uses X display to do the conversion, and fails when no X display is available.
It has been fixed recently and will be released in v 2.31. Unfortunately the chromium team does not make nightly builds publicly available and there is no official release date yet.
In the meantime you can build your own chromedriver or download a prebuilt binary from a third party... Both a dockerfile and a working binary may be found at this github.

selenium script in jmeter

I had write a script using selenium in Jmeter. Imported all the packages.
var pkg=JavaImporter(org.openqa.selenium) //import java selenium package
var support_ui=JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var ui=JavaImporter(org.openqa.selenium.support.ui)
var wait=new support_ui.WebDriverWait(WDS.browser,5000)
WDS.sampleResult.sampleStart()
WDS.browser.get('https://www.google.com')
WDS.sampleResult.sampleEnd()
to simply open the page.
it doesn't show any results in Listener.
Have you added the relevant Config element, like:
Firefox Driver Config
Chrome Driver Config
Phantom JS Driver Config
or whatever browser you're trying to use?
If yes and you still experience problems - check jmeter.log file - it usually contains enough troubleshooting information. The most common errors are:
libraries conflict. Selenium requires newer HTTP libraries version than JMeter so:
open /lib folder of your JMeter installation
locate .jar files which names start with http
delete duplicate .jar files with lesser version
unsupported browser (mostly affects Firefox). If you're trying to run Selenium test on Firefox - make sure you use one of the supported versions. Latest JMeter Plugins WebDriver Set 1.3.1 comes with Selenium 2.47.0 and according to the changelog it should be:
Supports native events for Firefox version 31 (immediately previous ESR).
Native event support has been discontinued for versions of Firefox later
than 33. Synthetic events tested on Firefox versions 31 (immediately
previous ESR), 38 (immediately previous release and current ESR), and 39
(current release).
For extra information and tips on using WebDriver Sampler in JMeter check out The WebDriver Sampler: Your Top 10 Questions Answered guide

How do you write end-to-end tests for Polymer (JS) based application (circa May 2015)?

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