Validate data table inputs to a single field

Best practices, code snippets for common functionality, examples, and guidelines.
fLaMePr0oF
Posts: 2
Joined: Mon Sep 21, 2015 3:46 pm

Validate data table inputs to a single field

Post by fLaMePr0oF » Mon Sep 21, 2015 4:11 pm

Trying to test the validation rules on a password field.

The current test is supposed to input several 'Good' passwords from a data table and validate each one (as each one is typed the screen auto-updates to show if it is 'insufficient', 'good', 'strong', or 'very strong'

However, when I run the script, the 'set value' (line 3) just works through each password in the data table without any opportunity to validate each one, (i.e the validation in line 4 which comes next is never executed).

How can I get validation on each data entry after it has been entered into the field?

1 Mouse Cick Left 134;10 <>>Passphrase [Cick the field]
2 KeySequence {Back}{Back}{Bac.. <>>Passphrase [Clear the field]
3 Set Value Value $passphrase <>>Passphrase [Inject data]
4 Validate Exists <>PasstextWifi [Validate response]

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Validate data table inputs to a single field

Post by odklizec » Tue Sep 22, 2015 7:56 am

Hi,

Could you please post your entire solution, so we can review it and suggest changes?

Generally speaking, all you need is a single Test Case with Data Connector containing the passwords and one recording inside that Test Case. Your described sequence of steps looks OK to me, maybe except the part where you cleaning the input. I would suggest to replace this one with Ctrl+A and Del shortcuts, where the first one will select the content of input and the other one will delete it. It's much more elegant and reliable than using backspace or delete char by char. I would also suggest to split setting and validation phase to two recordings.

Anyway, here is how your Test sequence should look like...
[TC] <--- data connector with passwords and validated text
|_Set_and_Validate <--- recording with setting and validation steps.
or
[TC] <--- data connector with passwords and validated text
|_Set_Values <--- recording with setting steps
|_Validate_Values <--- recording with validation steps
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

fLaMePr0oF
Posts: 2
Joined: Mon Sep 21, 2015 3:46 pm

Re: Validate data table inputs to a single field

Post by fLaMePr0oF » Tue Sep 22, 2015 4:08 pm

Thanks for the response

Yes, I'm pretty much doing exactly what you described in your second example.

I've created a Test Case with a data connector; in this case there are 14 passwords held in a CSV file which is bound to the variable $passphrase

The action in line 3 is [Right Click > Add New Action > Set Value]
The action is line 4 is [Right Click > Add New Action > Validation]

However, when I run the Suite, at this point it appears to loop between lines 2 and 3; clearing the field (I have taken your advice of using Alt+A Del here) and setting the value, taking the next value in the data table.

What I can't understand is why the script is looping; when it gets to the Set Value step it loops and one after the other injects each of the 14 passphrases into the field, clearing the field after each input (apparently using the Key Sequence in Step 2 as after I changed this to CTRL+A Del as you suggested it started highlighting and deleting after each value rather than deleting the characters one by one); hence it looks like steps 2 and 3 are looping, although if I place the validation step between these two lines it is still not applied within the loop!

Here is the code behind the test case:

'//////////////////////////////////////////////////////////////////////////////
'
' This file was automatically generated by RANOREX.
' DO NOT MODIFY THIS FILE! It is regenerated by the designer.
' All your modifications will be lost!
'
'//////////////////////////////////////////////////////////////////////////////

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Drawing
Imports System.Threading
Imports WinForms = System.Windows.Forms

Imports Ranorex
Imports Ranorex.Core
Imports Ranorex.Core.Testing
Imports Ranorex.Core.Repository

Namespace Mercury_Arris_WiFi_Passphrase
''' <summary>
'''The TryPassword recording.
''' </summary>
<TestModule("4c949b74-e900-40b4-8ef2-6783a07f2630", ModuleType.Recording, 1)> _
Partial Public Class TryPassword
Implements ITestModule

''' <summary>
''' Holds an instance of the Mercury_Arris_WiFi_PassphraseRepository repository.
''' </summary>
Public Shared repo as Mercury_Arris_WiFi_PassphraseRepository = Mercury_Arris_WiFi_PassphraseRepository.Instance

Shared _instance as TryPassword = new TryPassword()

''' <summary>
''' Constructs a new instance.
''' </summary>
Sub New()
passphrase = "Amm1notests"
End Sub

''' <summary>
''' Gets a static instance of this recording.
''' </summary>
Public Shared ReadOnly Property Instance As TryPassword
Get
Return _instance
End Get
End Property

#Region "Variables"

Dim _passphrase As String

''' <summary>
''' Gets or sets the value of variable passphrase.
''' </summary>
<TestVariable("6b4ac3d0-59a9-4cb1-ba37-76fb0dd36c30")> _
Public Property passphrase As String
Get
Return _passphrase
End Get
Set(ByVal value As String)
_passphrase = value
End Set
End Property

#End Region

''' <summary>
''' Starts the replay of the static recording <see cref="Instance"/>.
''' </summary>
<System.CodeDom.Compiler.GeneratedCode("Ranorex", "5.4.2")> _
Public Shared Sub Start()
TestModuleRunner.Run(Instance)
End Sub

''' <summary>
''' Performs the playback of actions in this recording.
''' </summary>
''' <remarks>You should not call this method directly, instead pass the module
''' instance to the <see cref="TestModuleRunner.Run(Of ITestModule)"/> method
''' that will in turn invoke this method.</remarks>
<System.CodeDom.Compiler.GeneratedCode("Ranorex", "5.4.2")> _
Sub Run() Implements ITestModule.Run
Mouse.DefaultMoveTime = 300
Keyboard.DefaultKeyPressTime = 100
Delay.SpeedFactor = 1.0

Init()

' Click the password field
Report.Log(ReportLevel.Info, "Mouse", "Click the password field"+Chr(13)+""+Chr(10)+"Mouse Left Click item 'WebDocument19216801.Passphrase' at 134;10.", repo.WebDocument19216801.PassphraseInfo, new RecordItemIndex(0))
repo.WebDocument19216801.Passphrase.Click("134;10")
Delay.Milliseconds(200)

' Clear existing passphrase from field
Report.Log(ReportLevel.Info, "Keyboard", "Clear existing passphrase from field"+Chr(13)+""+Chr(10)+"Key sequence '{LControlKey down}{Akey}{LControlKey up}{Delete}' with focus on 'WebDocument19216801.Passphrase'.", repo.WebDocument19216801.PassphraseInfo, new RecordItemIndex(1))
repo.WebDocument19216801.Passphrase.PressKeys("{LControlKey down}{Akey}{LControlKey up}{Delete}")
Delay.Milliseconds(0)

' Inject passphrases from data table
Report.Log(ReportLevel.Info, "Set Value", "Inject passphrases from data table"+Chr(13)+""+Chr(10)+"Setting attribute Value to '$passphrase' on item 'WebDocument19216801.Passphrase'.", repo.WebDocument19216801.PassphraseInfo, new RecordItemIndex(2))
repo.WebDocument19216801.Passphrase.Element.SetAttributeValue("Value", passphrase)
Delay.Milliseconds(100)

' Validate that passphrases are 'Good'
Report.Log(ReportLevel.Info, "Validation", "Validate that passphrases are 'Good'"+Chr(13)+""+Chr(10)+"Validating Exists on item 'WebDocument19216801.PasstextWifi'.", repo.WebDocument19216801.PasstextWifiInfo, new RecordItemIndex(3))
Validate.Exists(repo.WebDocument19216801.PasstextWifiInfo)
Delay.Milliseconds(100)

End Sub

#Region "Image Feature Data"
#End Region

End Class

End Namespace
odklizec wrote:Hi,

Could you please post your entire solution, so we can review it and suggest changes?

Generally speaking, all you need is a single Test Case with Data Connector containing the passwords and one recording inside that Test Case. Your described sequence of steps looks OK to me, maybe except the part where you cleaning the input. I would suggest to replace this one with Ctrl+A and Del shortcuts, where the first one will select the content of input and the other one will delete it. It's much more elegant and reliable than using backspace or delete char by char. I would also suggest to split setting and validation phase to two recordings.

Anyway, here is how your Test sequence should look like...
[TC] <--- data connector with passwords and validated text
|_Set_and_Validate <--- recording with setting and validation steps.
or
[TC] <--- data connector with passwords and validated text
|_Set_Values <--- recording with setting steps
|_Validate_Values <--- recording with validation steps

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Validate data table inputs to a single field

Post by odklizec » Tue Sep 22, 2015 5:52 pm

Please post the entire suite, or at least a Ranorex report you are getting at the end of test. Without seeing the solution, it's next to impossible to tell what's wrong with your test. Your posted code does not explain why the validation step is not performed.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration