Automated regression testing of Chromecast using Cucumber, JRuby and Rukuli

As you may know, i work as a Developer In Test for Media Playout at the BBC. We enable audio and video playout on the web (desktop, tablet and mobile) using our Standard Media Player.

We recently added support for Chromecast, and i want to write a bit about how i automated testing for it.

Chromecast HDMI dongle

Chromecast HDMI dongle

Chromecast is a HDMI dongle that plugs into a normal television and adds connected TV functionality. The neat thing is you can control it from your laptop, tablet or mobile using the media apps that you already know, such as YouTube, Netflix and now BBC iPlayer. Google also provides an API so that new Chromecast apps can be written all the time.

So how do you test a Chromecast? Well, personally i like to test things from an user’s point of view, actually clicking things and observing what happens as a result. But there’s only so far you can take this. I don’t want to rely on a television having a Chromecast being plugged in all the time and on the same network so that i can talk to it.

Though i’ve got to say .. it would be quite awesome to use a television 2 metres wide for my automated regression testing! :p

About to start casting

About to start casting

I didn’t need to test the Chromecast receiver app; that had already been written and tested by the guys in Salford for use by the iOS iPlayer app. I realised, what we actually care about is the communication between our player and the Chromecast. And there is a well documented Chromecast API. So with the help of colleagues Tim Hewitt and Wyell Hanna, i set about creating a fake Chromecast. Pretty much a bit of javascript that would respond in the same way as a real Chromecast, so that we could test how our player would respond to it.

And now i present to you .. the fake Chromecast!

https://gist.github.com/sermoa/10988494

A lot of it is empty methods that are neccessary to the API. But there are some neat tricks here too. I’ll talk you through a few of the more interesting bits.

Firstly we need to load the fake Chromecast into the page. We can achieve this with a @chromecast tag and a Before hook.

Before('@chromecast') do
  $chromecast = Chromecast.new
end

My Chromecast class has an initialize method that inserts the javascript into the page.

class Chromecast

  def initialize
    $capybara.execute_script <<-EOF
      var el=document.createElement("script");
      el.type="text/javascript";
      el.src = "https://gist.githubusercontent.com/sermoa/10988494/raw/82e08c5a29b5689b5e9f3d03c191b8c981102d85/fakeChromecast.js";
      document.getElementsByTagName("head")[0].appendChild(el);
    EOF
    @media_alive = true
  end

end

With this in place, so long as i set up our player with the relevant business logic that says casting is available, when i hover over the player, i get a cast button!

  @chromecast
  Scenario: Chromecast button appears
    Given Chromecast is available
    When I play media
    Then I should see the Chromecast button
A cast button appears!

A cast button appears!

So how does that work? I assure you, i don’t have a Chromecast on the network right now. I’m not using the Google Chrome extension. I’m actually running it in Firefox! What is this voodoo?!!

Have a look at the fakeChromecast.js file:

window.chrome = {};
window.chrome.cast = {};
window.chrome.cast.isAvailable = true;

See that? We’ve set up a Chromecast and said it’s available! Sneaky, hey? It’s that easy, folks! :)

The Standard Media Player will now attempt to set up a session request with its application ID. That’s fine: we’ll happily enable it to do its thing.

window.chrome.cast.SessionRequest = function(a) { }

Obviously a real Chromecast does something rather significant here. But we don’t have to care. This is a fake Chromecast. We only provide the function so that it doesn’t break.

Next, the media player makes a new ApiConfig. It’ll pass the session request it just obtained (in our case it’s null, but that doesn’t matter), and two callbacks, the second being a receiver listener. That’s the important one. We want to convince it that a Chromecast is available, so we trigger this callback with the special string “available”.

window.chrome.cast.ApiConfig = function(a, b, c) {
  c("available");
}

So Chromecast is available. Now suppose the user clicks the button to begin casting. This should request a session.

  @chromecast
  Scenario: Click Chromecast button and connect to a session
    Given I am playing media
    When I click the Chromecast button
    Then I should see Chromecast is connecting
