Agnes Ro, Confluence Developer

Last week, Matt Ryall and I have been trying to get a Selenium build up to test Confluence's Javascript features, especially the new drop down menus and page ordering tree. It wasn't easy, but I personally think it is definitely worth having these tests.

Below is a summary of the steps and problems we encountered in setting up the build.

1. Writing a Selenium Test

A few weeks back, I did a Selenium spike to see how easy it was to write a test that logged into Confluence and opened a add drop down menu. Surprisingly, this was very simple to do. I had to add the selenium client dependency in my test module and then used the Selenium Maven Plugin to start the Selenium server.

protected void setUp() throws Exception
{
  super.setUp();

  String serverLocation = "localhost";
  int serverPort = 4444;
  String browserStartString = "*firefox";
  baseUrl = "http://localhost:8080/confluence";

  sel = new DefaultSelenium(serverLocation, serverPort, browserStartString, baseUrl);
  sel.start();
}

public void testNewAddMenu() throws Throwable
{
  logInAsAdmin();
  assertEquals("Dashboard - Confluence", sel.getTitle());
  gotoPage("/display/" + TESTSPACE_KEY + "/Home");
  asserter.assertElementPresent("add-menu-link");
  sel.mouseMove("add-menu-link");
  assertTrue(sel.isVisible("createPageLink"));
  assertTrue(sel.isVisible("createNewsLink"));
}

2. Running the Selenium Test in Maven

During my spike, I also tried adding the selenium test I wrote above to the integration-test phase in maven. I had to add some config to start and stop the selenium server before running the tests.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>selenium-maven-plugin</artifactId>

  <version>1.0-beta-2</version>

  <executions>
    <execution>
      <id>start-selenium</id>

      <phase>pre-integration-test</phase>
      <goals>
        <goal>start-server</goal>
      </goals>
      <configuration>

        <background>true</background>
        <port>${selenium.server.port}</port>
      </configuration>
    </execution>
    <execution>

      <id>stop-selenium</id>
      <phase>post-integration-test</phase>
      <goals>
         <goal>stop-server</goal>

      </goals>
    </execution>
  </executions>
</plugin>

3. Selenium Test Infrastructure

Currently our acceptance tests do not have the best code infrastructure. For example, we have a huge AbstractConfluenceAcceptanceTest class that all the acceptance tests extend and it basically has everything in there. So it was nice to be able to start from scratch and split things out into separate classes. As we wrote more tests, we saw a lot of code duplication and realised how silly the DefaultSelenium client was. We ended up extending the default one to override methods with some sensible implementations. One example is the the client.open(url) method that opens the browser up in the provided url. In a test, you will always need to wait for the page to load before making assertions or clicking/typing on the page.

SeleniumClient
/**
     * Unlike {@link DefaultSelenium#open}, this opens the provided URL relative to the application context path.
     * It also waits for the page to load -- a maximum of five seconds before returning.
     */
    @Override
    public void open(String url)
    {
        super.open(contextPath + url);
        super.waitForPageToLoad(MAX_WAIT_TIME);
    }

The Selenium client also doesn't provide any convenient assertion methods. The Jira guys seemed to have a nice assertions class, so we just 'borrowed' it :) Ideally, we will have common code like this in a separate project.

4. Setting up the Bamboo build

To run the Selenium tests in a separate build, we wrote a new pom that only ran Selenium tests after Confluence setup. This was fairly trivial and passed on our local machine.

Up until this point, everything seemed surprisingly easy. Matt & I were starting to really like the Selenium tests... (You can actually see Firefox launched and it flickering through the tests!) However, it was when we actually setup and the build in bamboo that we started to hit a few problems.

Firefox wouldn't start in Bamboo

Since we got the tests running locally, we thought it wouldn't be much more difficult to run on Bamboo. The first problem we encountered when we kicked off the build was that firefox wouldn't launch and therefore not even run the tests. The first error message we got was something about the Selenium server being started on a headless system and was smart enough to suggest using the selenium:xvfb goal (also provided by the Selenium Maven Plugin). So we did as it said and modified the pom to started the Xvfb instance before starting the Selenium server.

