Forum Discussion

ssinha's avatar
ssinha
Occasional Visitor
8 years ago

How do I record script for handling dynamic user input based on dynamic question when navigating

How do I record script for handling dynamic user input based on dynamic question when navigating from page 1 to page 2.

 

Also, how do I skip steps (if needed) and still complete script and run it.

 

Option of having same user response for different dynamic question(s) when navigating from page 1 to page 2 is not possible due to business reasons nor does current code support bypassing this page for test ID used to running the script.

4 Replies

  • "How do I record script for handling dynamic user input based on dynamic question when navigating from page 1 to page 2."

     

    You don't.

     

    You will need to do something more than just record/replay for this sort of scenario. I would highly recommend doing this in script rather than trying to fight your way through using a keyword test (which may be possible, but incredibly painful).

     

    I'm assuming a couple things here:

    1. You know the data you want to send to the SUT, system under test, or the actions you want to perform
    2. You know ALL of the dynamic questions the user could be asked during the navigation operation

    I would grab the text from the screen that the user is prompted with and store it in a variable... then I would write a function that uses that variable value in a Switch Statement. Then for each Case in the switch statement, you would create the desired actions (I'm betting it's something like "type this answer to that question" or the like).

     

    Your code should end up something like this:

     

    switch(Project.Variable.WhichQuestion) {
        case "Question 1":
            code block // Do stuff
            break;
        case "Question 2":
            code block // Do other stuff
            break;
        default:
            default code block // Stop the test; the developers made up a new question without telling you!
    }

     

    Good luck!

     

    • dmiscannon's avatar
      dmiscannon
      Frequent Contributor

      We have a similar scenario where the user has to answer a challenge question when logging into the site. The questions that can be displayed may be changed by others, so I never know what will display. We have agreed that the answer to the challenge questions will always be set up to be the last word in the question. So I wrote a function to grab the question, take the last word and strip off the "?" to arrive at the answer to enter. This has worked well for me.

  • DCat1223's avatar
    DCat1223
    Frequent Contributor

    Hi ssinha...

     

    I had do the exact same thing.  I created a script to test an application for users to enroll in healthcare.  Based on a series of questions the application would determine how to enroll the user...  No healthcare, single coverage, family no spouse...  I think you get it.

     

    I found the easiest way to build my automation was to record myself clicking the radio buttons for each question for the purpose of mapping the questions only.  I did not record the script for each scenario because it would have been way too many scripts. 

     

    The way I started was to record the first question - Do you want to enroll in healthcare - Yes / No.  I did this only to map the questions and answers.  I recorded the second question - do you want to cover children?  Yes / No again to map the questions and answers.  Once I had all the questions and answers mapped, I created the automation with If Then statements.  It is helpful if you have a flowchart to follow.

    If question 1 = Yes go to question 2. 

    If Question 1 = No, go to question 2a.

     

    I attached a screenshot of a small piece. 

     

    Hope this helps. 

     

    Dave.