phantomjs custom header in robot framework - selenium

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.

Related

Why is chromedriver tied to chrome version?

I'm starting to use selenium and ChromeDriver in order to automate tasks in Chrome. I'm interested in scaling the task across multiple managed windows PC's.
I understand that updates of Chrome might break functionality in ChromeDriver. But I'm concerned it's the right tool because manually updating based on the chrome version results in a lot of maintenance as we'd have to manually place the executable on each system.
Is ChromeDriver really "whitelisting" with which chrome version it works? and why is that?
Browsers would have updates, which the driver also must have in order to invoke and interact with the browser, and hence your driver version must be in sync with the browser version. It is not just for Chrome, but for Firefox, and Edge also. One thing you can do is to use the ChromeDriverManager by installing the webdriver-manager library.
In Python, you do like this:
pip install webdriver-manager
In the py file, you can invoke the chromedriver:
from webdriver_manager import ChromeDriverManager
Then, when you initialize the driver, you can pass in the ChromeDriverManager:
driver = webdriver.Chrome(ChromeDriverManager().install())
With this, your driver and browser would be in sync. You need not worry about the incompatibility of driver-browser versions.
Please note: you would get a depcration warning with the above driver line of code, for which you need to include Service object; however, for now, it is a warning and not an error, so your code would not hamper the execution, but sooner or later, you must use Service object.
Here is a good article you can refer to Medium

Is there a way to run nightwatch on Safari v12.1?

My mac auto-updated safari to v12.1, but now I can't run my nightwatch tests against safari. I just always get the error: "Request body does not contain required parameter 'capabilities'.". I think it's related to this issue: https://github.com/SeleniumHQ/selenium/issues/6431
Is there anything I can update or do inside of nightwatch to get the tests to run again?
Turns out safari made some huge breaking changes in v12. They removed support for the Selenium JSON wire protocol and now only support w3c WebDriver protocol. There isn't much you can do from a nightwatch config standpoint to fix this. Just try to find the w3c equivalent command for what you are trying to do and use that instead.
Ref: https://developer.apple.com/documentation/webkit/macos_webdriver_commands_for_safari_12_and_later

How to replace Chrome with PhantomJS for use with Selenium and Conductor?

I am successfully using the Conductor framework to scrape data off a website. I use the Chrome browser and therefore I have installed chromedriver.exe in the root of my project.
To speed things up I want to replace Chrome with the headless PhantomJS browser. I installed PhantomJS as explained in the answer to this Stackoverflow question: PhantomJS & Conductor Framework and have changed the browser to Browser.PHANTOMJS in #Config.
Whatever I do however, I get no results.
I found no documentation how to setup PhantomJS for use with Selenium or PhantomJS.
The question How to Implement Selenium WebDriver with PhantomJS and Can we Use Sikuli with PhantomJS? did not help either.
How to replace Chrome with PhantomJS for use with Selenium and Conductor?
The trouble you are having appears to be due to an older version of the PhantomJS library included in Conductor. The error when running PhantomJS can be found in this imported issue on the Selenium Github. The remedy is to import a fork of PhantomJS which works with the newer releases of Selenium.
You can easily implement this by editing the pom.xml file and swapping
<groupId>com.github.detro</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>${phantomjs_version}</version>
with
<groupId>com.codeborne</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.2.1</version>
You can use a headless chrome driver with selenium, as showed here:
https://duo.com/decipher/driving-headless-chrome-with-python

What is the compatible version of Selenium RC with Selenium IDE 2.5.0?

I have installed the selenium ide 2.5.0 add-on for firefox and after exporting the test case as Java/JUnit 4/ Web Driver. When I try to execute it with JUnit testing I always get exceptions when some class from selenium is not found. I have used selenium-api-4.2.0.jar and selenium-server-stendalone-2.42.2.jar. Than I have also tried switching from selenium-api-4.2.0.jar to selenium-api-2.42.2.jar but there always a class missing.
Which is the correct selenium-api and selenium-server-stendalone Jar to use for the 2.5.0 IDE?
Thnx in advace
This graphic in the documentation shows you how all the jars relate to each other. The selenium-server-standalone by itself contains all of those and all the dependencies.
Selenium IDE does not export code that uses the Selenium-RC API, it only uses Selenium WebDriver API.
Generally, unless you are doing something very particular, you want to use the latest stable release of everything.
If you still have problems, have a read through this, post your code, post your error messages.

A GUI to debug phantomjs script

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