Connecting to Chromecast

Connecting to Chromecast

How did we do this? Easy! The media player requests a session, sending a success callback. Fake Chromecast store a references to that callback – on the window so that we can trigger it any time we like! The callback function is expected to provide a session. We send it a reference to a fake session, which is entirely within our control. Oh it’s all so much fun!

window.chrome.cast.requestSession = function(a, b) {
  window.triggerConnectingToCC = a;
  window.triggerConnectingToCC(window.fakeSession);
}

As the documentation says, “The Session object also has a Receiver which you can use to display the friendly name of the receiver.” We want to do exactly that. We decided to call our fake Chromecast Dave. Because Dave is a friendly name! :)

window.fakeSession = {};
window.fakeSession.receiver = {friendlyName:"dave", volume:{level:0.7}};

I think i found our app expected the session receiver to supply a volume too, so i added that.

The media player does some shenanigans with media that we don’t need to care about, but when it sends a request to load media it passes its callback to trigger when media is discovered by Chromecast. That’s another important one for us to keep, so we store that one. We wait 1 second for a semi-realistic connection time, and then trigger it, passing a reference to .. fake media, woo!

window.fakeSession.loadMedia = function(a, b, c) {
  window.pretendMediaDiscovered = b;
  setTimeout(function() {
    window.pretendMediaDiscovered(window.fakeMedia);
  }, 1000);
}

And now we are almost there. The last clever trick is the communication of status updates. The media player sends us a callback it wants triggered when there is a media status update. So we store that.

window.fakeMedia.addUpdateListener = function(a) {
  window.updateCCmediaStatus = a;
}

The magic of this is, we stored the references to fakeMedia and fakeSession on the browser’s window object, as well as the callbacks. This means the test script has access to them. Therefore the test script can control the fake Chromecast.

So you want Chromecast to report playing? Make it so!

  @chromecast
  Scenario: Begin casting
    Given I am playing media
    When I click the Chromecast button
    And Chromecast state is "PLAYING"
    Then I should see Chromecast is casting
We are casting!

We are casting!

What does that mean, Chromecast state is “PLAYING”? It’s pretty straightforward now, using the objects and callback functions that the fake Chromecast has set up:

When(/^Chromecast state is "(.*?)"$/) do |state|
  $chromecast.state = state
  $chromecast.update!
end

Those two methods get added to the Chromecast Ruby class:

class Chromecast

  def initialize
    $capybara.execute_script <<-EOF
      var el=document.createElement("script");
      el.type="text/javascript";
      el.src = "https://gist.githubusercontent.com/sermoa/10988494/raw/82e08c5a29b5689b5e9f3d03c191b8c981102d85/fakeChromecast.js";
      document.getElementsByTagName("head")[0].appendChild(el);
    EOF
    @media_alive = true
  end

  def state=(state)
    @media_alive = false if state == 'IDLE'
    $capybara.execute_script "window.fakeMedia.playerState = '#{state}';"
  end

  def update!
    $capybara.execute_script "window.updateCCmediaStatus(#{@media_alive});"
  end

end

Note that i had to do something special for the “IDLE” case because the media status update expects a true/false to indicate whether the media is alive.

So, using these techniques, sending and capturing events and observing reactions, i was able to verify all the two-way communication between the Standard Media Player and Chromecast. I verified playing and pausing, seeking, changing volume, turning subtitles on and off, ending casting, and loading new media.

This fake Chromecast is a lot faster than a real Chromecast, which has to make connections to real media. It’s also possible to put the fake Chromecast into situations that are very difficult to achieve with a real Chromecast. The “IDLE” state, for example, is really hard to achieve. But we need to know what would happen if it occurrs, and by testing it with a fake Chromecast i was able to identify a bug that would likely have gone unnoticed otherwise.

For the curious, here’s a demo of my Chromecast automated regression test in action!

