From Record-Playback to Automation Code

Is record and playback useful for test automation?

Commercial test automation tools claim that manual testers can do test automation without knowing any programming through their record and play components.

Is this correct?

Do you need record and playback for test automation?

Or test automation requires programming knowledge?

I had a discussion a few days ago with a colleague about the best way of doing test automation.

He thought that we should record a script using the test automation tool (Ranorex) and then play it back.



This would take not more than 5 minutes.

So we tried the approach that he suggested.

We recorded a test script for an application that implements workflows for different user types.

Between the first application page and the last one, there are about 10 other pages.

Each page has around 5 elements included.

After the script was recorded, we were able to see each of the recorded steps inside of an action grid.

Each step shows

  • the action name
  • if the mouse of keyboard is used
  • position of the click
  • the name of the application element


Each of the actions can be changed in the matrix and this is nice.

The application elements that the script interacts with are available in a repository:



The problem with the action grid is that the changes allowed by it are very limited.



How do you implement a looping action in the grid?

Next, we looked into the code generated by the recording component:

void ITestModule.Run()
{
Mouse.DefaultMoveTime = 300;

Keyboard.DefaultKeyPressTime = 100;

Delay.SpeedFactor = 1.0;

Init();

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.RadioButtonEn' at 169;22.", repo.MainWindow.RadioButtonEnInfo, new RecordItemIndex(0));

repo.MainWindow.RadioButtonEn.Click("169;22");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.SelectionStatement' at 135;328.", repo.MainWindow.SelectionStatementInfo, new RecordItemIndex(1));

repo.MainWindow.SpeechDocumentStatement.Click("135;328");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '{F1}'.", new RecordItemIndex(2));

Keyboard.Press("{F1}");

Delay.Milliseconds(0);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.ElementP' at 30;19.", repo.MainWindow.ElementPInfo, new RecordItemIndex(3));

repo.MainWindow.ElementP.Click("30;19");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.ButtonConfirm' at 67;5.", repo.MainWindow.ButtonConfirmInfo, new RecordItemIndex(4));

repo.MainWindow.ButtonConfirm.Click("67;5");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.SpeechButtonAccept' at 155;33.", repo.MainWindow.SpeechButtonAcceptInfo, new RecordItemIndex(5));

repo.MainWindow.SpeechButtonAccept.Click("155;33");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.SpeechChoiceNext' at 536;16.", repo.MainWindow.SpeechChoiceNextInfo, new RecordItemIndex(6));

repo.MainWindow.SpeechChoiceNext.Click("536;16");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.SpeechButtonNext' at 155;11.", repo.MainWindow.SpeechButtonNextInfo, new RecordItemIndex(7));

repo.MainWindow.SpeechButtonNext.Click("155;11");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '{F1}'.", new RecordItemIndex(8));

Keyboard.Press("{F1}");

Delay.Milliseconds(0);

Report.Log(ReportLevel.Info, "Keyboard", "Key sequence '{F1}'.", new RecordItemIndex(9));

Keyboard.Press("{F1}");

Delay.Milliseconds(0);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.Button' at 229;21.", repo.MainWindow.ButtonInfo, new RecordItemIndex(10));

repo.MainWindow.Button.Click("229;21");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.ButtonAgree' at 157;8.", repo.MainWindow.ButtonAgreeInfo, new RecordItemIndex(11));

repo.MainWindow.ButtonAgree.Click("157;8");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.SpeechButtonAgree1' at 153;14.", repo.MainWindow.SpeechButtonAgree1Info, new RecordItemIndex(12));

repo.MainWindow.SpeechButtonAgree1.Click("153;14");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.ButtonNo' at 252;10.", repo.MainWindow.ButtonNoInfo, new RecordItemIndex(13));

repo.MainWindow.ButtonNo.Click("252;10");

Delay.Milliseconds(200);

Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'MainWindow.ButtonConfirmYes' at 236;12.", repo.MainWindow.ButtonConfirmYesInfo, new RecordItemIndex(14));

repo.MainWindow.ButtonConfirmYes.Click("236;12");

Delay.Milliseconds(200);
}


I know what you think. Awful code, right?




Whats wrong with this script?

So many things:

- repo.MainWindow.RadioButtonEn.Click("169;22");

This action clicks a radio button.

The click happens on the (169, 22) position inside of the radio button.

If the radio button size is changed in the future, it is possible that the (169, 22) position is not inside of the radio button any longer so this action will fail.


- Delay.Milliseconds(200);

This action introduces a delay.

Delays are sometimes needed if an application element is not available right away.

If the script wants to click a button, it may add a delay for waiting until the button is displayed.

But what if the button is not displayed after the delays ends?

What if the button is displayed after much more time elapses?
In this case, the action will fail.


- repo.MainWindow.ButtonAgree.Click("157;8");

This action click the ButtonAgree button.

It is not clear what page this button belongs to.
Does it belong to the first page, second page, third page?


- is it obvious to you looking at the code that it goes through a workflow for a specific type of user?


- is it clear how to change this code for another type of user?


- repo.MainWindow.Button.Click("229;21");

The action clicks a button.

How does the code know how to find the button?

If this action fails in the future, how do you troubleshoot it?


Lets look now at the code that I was showing my colleague before he made his suggestion:

void ITestModule.Run()
{
MainWorkflow workflow = new MainWorkflow();

workflow.start();

workflow.addUser("Alex", "PowerUser", "alex@alex.com");

workflow.close();
}

Do you understand what this test script does?

I believe that you can.

Now, lets assume that we want to have the ability to add other users to the first script.

How do you do this using record and playback?

You could record additional scripts for each type of user.

You will have in the end of lot of very unfriendly test scripts.

And lets assume that the application changes.

How do you modify all these scripts?


If I want to add the additional users to my scripts, the same script changes a little bit:

void ITestModule.Run()
{
MainWorkflow workflow = new MainWorkflow();

workflow.start();

workflow.addUser("Alex","PowerUser","alex@alex.com");

workflow.addAdditionalUser("John","NormalUser","john@john.com");

workflow.addAdditionalUser("Sam","french","sam@sam.com");

workflow.close();
}

I believe that you agree by now that record and playback test automation does not work.

Having a lot of recorded test scripts will make the test automation maintenance extremely difficult.

Difficult and complex.
And these are 2 of the reasons why test automation projects fail.

My script was not created in 5 minutes as I needed more than a week to put it together.

But it comes with so many advantages:


  1. adding changes to it is very easy
  2. the script reads like English
  3. it does not show any details of how the application to be tested works
  4. all details of how the script interacts with the application are not visible
  5. the script is short


How do you go from record-playback to automation code?

By learning a programming language, learning a test automation framework, learning how page object model works...

And by forgetting about record and playback.


PS:

Please don't get me wrong.

I am not trying to say in this article that Ranorex is not a good tool.

Ranorex is an amazing tool and my tool choice for test automation of Windows apps.

The only point that the article tries to make is about the record and playback,

0 Response to "From Record-Playback to Automation Code"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel