Writing Selenium test steps for cucumber tests

In my current job, I’m responsible for developing a framework for performing UI testing of web and mobile applications with Selenium WebDriver/Appium, using the webdriver.io bindings for node.js Javascript. We have adopted cucumber as the format for defining the tests.

Conventional wisdom regarding UI testing holds that you should always strive to select UI objects by the attribute that is least likely to change. With web UIs, you’ll typically see a hierarchy of preferred selectors as the following:

  1. Element ID
  2. Element name
  3. CSS class(es) associated with the element
  4. Text associated with the element

If you used this strategy with cucumber, you would get tests that looked something like this:

Given I go to the login page
And I enter "johndoe" in the field with id "username"
And I enter "password1" in the field with id "password"
Then the input element with type "submit" should become enabled
And I click the input element with type "submit"

But such steps are counter to the principles of behavior-driven development. The primary purpose of cucumber is that it allows your business owner to write requirements that can also directly serve as tests, and identifiers such as element ID or name are artifacts of implementation details, not part of the basic requirements. Or more simply–your business owner should be able to describe interaction with the application using only what’s visible to them in the UI.

More typically, cucumber steps for the login scenario above would look something like this:

Given I go to the login page
And I enter "johndoe" in the "Username" field
And I enter "password1" in the "Password" field
The the "Log in" button should become enabled
And I click the "Log in" button

Note that the steps use the visible text associated with each element to select the element.

The argument against this approach is: “But whenever your UI text changes–and let’s face it, it often changes–you’ll have to go update every single test!” While this is true, my rebuttal is that it’s a simple global search and replace change, and more importantly, it’s not a change to the code behind the cucumber, only to the cucumber test definitions, which, in my opinion, is a lower risk change than an actual code change.

To be fair, as the number of tests grew, I saw the redundancy between tests as a maintenance risk, so I’ve abstracted out frequently used functions, such as login and navigation, into single steps. Steps like the examples above no longer exists in our codebase. Instead, we have single steps such as:

Given I log in as username "johndoe" and password "password1"

So, now, if the text on our login page changes, we only have to change it in one place.

In my next blog post, I’ll show some of the code behind these steps.

UPDATE: Here is the next blog post.

Underestimating myself

I’m a self-taught programmer; I’ve never done it full-time. Most of the QA jobs that I have had over the years have included some amount of scripting and/or automated testing work, but it’s always been done alongside other QA tasks. When I was job hunting last year, I concluded that if I really wanted to remain competitive in my career, my next job needed to focus solely or primarily on writing test automation. Plus, I love to code, and I thought I would really enjoy such a job.

During my job hunt, my standard line about my coding skills was: I’m a decent coder, but because I’ve never done it full-time, I’m probably not qualified to fill a role where I’m the person primarily responsible for the development of an automation framework. When I interviewed here at Netspend for a senior automation developer job, I was told that they were seeking someone with a strong automation background but that they were less concerned whether the candidate knew the language being used, node.js/Javascript. Since node.js is a fairly new framework, and since Javascript is rarely used in automation, they (accurately, in my opinion) didn’t expect to find a candidate who had node.js/Javascript experience. Furthermore, they assumed that any qualified candidate could pick up the language.

It turned out that those were perfect expectations for me. During my interviews here, the interviewers were impressed with my extensive knowledge and experience with automation, and I passed their general programming tests. In regard to programming skills, they were more interested in my thought processes and logic than producing accurate code in the spur of the moment on a whiteboard. Plus, I did have a distant background with Javascript (not just in the browser; it was also the programming language of an automation tool that I used many years ago).

Now that I’ve been here at Netspend for about 8 months and developed a framework and automated tests for UI-testing, I’ve discovered that I misapprehended the skills that are necessary for building an automated testing framework. When I said I was probably not qualified to build an automation framework, I was thinking primarily of coding skills. I have learned the Javascript syntax and the node-specific knowledge necessary to build an automation framework, and I’ve built a robust framework and set of tests that adds value to our development process.

Last week, I worked with another senior QA engineer here at Netspend to define the desired skill sets of our different types of QA jobs: general QA, QA of our back-end systems, QA for our user-facing applications, and automated test developer (I’ll do another blog post about the results of this work). Here is the list of skills that we feel are necessary for an automated test developer in our organization:

  • Source Control Management (we use git)
    • How and Why
  • Continuous Integration (we use Bamboo)
  • Programming Basics, e.g.,
    • Conditionals
    • Data Types
    • Program flow
  • Advanced Programming, e.g.,
    • Development Patterns / Architecture
    • Abstractions / Refactoring
    • Contributing to Framework development
  • X-Path / DOM manipulation (for UI testing)
  • Automation Test Concepts, e.g.,
    • How to Validate what
    • Types of automation
    • Reducing to minimum set of tests
    • Cost / Benefit analysis
  • Database basics
  • Linux basics

As it turns out (and as the people who hired me here–one of whom was the guy I worked with to create this list–astutely realized), being an expert coder of the language of choice doesn’t even make the list. I’ve been successful with the development of an automated testing framework here due to my knowledge of and experience with all of these areas.

Not a maker

I recently met with a friend of a friend to offer some ideas on a career change. This guy has a BA in English and has worked in retail management for 26 years. It has worn him out and he is looking for something new. When he heard that I work in software development, he initially didn’t imagine I had much to offer him since the only job he knew of was coding. During our talk, I outlined to him all the different roles involved in software development and sales–not just programming, but QA, tech writing, product management, business analysis, sales, sales engineering, partner management, etc.–and I briefly outlined the desired skills sets of each of these roles.