This is all a lot of fun, but there is nothing quite like testing for real with an actual Chromecast plugged into a massive television!

Testing Chromecast for real

Testing Chromecast for real

So that’s how i test Chromecast. If you want to test Chromecast too, please feel free to copy and tweak my fakeChromecast.js script, and ask me questions if you need any help.

Motorhome Road Trip: The final day

It’s been nearly a week since returning from the epic road trip, but i’ve been busy getting back into my music every night this week, so here’s my first chance to catch up on what happened on the last day of the trip.

We woke up in Newport and took our time getting going. We had a little look around Newport but i was very disappointed. I thought it would be a tourist town, but it’s not at all. In fact, on a rainy sunday morning it feels like a ghost town. So many shops have closed down, it’s quite shocking!

Anyway, so we went over the bridge towards Bristol and Bath, but we didn’t stop at either because we had somewhere more exciting to visit. The tiny village of Lacock.

Seriously, Lacock is beautiful. A place of quaint old cottages like this:

A cottage in Lacock

But what we were really there for was Lacock Abbey, for its history of filming for Hogwarts. It is wonderful. The ceiling in the Chapter House is so distinctive, you just know it’s the Mirror of Erised room the moment you walk in.

Chapter House, Lacock Abbey

The Sacristy next to it was Snape’s dungeon in the first movie, we think.

The Sacristy, Lacock Abbey

And then you find the Warming Room, which may have been Professor Quirrell’s classroom. They’ve made the most of the association by putting a huge cauldron in the middle of the room!

Warming Room, Lacock Abbey

I also saw some pictures up around Lacock Abbey that showed filming at Durham Cathedral, making out as if it was done at Lacock. I mean, certainly the cloisters are similar, but the shapes at the top of the windows are different, which is immediately obvious as soon as you compare the photos to what you see in Lacock Abbey!

The Cloisters, Lacock Abbey

Still, they are very beautiful, and have very much a Hogwarts feel, whether these locations were actually used for the movies or not.

The Cloisters, Lacock Abbey

On the way out of Lacock, we had a real treat! This is the house used by Slughorn that is seen in Half Blood Prince.

Slughorn's House in Lacock village

I think it’s quite interesting that they came back to Lacock to film again, even though they didn’t use the Abbey again after the first two films. I guess it got too expensive, or they just preferred to use Leavesden studios.

So from there we made our way back to London. I had an amazing time, but i was really happy to come back to streets i recognise, and back to a campsite i know and love. It has been really good to get back into my normal life again.

My iPhone shows a nice map of where we went.

Map of the motorhome road trip

I think we travelled over 1,400 miles! We saw some great sights along the way, and met up with some lovely people! Thanks to everyone who met us and showed us around. It was brilliant.

Motorhome Road Trip: Chester

Yesterday morning we were very privileged to have Matt give us a personal guided tour of Chester.

I love the city of Chester, because it feels so old and steeped in history. It might have been intended to be the capital city at one time. Unfortunately, there’s a lot of 60s and 70s buildings right alongside architecture that is hundreds of years old, which makes Matt pretty angry! But the old stuff is lovely!

The cathedral:

Chester Cathedral

The town hall:

Chester town hall

A lovely walk along the old city wall, looking out towards Wales in the distance:

Chester city wall

Chester abbey is just brilliant. So brilliant i had to give it the monochrome filter! :p

Chester Abbey

The high street is also lovely, feels so old. Reminds me quite a lot of Winchester, actually.

Chester high street

We had a fantastic time in Chester, i’m so glad we were able to include it on our trip, and thanks ever so much to Matt for showing us around.

We also began a very exciting secret project, that i’m hoping will soon become not-secret! Watch this space for news! :)

After that we made the long, pretty journey down to South Wales, and had a very good pub crawl around Cardiff for the night, guided by my lovely friend Hannah.

The best thing was finding Ianto’s Shrine in Cardiff Bay!