After that, we got no other error message, but Firefox still wouldn't start. It would simply fail and eventually timeout. We got to a point where we could ssh into the bamboo box and manually run the maven command to run the tests on the bamboo boxes. Strangely this worked?! We decided to take a look at Jira's build and see what the difference was. This is when we realised that they were running a vncserver before the running the tests! It seems like bamboo doesn't have access to a console and this causing problems when Selenium tries to launch Firefox. As soon as we ran the build with a vncserver, we actually got the tests running - but not quite all passing...

Intermittent Test Failures

The annoying thing about Selenium is trying to guess how much you want to wait for things to load and appear before making assertions and continue on with the test. For example, when you click the 'Edit Labels' link on a Confluence page, the edit labels input div becomes visible. So how long do I need to wait in the test for it to become visible before actually testing? The wait time you specify to the Selenium client is a maximum wait time, however you still don't want to be waiting too long for a genuine failure. The problem is when you run the tests locally, you usually don't have to make the wait for very long (1~2 seconds). However, this is a different story on Bamboo. We decided to bump the default wait to 5 seconds and for extra slow pages (like the edit page) to 10 seconds.

The confluence.editor.ajax.disable Property

There was one other problem that I encountered, but is purely specific to Confluence. There was this one particular test that continuously failed when running the tests in maven but not in Idea. WHY? The only difference was that Confluence was started up by cargo through maven.... It took me a very long and frustrating few hours to figure out why...

Up until now, we haven't been able to test the ajax requests (known as 'heartbeats') that Confluence sends for concurrent edits to the same page. During our other test builds, apparently this continuous heartbeat being sent during tests were causing problems. So they decided to add a nice system property to disable this for our tests and was included in the parent pom of our test runner module. And guess what my failing tests was actually testing? It was testing for concurrent edits on the same page and thus relied on the heartbeats being sent... I have learnt my lesson and will always make sure to check the parent pom before using it blindly!

5. Watch the Build go Green

Despite all the problems we had, the 9 tests we wrote are passing right now :) The next step would probably be to setup a Selenium build with IE.... which should also be quite interesting...

seleniumbuild.png
Jonathan Nolen, Dir. of Developer Relations

UPDATE: corrected the closing time. It's 1pm PST, not 11am PST.

Just a quick note to remind everyone that Codegeist III closes this Friday, May 9th at 1pm PST. We've had a tremendous response so far: forty-one plugins! Go check out all the terrific entries. And if you're a user -- there's no reason that you can't start using these plugins yourselves right now! Developers, there are still a few days to get your entries posted and get feedback on your plugin. As many of the people who posted early have found, a few beta testers can be very valuable!

If you've already posted your entry, you might use these final days to polish your plugin homepage, your documentation and your tests. We'll use the homepages to understand what your plugin does -- so it's in your interest to make it as attractive and enticing as possible. Tell us why your plugin is great, and why we should find it useful. And be sure to add lots of screenshots! (Don't forget Skitch!).

As always, if you have questions or if I can help out with anything, please get in touch. I can't wait to see all of the Codegeist entries on Friday!

Edwin Dawson

... or, "Code Reviews for Fun and Profit!"

This is the story of Atlassians jumping at the chance to review computer game logic. I work on documentation for Atlassian's products, namely FishEye, Crucible and Clover. As a non-programmer, this is challenging. My main problem is that each of these is a powerful tool for elite programmers, and it's very difficult to place yourself in the shoes of a Wintermute-inspired old-school hacker, who has a strong need for some l33t tools, when this is perhaps the last thing you would have considered for yourself on a given day, between breakfast and morning tea.

In particular, Crucible. Crucible is a tool enabling peer reviews of code, which is of course an ennobling practice that fosters team development and allows spooky, pre-release bug detection. Logical bugs are caught so early, they rarely get a chance to crash anything. Weird!

So, my essential problem is that I don't have any regular impetus to participate in a code review. I've never contributed code in a team of programmers, and I certainly can't contribute much to a Java code review. So, while I was included in the Atlassian team's internal code reviews (as a new type of participant, the passenger ;-) ), I never really felt that my familiarity with Crucible was deepening. I wasn't invested in the work at hand.

