Is it possible to use Selenium WebDriver to drive PhantomJS? - selenium

I’m going through the documentation for the Selenium WebDriver, and it can drive Chrome for example. I was thinking, wouldn't it be far more efficient to ‘drive’ PhantomJS?
Is there a way to use Selenium with PhantomJS?
My intended use would be web scraping: The sites I scrape are loaded with AJAX and lots of lovely JavaScript, and I’m thinking this setup could be a good replacement for the Scrapy Python framework that I’m currently working with.

PhantomJS now includes the GhostDriver project.
You are also suggested to use PhantomJS directly or with a convenience library such as CasperJS. CasperJS is specifically designed to make it easy to do sequential operations to web pages, perfect for many automation tasks.
Disclaimer: I am the author of PhantomJS.
Edit: As noted in Nick's answer, GhostDriver is now included in PhantomJS.

#Joseph, since the 1.8 release GhostDriver is included in the stable release of PhantomJS. Here is the exact release notes: http://phantomjs.org/release-1.8.html.
You can simply start PhantomJS process to listen on some port, like this:
phantomjs --webdriver=PORT
Kudos to #detro and PhantomJS team for awesome work!

Related

Do we have interactive mode in selenium webdriver?

I am a newbie to Selenium.I want to know do we have any interactive mode to automate Selenium webdriver.Because i want to test each and every line is correct or not while automating.I have Automated Watir earlier,i have used "irb" to interact with.Please help me do we have any similar kind of mode in Selenium webdriver.
IRB is nothing Watir specific it is just an interactive ruby shell (IRB = Interactive Ruby Shell) and thus you can also use it to work with Selenium. You only need the selenium-webdriver gem and then you can start.
You can also find a good getting started tutorial here: http://aspyct.org/blog/2012/09/09/functional-web-testing-with-selenium-and-ruby/
I'm sorry if this topic may feel so old, but I have an idea for this.
You can use the python interpreter in the terminal and type each line:
from selenium import webdriver
b = webdriver.Firefox()
b.get('https://www.google.com')
And so on :)
I use a debugger (byebug gem) to stop tests at the point where I need to continue the automation interactively. I prefer to have all gems, modules, and classes available when I hit the breakpoint.
I also wrote a couple methods that will reload page object classes from the commandline/breakpoint. I can add a new method, reload, and verify it works, and move on to the next action; all without restarting the test.

is this testing setup correct/possible selenium IDE, ghostdriver, phantom.js, grid and php-webdriver correct?

I would like to run many instances of phantomjs at once. The reason I would like to use phantomjs rather than selenium with firefox/chrome/ie is the cookie separation and the ease of using proxies if every needed (some of our systems will need to be accessed from different IP's). Plus phantomjs seems much slimmer/faster than browsers with "heads".
I would also like to generate the test scripts using selenium IDE (I've experimented with Resurrectio+casperjs its good but selenium seems better) then run them as PHP using php-webdriver.
I've been trying to understand how all these pieces fit together so is would this process work....
Generate the test scripts in selenium IDE with firefox then export them to python
Convert this Python script to a facebooks php-webdriver version. Looks like I'll have to manually do this?
Run Phantom.js with this php script and point it at the selenium java server to execute the script.
Is this all correct? Can I run multiple instances simultaneously on once machine? Will I need grid? Where does ghostdriver fit in all this!?

Browser emulation - Which Selenium do I need?

I am struggling to get a RemoteWebDriver to work.
I wondered whether I needed Selenium RC, so I installed that with Nuget and noticed that DefaultSelenium takes a path to the browser as a parameter.
I am getting a bit overwhelmed with all the different libraries available for Selenium - but what I want is to be able to run against a host of browsers (android/chrome/firefox, etc) without those browsers necessarily existing on the machine that Selenium is running on.
Is that possible? And if so, which Selenium libraries would I need (I am using VS2012 and C#) to acheive this?
I was trying to achieve this with RemoteWebDriver with a range of different DesiredCapabilites, rather than using ChromeDriver, FirefoxDriver, etc.
You should, especially considering this is a new project, 100% absolutely positively use the WebDriver API. So you only need the WebDriver NuGet package:
http://www.nuget.org/packages/Selenium.WebDriver/
You will need the IEDriver package too, if you intend to test against IE, and the same for Chrome/Safari etc.
I say this because the WebDriver is constantly being developed on, maintained, and improved. It has a better cleaner and nicer API, and will be more stable in the long run.
RC is deprecated. Although I believe the developer's intend to still fix any bugs, new features and improvements won't be happening.
Try this has some good answers : Run Selenium tests in multiple browsers one after another from C# NUnit. I personal use IWebDriver and Selenium RC and test it like that. Cause i have a lot of tests and testing in every browser is to much for me.

Implementing selenium with Jenkins and PHPUnit

I'm trying to do set up some Selenium WebTests using PHPUnit, but php is no longer supported by Selenium IDE, does this mean I have to re-write all my tests into php in order to use this method?
I'm trying to set up a continuous integration system, but have never even used one before, I tried using jenkins-php.org but it wasn't very helpful.
The newer releasee Selenium IDE "claims" it does not support PHP,
But you can still convert your IDE to PHP or PHPUnit.
(In Selenium IDE) Option > Options > Enable Experimental Functions.
With this option checked you can switch your format under Options again.
You may still want to review your code.
Hope this helps and it is what you meant by "Selenium IDE does not support PHP".
I was able to find: https://addons.mozilla.org/en-US/firefox/addon/selenium-ide-php-formatters/
It allows output from Selenium to PHP, either PHPUnit format or Selenium Testing.
However after all this playing around it became apparent that the best way was to use htmlSuite, it has the most support when it comes to automation and seems to work out of the box, whereas PHPUnit testing requires lots of tinkering.
After a lot of hacking around it became apparent that the best solution is this tool:
http://www.enjoyxstudy.com/selenium/autoexec/index.en.html
It works out of the box, supports htmlSuite, works with windows and linux, runs most browsers, sends email reports, can get new tests from SVN, integrates with Jenkins well, and works with Selenium tests, its not PHP based tests but it works wonders compared to the other tools I tried out.
Really, so much easier, very user friendly, free and works out the box.

Front-end testing - tools Selenium RC

I am wondering what tool(s) do you use for front-end testing...
Currently I am using Selenium RC as tool to test the front-end. I am quite happy with the result as I managed to integrate it with the ms build process etc. The problem with Selenium tests is that they are not always reliable especially if you browse with something else than Firefox.
I am looking for open source alternatives (tools for front-end testing)?
I'd recommend TestPlan which can use Selenium as a backend, or HTMLUnit. It also allows you to do a myriad of other testing. It also works around several of the problems Selenium has, making it a bit easier to user than Selenium directly.
My experience shows, Selenium works the best from everything I tried. Even now I work with Firefox 6 and Selenium IDE works perfectly with it.
Together with selenium, we're also using twill. However, it is because of its speed and it is used only for "quick & fast" tests, I'm afraid not a lot of things are better then selenium out there.
On the other hand, I find Selenium quite reliable, even in another browsers - it's just hard to build tests in such way, to think about race conditions etc.
Have you heard of Watin ?
There is a great tool named cypress.
With cypress it is possible to write
End-to-end tests, Integration tests & Unit tests.
It is open source.
Learning curve is very low.
https://docs.cypress.io/guides/overview/why-cypress