How to fast rewrite PhantomJS scripts for Headless Chrome? - phantomjs

Is there a simple/fast solution to rewrite PhantomJS scripts for Headless Chrome? Share a lifehack please.

puppeteer is the closest to the original Phantomjs in terms of terminology and syntax.

Related

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

Slow running acceptance test with php + codeception + phantomjs

I am moving to codeception 2.0.3 for doing some tests in various web platforms I am developing. I started doing some acceptance testing. Mainly check for pages ok and doing some form completions (sign in, sign up, nothing fancy).
I have been monitoring tests with firefox browser and we are moving now tests to a dedicated server so I switched to phantomjs as my testing browser.
Configuration in acceptance.suite.yml
WebDriver:
url: 'localUrl'
browser: phantomjs
window_size: 'maximize'
capabilities:
phantomjs.cli.args: ['--ignore-ssl-errors=true']
The thing is that with this headless configuration, tests are running very slowly. I mean, the test I wrote is checking that four links are OK (no error or exception message) without any fancy assertions (something which I can check in less than 20 secs) and it is taking more than a minute a half.
Am I missing something in the configuration of the testing stack? I read that phantomjs testing in this way is supossed to be fast and reliable something that can be integrated while developing but I don't seem to get it working right. I have been doing TDD in Smalltalk and maybe I am a little biased with the way that things work in that environment so maybe my expectations are too high but I had hopes that this could be a little more responsive and easy going.
I am using codeception 2.0.3 with phantomjs 1.9.7 on a linux box with php 5.5.
Any suggestion is welcomed. Thanks!!!
I had very slow running tests and started using strict locators. That sped up things a lot.
Instead of writing:
$I->fillField('username, 'john');
which will try and fail many locator types before actually working, specify the locator you are using and write:
$I->fillField(['id' => 'username'], 'john');
or
$I->fillField(['class' => 'username'], 'john');
or
$I->fillField(['css' => 'input .username'], 'john');
Read here: http://codeception.com/docs/04-AcceptanceTests#Click
Could be problem with phantomjs, usually headless with Codeception PhpBrowser goes very fast, try to switch to it.
For in-browser try to use Codeception WebDriver + latest selenium 2 standalone.
Also if you are developing with some framework, you can check if it is present in Codeception modules list. If so you can use it, it runs much faster than PhpBrowser since it does not need any server and works with symfony dom - crawler and browser - kit.
The size of the database sql file also matters. In my case import of some big tables caused more than minute of additional time.

Does phantomjs cover more than just chrome?

Phantomjs is webkit based. That means of the major browsers it's really only emulating Chrome, right? Does it provide a mechanism (or is there a way to force it) to provide sufficient test coverage for other browsers, aside from wrapping it in Selenium?
No. Current PhantomJS is a version of WebKit that is roughly equivalent to Chrome 13 or Safari 5.1, but it is neither of those browsers. (Chrome and Safari behave differently too.) (BTW, PhantomJS 2.0 is hopefully going to have the webkit separately linkable, so you can use different versions.)
If you move to using CasperJS, then your same script can (usually) run with each of PhantomJS and SlimerJS, which will give you test coverage for both WebKit and Gecko (Firefox). SlimerJS also allows you to directly use a local installation of Firefox instead of the supplied Gecko engine, if you wanted to test against different Firefox versions.

Selenium Junits on headless browser

I have recorded scripts through Selenium IDE and converted them to JUnit 4 Webdriver scripts.
Of course converted scripts had to be changed to run smoothly as Junits. Now my next goal is to make these scripts run on CI, So obviously I need some headless browser for this purpose. I found some threads, but I am looking for Junits specifically.
What could be the best solution/approach for this, any help in this regard is appreciated.
Take a look at PhantomJS. It is a headless WebKit-based browser and there is Selenium WebDriver for that called GhostDriver.
That's what i use and is OK but there is also the option of using a headed browser like Firefox or Chrome and then use Xvfb to ignore screen output.

Use phantomjs to drive chrome

Is there a way to use phantomjs to drive my firefox/chrome browser?
We have a bunch of casperjs tests, that I would like to run directly in the browser for debugging ( or just pure interrest ).
I seem to recall that a long time ago, before phantomjs became pure headless, I could do this by making it run on X instead of xvfb and removing/uncommenting the phantom.exit() line.
PhantomJs IS a browser, so the answer is no. You may want to look into Karma however.
You just use a config file which allows you to provide a browser to run your tests in:
Chrome
ChromeCanary
Firefox
Opera
Safari (only Mac)
PhantomJS
IE & Edge (only Windows)
SauseLabs, BrowserStack Electron, & more
Still, your tests will need to be written in QUnit, Jasmine, Mocha, ... which can be too much work to port from CasperJs.