Ianto's Shrine, Cardiff Bay

The motorhome road trip was almost over but there was one more very special place to visit. I’ll save that for another blog post!

Motorhome Road Trip: Liverpool

Yay! Today was mostly spent in Liverpool. After a great night out in Manchester last night, we took our time getting up, and then got on our way.

Liverpool turned out to be nicer than i expected. I’d been there before and not thought too much of it. Today i found i really liked the architecture, the water, the diversity of alternative culture, the general feeling of inclusivity, particularly how it seemed to embrace gay culture as perfectly normal and just part of the city.

The Port of Liverpool Building is particularly impressive.

Port of Liverpool Building

I really liked Albert Dock too. We had a look in the Tate Liverpool there.

Albert Dock, Liverpool

When exploring cities, we have tended to look for the tattoo and piercing studios. Partly because we like tattoos and piercings, but also because it gets us out of the main shopping areas and into the less mainstream areas. Otherwise i feel like every city is pretty much the same, with the same shops and restaurants and coffee shops. I like to see the unique characteristics of each city.

In Liverpool, i particularly liked Gostins Arcade, full of alternative shops and seemed a general hangout place for different sorts of people. It is such a refreshing change from the commercialism of most big cities.

Anyway, so from Liverpool we journeyed into Wales. I have always wanted to take my motorhome to Wales, and this is the first time i have. I love the bilingual sign posts, and trying to understand how they get from “Services” to “Gwasanathaeu” and chuckling at how they feel the need, every time they write “Wrexham”, to also write “Wrecsam” :)

I am delighted to see the Caravan Club fully embracing the bilingual signposting, too!

Bilingual signs at Welsh Caravan Club

So tonight there is not a lot to do in deepest darkest North Wales, so we’re going to watch a Harry Potter, sleep early, and get up early for more adventures tomorrow!

Two days left of our trip! Please follow us on twitter: @sermoa and @findthepilgrim. Use the hashtag #motorhomeroadtrip to keep up with us!

Motorhome Road Trip: Scotland!

Well, we had 3 excellent days in Scotland.

New year’s eve, we spent the whole day looking around Edinburgh. Starting with breakfast at The Elephant House, one of the cafes where Jo Rowling wrote Harry Potter and the Philosopher’s Stone. Somebody took this photo years ago, probably not knowing how significant it would become:

Jo Rowling writing at The Elephant House

So Liam went to sit at the same spot!

Liam in The Elephant House

The toilets of that cafe are COVERED with Harry Potter related graffiti. Quotes from the books, people’s favourite moments, messages of gratitude to Jo. It was lovely to see!

Harry Potter graffiti at The Elephant House

We had lunch at The Spoon bistro, another venue that Jo used to visit. And we went past the Balmoral Hotel, where Jo finished writing Harry Potter and the Deathly Hallows and famously signed a bust to celebrate! :)

New year’s eve celebrations in Edinburgh were excellent fun, and the fireworks were fantastic; we saw them from the South Bridge.

New year’s day we drove to Strathclyde, and then it was pretty much a day of recovery. We lay in bed and watched movies for most of the afternoon, and watched the new Sherlock episode!

Yesterday morning we went into Glasgow. I had really no idea what to expect from Glasgow, but i found it felt quite like Southampton. We were delighted to find a real police box in the high street!

Police box in Glasgow

Glasgow is pretty industrial, but the river Clyde is nice.

River Clyde in Glasgow

Our last experience of Scotland was a stop off at a service station just before we reached the border.

From there we drove through the pretty hills around the edge of the Lake District, and made it to Manchester for a great night out with some of my friends from BBC Sport.

Today we’re going to Liverpool, and we’ll sleep in Wrexham, Wales tonight. Tomorrow it’ll be Chester, then driving down to South Wales and a night out in Cardiff. The next day we’ll visit Bristol, Bath, Lacock and Oxford before returning to London.