I would say that his is a typical view of software development: it’s all about the coding. When I read Debbie Chachra’s essay, Why I Am Not a Maker, it immediately struck me that what she describes is exactly what goes on with high tech in general: “As Kate Losse has noted, coders get high salary, prestige, and stock options. The people who do community management—on which the success of many tech companies is based—get none of those.” Substitute any of the job roles I mentioned above (and many others I overlooked) for ‘community management’ in that sentence and you get what I mean.

Debbie Chachra’s essay focuses on the ‘caregiving’ behind making, and in many ways, I don’t think that aspect of her thinking applies to QA and the other roles in software development. On the other hand, it’s usually the job of some non-coding member(s) of the software development team–QA, scrum master, program manager, etc.–to make sure that the processes are followed: bugs get tracked through correctly through their lifecycle, the team board accurately reflects work in progress, etc. You could certainly consider these to be caregiving roles. To cite Debbie’s example, the team members who get those tasks are the mothers who make sure that the housecleaning takes place–if not doing all the housecleaning themselves. Interesting.

Update: There’s a very long and thought-provoking MeFi discussion about this essay. For instance, “[P]rogrammers (I’m one of them) tend to over-estimate how hard their primary skills are and under-estimate skills others learn for their roles, as well, as you note, the half of the population that is “naturally” expected to be better at them (also in that half.)” On the one hand, it’s true that being a programmer typically requires more specialized training than many of the ‘supporting’ roles in software development. On the other hand, programmers overestimating the difficulty of their primary skills is a product of an environment where that work has been given preference over other work since it was dominated by males. It’s a self-reinforcing circle.

Perks in the high-tech workplace

My friend Rafe Colburn and his Etsy coworker Melissa Santos have written an insightful article on perks in high-tech companies in which they explore a lot of issues that I’ve thought about over the years. Their thesis:

In an industry where culture is often allowed to be defined by perks, managers need to [be] mindful of the fact that for many people, perks underscore the differences between members of the team rather than bringing them together. They also need to think about what a company’s perks indicate to potential employees about the culture.

I’m one of those employees who often feels ambivalent about company perks–especially team-building events, and within that category, especially events that take place outside of work hours. Balancing my responsibilities to my family with my work responsibilities is hard enough when work is confined to defined hours and expectations. An after-hours event often just adds to that delicate balancing act.

Placeholder text goes here

content-loremEarly on in my career as a software tester, I learned–the hard way–not to use profanity in my test text when an executive asked me to demo our software to someone outside the company and I had to use my test environment. In the same vein, Rian van der Merwe has collected  instances of placeholder text that have unintentionally  made it into the real world–both in new and old media. It’s great.

Assigning colors to a BIRT stacked bar chart based on series values

This has nothing to do with QA, but I’ve been writing a lot of BIRT reports lately; I just solved this problem and wanted to make sure my solution is out there for others who need it.
This is the stacked bar chart that I created:
There are three possible values: PASS, FAIL and NOTRUN, and I wanted to make sure that each value got a specified color: green for PASS, red for FAIL and grey for NOTRUN (not tests showed this value on the chart that I used for this post)
The solution was to select the chart, click on the ‘Script’ tab and enter the code below. The beforeDrawDataPoint function draws the bars. the beforeDrawLegendItem function draws the legend:

* Called before drawing each datapoint graphical representation or marker.
* @param dph
* DataPointHints
* @param fill
* Fill
* @param icsc
* IChartScriptContext
function beforeDrawDataPoint( dph, fill, icsc )
var Condition = dph.getSeriesDisplayValue();
if(Condition == "PASS") {fill.set(0,153,0);}
if(Condition == "FAIL") {fill.set(255,0,0);}
if(Condition == "NOTRUN") {fill.set(204,204,204);}
* Called before drawing the legend item.
* @param lerh
* LegendEntryRenderingHints
* @param bounds
* Bounds
* @param icsc
* IChartScriptContext
* @since Version 2.2.0
function beforeDrawLegendItem( lerh, bounds, icsc )
var Condition = lerh.getLabel().getCaption().getValue();
if(Condition == "PASS") { lerh.getFill().set(0,153,0);}
if(Condition == "FAIL") { lerh.getFill().set(255,0,0);}
if(Condition == "NOTRUN") { lerh.getFill().set(204,204,204);}

Often overlooked test automation challenges

The company I work for develops several different products as part of a unified offering. These products need to work with each other and with products from other companies. Each product development team has its own manual QA and automation team, and we have a solutions testing team that ensures interoperability between our products and others. The company has been pretty ‘siloed’–each product’s automation team has worked mostly in isolation from the others.
Until now, the interoperability testing has been all manual, but the manager of that team has embarked on an effort 1.) to get the different automation teams familiar with each other and their work, and 2.) to leverage the automation efforts of the various product teams in the interoperability testing effort.
To that end, we’ve started holding a weekly cross-team automation meeting, with run by the interoperability testing manager with a representative from each product’s automation team. The agenda consists of the following:

  1. Product configuration automation
  2. Test lab usage management (automated check out/in of lab resources
  3. Automation strategy
  4. Test management and reporting

What’s striking is that each product automation team has put in significant effort to address all four of these functions (with a lot of duplicated work!), yet when we think about test automation, we typically only think about #3, the actual automated tests themselves.
Just an observation. When we think about test automation, we need to remember that there are several complex components to it besides the tests themselves.

Clever job-hunting move

I can’t say I condone this, but it’s a clever way to see how you stack up against the competition:

After a fruitless job search — endlessly scanning Monster.com and Craigslist and tweaking resumes and cover letters — he grew more curious about his competitors. So he created a fake Craigslist ad for an administrative assistant position and, in one day, received 653 responses from applicants with a wide range of education and experience.

Sneaky. Not ethical. But sneaky.