All posts by Mindful tester

Find The Button Sometimes In The Room

Small recap also known as cliff hanger

At the end of the sprint I demonstrated my automated regression tests. An unknown dialog popped up and interrupted the normal flow of the tests.

An unexpected dialog

After the demo one of my team mates asked the standard routine questions:
“Did you test before the demo?”
“Yes, of course”
“Did everything go right?”
“Yes”

I had done all the standard actions and still this dialog popped up. I studied it. Something went wrong with saving a file. This neat feature offered the user to add a personalised picture with a text like “Happy birthday, Cap. Loves from Dom, Sam, and George.” This way nicknames “Captain Marvel” or “Captain America” can be used or even abbreviated to Cap.

So the first attempt to save the file failed. I pressed the OK button to upload the picture again. After two other attempts, an error dialog popped up. It was not possible.

Of course I tried to reproduce this error manually, but all uploading went just fine. Hmm. Another attempt with the automated test showed the file upload problem straight away. The computer was too fast with testing.

The Need For Brakes

Imaginary scene in a shop in a cinema. I am recognised by one of the employees.

Employee: “Good evening, what do you want to drink?”
Me: “Well.”
Employee: “Here is your favourite drink, Cola.”
Me: “I was thinking about .. ”

Employee: “Here is your second favourite drink, Lemonade.”
Me: “Actually ….”
Employee: “This is the last drink we offer: Sparkling Orange.”

Me: “This was not in my mind.”
Employee: “You are going to watch Monsters Unlimited with the famous desert scene. Right?”
Me: [Nods]
Employee: “Excuse me for being so rude.”
Employee [Removes the 3 drinks from the counter and places a bucket on the counter.]
Employee: “This will take a few seconds.”
Employee: [Places a thick tube into the bucket.]
[The sound of 1 gallon of Sparkling Orange being pumped into the bucket.]
Employee [Removes the tube and smiles at me]

Me: “And …”
Employee: “You are going to the 5D experience with the real desert temperature.”
Me [Nods slightly]
Employee: [Empties a box of ice cubes into the bucket.]
[The sound of overflowing Sparkling Orange, followed by dripping sounds on the floor.]

Me: “I am trying to tell you …”
Employee: “I got it. Drinking out of a bucket is a drinking hazard, so you get this special straw.”
Employee [Pulls out a mini submarine with a tube on top and places it on the drink.]
[Again the sound of dripping Sparkling Orange on the floor]

Me; “I want ..”
Employee [Shows receipt of 100 Euro.]
Me: “nothing to drink.”
[The end]

This story describes a timing issue. The employee is way too fast. And guess what? Programs are also very fast. For example a test automation tool.

Wait a few seconds

Something had been changed in the program and a dialog popped up. There should be a way to let the test automation tool wait. I picked Thread.sleep(2000). This command let the tool wait for 2000 milliseconds or 2 seconds.

I started the tests again. This time no problems with the Error dialog were encountered.

Next stop was to ponder whether this was a proper solution. I was actually hiding a performance issue. My team lead had already given me a hint about this kind of cases.

Personally I never had any problems with the upload of the file. So this should not happen with other human beings. Waiting for 2 seconds was not that bad.

The Untouchable

On my screen I had a nice combo box. I wanted to select an option. This was not that difficult I thought.

My test failed. Wait, this cannot be true. All the time the combo box was in full view and my test automation tool Selenium web driver could find it until that very moment. I opened the console to look at the problem: it was a Stale Element Reference Exception.

On the internet I read about a situation that a web element was somehow disconnected with the element on the screen. This read quite cryptic. I tried to imagine what happened.

There was a combo box with movies to be shown, Monsters Unlimited and Finding Marlin. After the selection of a new date a new movie would be shown, the combo box was updated with the latest movie, Outside In.

What actually happens was that the old combo box was replaced by another combo box. So the old combo box did not exist anymore. Small courtesy of the low code development tool. Not really helpful.