Please follow us on twitter: @sermoa and @findthepilgrim. Use the hashtag #motorhomeroadtrip to keep up with us!

Motorhome Road Trip: Durham to Edinburgh

Wow, today was a very exciting day! Our fist stop was Durham.

View of Durham

The main attraction was the cathedral, because of its use in the first two Harry Potter movies. Before we went in i spied this very attractive knocker on the door.

Knocker to Durham cathedral

The courtyard was beautiful. Instantly recognisable.

Durham cathedral courtyard

The corridors around the outside of the courtyard were also used extensively in the first two movies. Most of the cast have walked down here.

Durham cathedral

Professor McGonagall’s classroom is Chapter House, sadly closed to the public today but we got a peek through a window.

Chapter House, Durham Cathedral

I also found the castle quite appealing.

Durham Castle

We journeyed on. I had to take a detour at Gateshead to show Liam the stunning Angel Of The North sculpture by Antony Gormley.

Angel Of The North

The Angel has a lovely view.

View from The Angel Of The North

Our next stop was Alnwick Castle in Northumberland. We knew it would be closed, and the light was fading fast by this point, but this is as close as we managed to get.

Alnwick Castle

It is another location used for the first two movies, particularly the flying lessons.

We stopped for a while in Alnwick to eat grilled cheese! :)

Then we got a club mix on loud and traveled on up into Scotland. We cheered when we crossed the border! We made it to Edinburgh and have found a nice place to park for two nights. Tomorrow we’ll see all the best sights in Edinburgh, including the cafe where Jo began writing Harry Potter, and the hotel where the series was concluded. And we are massively looking forward to Hogmanay in Edinburgh!

For tonight though, it’s time for a well deserved drink!

Time for a drink!

We have a long way still to go next week: Glasgow, Manchester, Liverpool and down through Wales to Cardiff and Newport, then across to Bristol, Bath and Oxford before heading back to London.

Please follow us on twitter: @sermoa and @findthepilgrim. Use the hashtag #motorhomeroadtrip to keep up with us! If we’re passing your way, tweet us and we might manage to meet up with you!

Motorhome Road Trip: Through the Yorkshire Moors

Wow. Today was an epic motorhome adventure! Saw some amazing scenery, met a friend by surprise, got lost a few times, visited some historic Harry Potter landmarks!

We have found quite a nice routine now. We wake up about 7am, have breakfast and a shower, hit the road by about 9am. Spend the day driving, exploring, taking photos. Find the campsite for the night, cook some dinner, then settle into an evening of drinking and watching Harry Potter movies!

So this morning we saw more of Sherwood Forest .. more than intended, actually, thanks to the very limited 3G and GPS signals! We had to resort to the paper atlas to help find the way to York.

We took the Park & Ride in York and were soon admiring the delightful sights, such as the River Ouse.

River Ouse

I was drawn towards The Shambles, and i wasn’t disappointed. It reminded us strongly of Diagon Alley!

Diagon Alley?

I loved some of the crooked buildings in that street. For the first time, the “antique” filter turned out to be quite appropriate!

Crooked buildings in The Shambles, York

We even saw a street that looks like it leads to Knockturn Alley:

This way to Knockturn Alley

We had a very happy chance meetup with @tweetyaca who happened to be in York at the same time .. who gave us a tip about the best place to stand for a great view of York station:

York train station

Our next stop was Goathland railway station. Liam asked me weeks ago if we could go there. I saw that it could be more-or-less on our route up north, so i said, “Yes, sure!” All i knew was that it was in the Yorkshire Moors and that i should probably fill up with fuel before we went there!

I had a feeling the Yorkshire Moors would be quite good scenery, but even i found myself breathtaken by the miles and miles of stunning hills and moors. Thanks to Liam for taking this photo while i was too busy looking where i was going and trying not to fall off the edge of the cliffs!

Yorkshire Moors

It took about an hour of driving through remote moorlands until we came to Goathland, a tiny village with a most beautiful train station.

