Posts tagged ‘Chrome’

C# Selenium Integration Tests using Chrome Ghost PhantomJs headless driver

A lot has changed since my last post using Selenium to test web pages. Then you had to install a few things both on the client, browser and server. Today it has been simplified a lot. All you need really is the webdriver and you are in business. You can use the webdriver on your development machine and the server machine as well to run the Selenium tests. In my case I’m using the Ghost-PhanthomJS webdriver as I need to do headless testing ( no GUI ). Since it’s a lot harder to run tests automatically on the server if there is need for GUI, it will complicate things a lot, has to do with security restrictions etc.

Lets take a look at what is needed.
Create a new C# project in VS

Install xUnit Package Manger Console in VS using nuget.
Note I’m specifically using 1.9.2 and 2.0 as I know these two work on the build machine, I had trouble with other version combinations.
PM> Install-Package xunit -Version 1.9.2
Install xUnit VS Runner
PM>Install-Package xunit.runner.visualstudio -Version 2.0.0

Install the Chrome webdriver and libraries
PM> Install-Package WebDriver.ChromeDriver

Install the PhantomJS headless driver and libraries
PM> Install-Package PhantomJS

Then we write the test that will run after the build does the web deployment to the local server. The sample below just loads and checks for the title, then shuts down.

using System;
using Xunit;
using OpenQA.Selenium;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.PhantomJS;

namespace IntegrationTesting

    public class HelloIntegration
        // Proofs that google can be pulled up in the browser and has the right title
        public void GoogleCheckTitle()
            // Init
            IWebDriver driver = new PhantomJSDriver();

            // Test
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3));
            var title = driver.Title;

            // Proof
            Assert.Equal( “Google”, title);

            // Close down


If you are using TFS you also need to point your build agent to the xUnit runner, in my case I just check it in as part of the project and set it like that.
Path to custom test adapters

That’s all you need, then you can write your own tests to test specific functionality tailored to your needs. Selenium is pretty powerful for Integration testing.

My alarm clock

I figured it out the other day that I had stopped using the alarm clock.  I just got used to waking up after a good night sleep.  Then I had to take my son to 6.45AM ! hockey practice, in that case the alarm is man’s best friend.

I got this one in New York, in one of those electronic stores around Times Squire.  The sticker price was $22.50, I went deep in my pocket and came out with $15.  That’s all I got I exclaimed and started walking out.  But the clerk said to my astonishment.  That’s ok take it, $15 is good.  That was a nice bargain, I thought.  I still have it today 10+ years later.  Although the snooze button doesn’t work anymore.  The snooze is a scam anyway,  if the alarm goes off get up.

Here is the last clock that I bought, not that I really needed one.  I just though the binary clock was pretty cool.

I spent some time surfing tonight, here are some thoughts / links.

You heard about Chrome, right ?  Sorry, Chrome is long dead.

And what does the TCP header really look like.

Oz just got bought, I used to work at Oz before leaving for New York.

Walk down microsoft Windows memory lane

Message Computer in a bottle.

Cheers !