But why did this error happen right now?
The code of the website was not changed. But. I had changed the structure of my tests.
How can a restructuring of my tests cause this problem? Give me a few paragraphs to explain.

A popular design pattern for test automation is the Page Object Model. A design pattern is an experience based way of working, which saves a lot of time and frustration. Using Page Object Model or POM I put all the old code associated with a page like Select Movie Page in one single class.

The class contains the following useful information:

  • Constructor (how can I make this page object?)
  • Methods (which actions can I do on this particular page?)
  • Fields (which web elements are contained on this page? What other relevant information is used by this page?)

A movie combo box can be coded like:

@FindBy(contains(@id, “moviesComboBox”))
WebElement moviesComboBox ;

This is an abbreviation of TestNG, a test framework, for

WebElement moviesComboBox = driver.findElement(By.xpath(contains(@id,“moviesComboBox”))

For the reader wondering about the word contains, there is an explanation about this construction.

What I set up, was an administration, which connects moviesComboBox to the movie combo box with the movies Monsters Unlimited and Finding Marlin on screen.
The program replaced the combo box with the two movies by the movie combo box with Monsters Unlimited, Finding Marlin, and Outside In.
Now my web element moviesComboBox was referencing nothing.

My solution was to make the connection between the web element moviesComboBox and the combo box on screen as last as possible. Just before selecting a movie I placed the following code:

WebElement moviesComboBox = driver.findElement(By.xpath(contains(@id,
                                     “moviesComboBox”));

I got a Stale Element Reference Exception. No worries, I use a sleep.

Thread.sleep(100);
WebElement moviesComboBox = driver.findElement(By.xpath(contains(@id,
                                     “moviesComboBox”));

This was a flaky test. I could tweak my number of milliseconds of sleep, but a reliable test was slipping out of my hands.

The Unfindable

Now I had a situation that in 60 % of the cases my tests would execute with Passed. This was quite disturbing for me, because the website was not changed. Same test, same unpredictable result.

I focused on my latest test automation challenge: finding the right order identity often abbreviated to order id. Users were allowed to use an order Name like “Cap 13”. This is short for the 13th birthday of Captain Marvel or Captain America.

But this could hurt the handling of orders. Suppose a parent of Cap had made two reservations with the same name. If this persons calls the cinema, which order must be deleted by the customer agent? Cap 13 or Cap 13? So an order id was introduced.

For test automation this was really helpful. The organizer or parent placed the order for the movie visit. And she or he got an order id. In turn all attendees or kids could use this order id to order a snack and a drink.

If I automated my manual steps, then everything would be okay.
My steps were:

  • Search for the order name.
  • Determine the first row in the table.
  • Determine the order id in this row.

The code was ready, but the test did not pass. Another fail on my record. I better got used to this.

This time I saw a No Such Element Exception in my console. This meant, that the first row could not be found. Then I got a déjà vu. The test automation tool was too fast, so I built in a sleep. This did not solve the problem completely.

Sent until accepted

[Update author: my opinion is not the same as the author of the referred characters, but I believe in the goodness of the good characters.]

Suppose there is a character, who wants to reach someone else. Let me pick an arbitrary person called M. McGonagall. Her employer does not receive a response on her letter.

So every responseless day she resends a letter and also slowly increases the number from 1 via 3 via 12 via 24 via 30 – 40 to some 100. Until a pink umbrella wielding bloke delivers the long awaited letter to Mr. H. Potter.

The Multiple

In the meantime I was tweaking my sleep time in milliseconds. It looks that a response time was between the 2 and 6 seconds. If I only used the worst case scenario time, then this would lead to an increased execution time of my regression tests. Because the low code tool automatically made the code for the website, there was no way to tweak this code.

I got an idea. What about trying to find the first row 3 times instead of once?

Boolean individualOrderNotFound = false;
For (int i = 0; i < 3 && !individualOrderNotFound; i++){
  try {
      findElement(xpath).click();
      individualOrderNotFound = true;
  }
  catch(NoSuchElementException e){
      Thread.sleep(2000);
  }
}

While blogging I fully realise that this is not the best piece of code to be shown. But things in the past cannot be changed.

I performed my test 5 times in a row. There was 1 fail. I felt relieved, that my tests were more reliable than before. Less fails on my record. I better got used to it.

There was still one more thing to check.

Time for another blog post.

Find The Button In The Room

Introduction

This is my second blog post in the Find In The Room blog post serie. In order to avoid any legal issues I sanitised my story. It is about software testing and IT: test automation.

For this story I will use the Cinema Hype VIP website.

Voice commercial:
“Are you tired to buy drinks and snacks for a child birthday party in a cinema?
Cinema Hype VIP website is here to rescue you.”
Author – that’s me: “Let me turn down the volume.”
[Presses a button]
Commercial [Loud voice] “Now you can order everything before setting a foot in the cinema.”
Me: “Excuse me. Let me mute the volume.”
[Presses a button]
Commercial: [Loud voice] “What are you waiting for?”

Me: [Surprised]
[Presses a button]
Commercial: [Silent]
Me: [Silently smiling]
[Presses a button]
Commercial: [Silent]
Me: “Test. 1 2 3. ”

Commercial: [Silent]
Me [Remains a few seconds silent.]
Commercial: [Silent]
Me [Looks a few lines up and down.]
Me [Remains a few seconds silent.]
Commercial: [Silent]
Me: “Ahum.”
Commercial: [Silent]
Me: “Someone is watching me from a few lines above.
Oh, I watched myself.”

The moment of approval

In my introduction I wrote several times about the button. It took me some effort to find the right button.

Now it is time for a real world test automation example. For my first big test automation experience I programmed the steps in Java. Selenium was used for the interaction with the website.

One of the most important steps of a website is pushing a button. These days a lot of deals are closed with a press of a button. Also online transactions need some key presses to pay. So I must be able to find a button on the web page.

Let me return to the Cinema hype VIP website.
My kid has a birthday party and all tickets, snacks, and drinks are listed. The only thing I have to do is to press a button.

The quickest way

Years ago I thought that there was one way to find a button.

  • Right click the button and select Inspect in the Option menu.
    An option  menu is shown above the OK button. The last menu option is Inspecteren or inspect in English!
  • Select the HTML code of the button and copy XPath.
    In DevTools  menu is shown above the HTML text for the OK button. This menu contains the sub menu Copy containing the option Copy XPath!
  • Give XPath to Selenium to find the button.
  • Pat myself on my shoulder.

Then my attention was drawn to the free online course of Andrew Knight, Web Element Locator Strategies, on Test Automation University.
So what did I actually use?

An XPath is basically a route description through the web page. And it can look a bit scary:
/html/body/div[2]/div/div[2]/button
This is of course automatically followed by Selenium. That is something programs tend to do. There is 1 huge problem. If signs change, then Selenium cannot find its way.

[Update author: my opinion is not the same as the author of the referred characters, but I believe in the goodness of the good characters.]

Let me use an arbitrary text on a letter and transform it to a more computer friendly notation.

/Surrey / Little Whinging / Privet Drive 4 / The Cupboard under the Stairs / Mr. H. Potter.

If his uncle would move Mr. Potter to a bed room, then the postman had still no problem with delivery. Same address and a decent room this time.

Would it a bit more convenient to address the letter to a mister called H. Potter? A muggle postman would have serious problems, if this Mr. is evacuated to an island before his 12th anniversary. But finding him is a Half Giant job for a bloke like Hagrid.

This would lead to:
//Mr. H. Potter

But computers need more details:
//Human[contains(text() = 'Mr. H. Potter`]

Find a button with text OK.In that case I would get something like
//button[text()='OK']

The HTML code of the OK is hightlighted, while the search bar contains the text “//button[text()='OK']” followed by the text “1 of 1”!

Let me give you a more precise translation:

  • “//” means “Find somewhere on the page”
  • “button” means “the first button you encounter”
  • “[text()= ‘OK’]” means with the condition, that the text is equal to ‘OK’

No idea

But this does not completely explain:
/html/body/div[2]/div/div[2]/button

  • “/” means “search directly under”
    “body/div” means “search the first div under the body”
  • “[2]” means the second, so
    “div[2]” is the second div.
  • The rectangular brackes, “[” and “]”, are useful, if I do not need the first , but another one in the row.

The website I was testing was created with a low code tool. This tool can be compared with an advanced presentation tool, which also builds a fully functional website.

With great power comes great creativity. This basically means, that certain things were not fully under control of the developers. As a tester I had to solve these problems.

Placing a button on a web page led to an explosion of actions. Lots of code were automatically added, but this led to names like 1_saveFiles.

So I used ‘1_saveFiles’. A fellow tester pointed out, that the low code tool could change the button name to ‘2_saveFiles’ at will.

So I focused on the last part of the string.
//Button[contains(@name, 'saveFiles')]
This means such much as
“Search a button with the name containing saveFiles”
Of course there is a faster way to address an element using the attribute id. There is no magic needed to find Mr. Potter, if we were on the same page.
//Human[contains(@id, 'Mr. H. Potter`]

By the way id is pronounced as at Eye Dee instead of it. If you want to surprise your big sister or brother test automator, then use a sentence like “That element had probably no id.” Don’t forget a little sigh.

In my case id was not always set. To make things a little more challenging for me a single condition was not enough.

This is an exaggerated situation:
Code for dirnks: <input class="radio" name="2_drink" type="radio" value="one"> Cola</label> <br> <input class="radio" name="2_drink" type="radio" value="two"> Lemonade</label> <br> <input class="radio" name="2_drink" type="radio" value="three”> Sparkling Orange</label> <br>!

//input[contains(@name, 'drink')]
This might lead to some drink

//input[@value = 'two')]
could lead to the second drink or second snack.

So I chose for two conditions:
//input[contains(@name, 'drink')][@value = 'two']

There were other cool tricks in the course of Andrew Knight. The described ones in this blog post were big time savers.

Show and fail

It was time for the demo. My team liked that I would show my scripts in action. People were looking when I kicked off the tests.

An unexpected dialog popped up. I had to close it. What went wrong?

I apologised and left the stage. My team members postponed the demonstration of my tests.

Time for another blog post.

Find The Monster In The Room

One evening in the winter I was having a dinner. People enjoyed their meal and there was a lot of talk.

The mood
was good.

Then the youngest child shrieked of panic. All talk stopped.

The first steps would be like: go to the bedroom and put on the light.

Everyone at the dinner table looked at the kid a few meters away. The kid was in the same room.

The mother said that the kid had seen something. She went to the little child and tried to talk about it. This was difficult, because the kid knew only a few words.

The mother looked in the direction of the fearful eyes and saw nothing strange.

Back at the dinner table she told a story about curtains with triangles which looked like eyes to another little kid.

The second shriek was handled in the same way. The mother went to comfort the child. While looking for the source of fear.

The 3rd time an adult was with the frightened child within a second. The person lowered the head to the same height of the kid and looked carefully.

A machine showed some scrolling text. It was like the pupil of an eye looking for …

One of my kids asked: “Can I draw out the power cord?”
My answer was: “Yes.”
This was immediately followed by a familiar sound.
The display went blank.

Earlier that evening there was a power outage. The machine was switched on and had no current time. So it politely asked to set the proper time and scared a little child.

Some readers might remark, that this blog is about IT and  testing.
My answer is: “Yes”.

My New Year’s resolution is to Find The Monster In The Room.

Now I gave it a name.