We were very lucky to be there when a train pulled into the station, looking very much like the Hogwarts Express. You almost expected Hagrid to arrive and say, “First years this way!”

Goathland station

I’m so glad we went to Goathland, it was very good to get off the motorways and into the remote countryside, to see those views and visit that iconic station.

Tonight we made our way north, out of Yorkshire and into Teeside, somewhere near Middlesborough. This will make a very pleasant stop for the night, and tomorrow we’ll go on into Durham, up through Newcastle and up the north-east coast, continuing our journey towards Edinburgh.

But for now, it is the time to relax. We know exactly how to do that!

Time to relax!

As i’ve said before, here is a map of all the places we intend to visit: Liam and aimee’s Motorhome Road Trip.

Please follow us on twitter: @sermoa and @findthepilgrim. Use the hashtag #motorhomeroadtrip to keep up with us!

If you’re along our route and would like to meet, tweet us and we’ll see if we can meet .. if we like you, of course! ;)

Motorhome Road Trip: Cambridgeshire to Nottinghamshire

So we woke up this morning and had pancakes with bacon and maple syrup for breakfast. An excellent way to begin any day, but especially good for a day of adventures!

Bacon and maple syrup on pancakes

We went for a brief explore of Cambridge. It had to be brief, because the only place i could find to park a 3 metre high motorhome was a 1 hour maximum stay on a street. So we rushed round and saw the colleges and the river Cam …

College in Cambridge

River Cam

Cambridge has some interesting architecture. Look at the mashup of brickwork in this building!

Intereting brickwork in Cambridge

Our hour being up, we returned to Drifter and headed towards Peterborough. The scenery on the way was so beautiful, i just had to stop in a layby, climb up on my roof and take this photo!

Scenery in Cambridgeshire

We spent a good deal of time in Peterborough library doing some family history research for Liam, which went well.

The centre of Peterborough still felt quite Christmassy and i loved the ferris wheel!

Centre of Peterborough

We took an hour out to visit my grandparents who live near Peterborough, and then we journeyed on to Nottinghamshire.

Tonight we are actually staying inside Sherwood Forest. I couldn’t believe us when Google maps directed us right into Clumber Park, with a gated entrance, looking completely dark inside! We got a bit lost in the thick forest, which was kinda spooky! But soon enough we found the Caravan Club site where we’ll stay the night. There is no 3G here so my magical internet box doesn’t work, but we’re just about coping on the Caravan Club wifi!

Tomorrow we’ll travel through the Yorkshire moors, the highlight being Goathland railway station, which is the station used for Hogsmeade in the Harry Potter movies. From there we’re heading up towards Durham.

As i said yesterday, here is a map of all the places we intend to visit: Liam and aimee’s Motorhome Road Trip.

Please follow us on twitter: @sermoa and @findthepilgrim. Use the hashtag #motorhomeroadtrip to keep up with us!

If you’re along our route and would like to meet, tweet us and we’ll see if we can schedule in a stop!

Motorhome Road Trip

Well hello to you dear readers!

As you probably know, one of the most unusual things about me is that i live in a motorhome. I find it a great joy to keep moving, never settle somewhere, rock up anywhere and have everything i need with me in my van. It’s great.

Here’s my home on a typical weekend away travelling ..

Drifter

I’ve always wanted to do a road trip around the UK, and as my friend Liam is currently visiting me from Chicago, this is the perfect opportunity. Liam wanted to be in Edinburgh for New Year, and i know you can drive to Edinburgh in a day .. but i just thought, what if we took our time, visited lots of places along the way? I booked up several campsites and we’re taking two weeks to tour England, Scotland and Wales.

I picked up Liam from Heathrow on Christmas Eve. Our first trip was to Kent, with our mascot, Bouncy Santa hanging from the rear view mirror!

Bouncy Santa

The first night, Liam had pretty bad jetlag, and quickly found out that my bed is a nice cosy place to sleep!

Sleepy Liam