As I always try to write documentation from a genuinely realistic experience using the product personally, I decided to set up my own Crucible instance and create a code review that the developers would attend. I've dabbled in Flash Actionscript programming, so as an example project I used the source code of a Pac-Man clone that I wrote.

Knowing the cachet of my auditing audience, I was fully expecting the Wrath of Hades to be unleashed, in that particularly cutting tone that the deeply intelligent reserve for the "box-of-hammers" ignorant. I expected the feedback to be short. I expected it to be brutal. In a word, I thought it was going to be nasty.

Most of the comments were sober. Some of them were amusing. But what struck me was the sheer sense of seriousness which the developers applied to the task. For them, code review is not a laughing matter, even when dealing with a half-baked piece of hackery that's been cobbled together with baling wire and duct tape. They maintained a professional, scholarly tone whilst no doubt stifling gales of laughter. Bravo, Atlassians.


Straight off the bat, my indenting was strafed for being less than ideal.

My indenting was strafed.

View image


The structure, after many attacks on its logic, began to resemble Swiss Cheese.

View image


Refactoring was called for.

View image


Some logic needed a visit from the Elegance Fairy.

View image


We learned something about Clamping.

View image


Remnants of old cruft were targeted for extermination. You must run a clean shop floor, when programming code.

View image


They liked the way my attributes and variable names had a certain poetic quality about them.

View image


We had a rare moment of cross-language insight.

View image


Capitalisation of certain letters is important.

View image


One reviewer deferred to the solutions put forth by another reviewer.

View image


The length of certain functions was flagged as smelly. Modularisation suggestions were also a recurring theme.

View image


Finally, mild confusion over bracket placement inspired a moment of mirth.

View image


Thanks for reading. Here's the Flash game in its compiled form:

Cheryl Jerozal, Developer

The beta version of the Bamboo Plugin for Confluence is out. The plugin provides several macros that allow Confluence users to easily display data from Bamboo, such as the status of a particular plan's latest build.

Examples

For example, including {current-build:CONFSTABFUNC-LDAP|mode=full} in your Confluence page would result in something like this:
current-build_full_medium.png


And using the macro {bamboo-project:CONFSTABFUNC} would display:
bamboo-project_medium.png


More examples can be found on the Bamboo Plugin homepage.

Try it, it's fun!

Try it out and let us know what you think.

Tim Moore, Developer

We'd like to invite everyone in the San Francisco, Boston, and Washington, DC areas to join us at the upcoming Atlassian User Group meetings. We've got a lot of great stuff planned:

  • Presentations by Atlassian and members of the community
  • A preview of the upcoming JIRA 4.0 in SF
  • A tour of the new JIRA Studio hosted development suite in SF and DC
  • Birds of a Feather sessions
  • Time to socialize afterwards with free food and drinks!

Plenty of Atlassian developers will be on hand to answer questions and just shoot the breeze.

These are all free to attend. Just sign up at http://confluence.atlassian.com/display/AUG/Atlassian+User+Group

Details

San Francisco Bay Area

Date May 1, 2008
Time Registration from 11:00am - 12:00pm
The User Group will be running from 12:00pm - 5:00pm
Location Stanford University
Schwab Residential Center, Vidalakis Room
680 Serra Street, Stanford, CA
Signup & Details http://confluence.atlassian.com/x/7QEQCQ

Washington DC Area

Date May 15, 2008
Time TBD
Location Near Infinity Corporation
1881 Campus Commons Drive
Suite 205
Reston, VA 20191
Signup & Details http://confluence.atlassian.com/x/7wEQCQ

Boston Area

Date June 12, 2008
Time TBD
Location TBD
Signup & Details http://confluence.atlassian.com/x/swIQCQ

P.S. We've still got space for more presenters in DC and Boston, so if you're interested in speaking at one of those events, please email Laura Khalil at lkhalil [at] atlassian [dot] com

Nick Pellow

skitchslapped

Nick Pellow talks about programming tools
April 22, 2008 10:19 PM
Cheryl Jerozal, Developer
Anton Mazkovoi, Lead Jira Developer
Jonathan Nolen, Dir. of Developer Relations
Michael Tokar, JIRA Developer