We spent Christmas Day with my mum in Kent, Boxing day with my dad in Essex, and then today our road trip began for real.

Liam feet up

We journeyed from Essex through Hertfordshire, to Cambridgeshire, land of flat farmlands. We saw this pretty amazing water cleaning tower along the way.

Water cleaning tower

Tomorrow we will visit Cambridge and Peterborough, as we travel on to Nottinghamshire. I’m hoping we’ll have some time to stop and take some great photographs. As we’re both Harry Potter fans, we’ll visit some of the film locations along the journey.

Here’s a map of the places we intend to visit: Liam and aimee’s Motorhome Road Trip.

Please follow us on twitter: @sermoa and @findthepilgrim. Use the hashtag #motorhomeroadtrip to keep up with us!

If you’re along our route and would like to meet, tweet us and we’ll see if we can schedule in a stop! You might even get some sausage and eggs cooked in my van! :)

Getting chromedriver to work with Ruby selenium-webdriver under OSX Mavericks

I interrupt my soprano-saxophone-and-bass-guitar-playing evening to write very quickly about something that annoyed me today. I can’t find the fix anywhere else on the internet, so i guess it’s up to me to provide the solution.

Yesterday i upgraded to OS X Mavericks. Which is nice. Free upgrade, woo! Most things work well, though i had a few Java version issues.

Today i found that selenium-webdriver was not able to launch Chrome with chromedriver. It would open and immediately quit.

A quick google reveals that the workaround is to start chromedriver with the --verbose flag and then it magically works again. Which is true in my experience. But all the examples are for selenium wedriver called by Java or Python and i couldn’t find one for Ruby.

The first thing i did was upgrade selenium-webdriver gem to 2.37.0 and chromedriver to 2.4. I checked my version of Chrome; it is 30.0.1599.101 which is apparently up to date. When none of those things made any difference, I investigated the verbose option.

I thought i would just have to pass --verbose to the Capybara::Selenium::Driver via the args or switches option. But no. That will send the flag to Chrome when it launches, but i need the flag to be set on chromedriver.

Ruby open source to the rescue!

I poked around in the source code for service args and found this:

# selenium/webdriver/chrome/bridge.rb

module Selenium
  module WebDriver
    module Chrome

      class Bridge < Remote::Bridge

        # ...

        def extract_service_args(opts)
          args = []

          if opts.has_key?(:service_log_path)
            args << "--log-path=#{opts.delete(:service_log_path)}"
          end

          args
        end

        # ...

      end
    end
  end
end

Hmm, so the only service arg you can set is the --log-path. That’s no good.

Ruby monkey patching to the rescue!

In my cucumber features folder i made a support file to monkey patch that method, and add a possibility of sending any service args i like.

# features/support/selenium_webdriver_monkey_patch.rb

module Selenium::WebDriver::Chrome
  class Bridge
    def extract_service_args(opts)
      args = []
      args += opts.delete(:service_args) if opts.has_key?(:service_args)
      args << "--log-path=#{opts.delete(:service_log_path)}" if opts.has_key?(:service_log_path)
      args
    end
  end
end

Now in my env.rb file i just have to require the monkey patch file and i’m able to send the verbose flag.

# features/support/env.rb

# ...

require 'selenium-webdriver'
require 'selenium_webdriver_monkey_patch'

# ...

Capybara.register_driver :selenium_chrome do |app|
  Capybara::Selenium::Driver.new(
    app,
    browser: :chrome,
    service_args: ["--verbose"])
end

# ...

Hey presto, now i can set the verbose flag on chromedriver, and sure enough, it works. I am testing in Chrome again.

It seems a really horrible hack, and i hope a better solution is found soon, either from a Mavericks update, or chromedriver, or maybe selenium-webdriver will add this option for service args in a future version.

I still don’t really know why verbose works when normal mode does not. But there we go. I can test again tomorrow, and that makes me happy!

Now, back to my bass guitar! :)