question

emmanuel avatar image
emmanuel asked emmanuel posted

handling prompts in cli sessions

How can i execute the next command on a cli depending upon the prompt i get?

For example when login to my device, sometimes it asks for login and password and sometimes it gives me the # prompt to enter my commands skipping the login.

I want to say if prompt is "login:"  then enter loginname and password and if prompt is # then enter some cli command.

 

 

iTest
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JeffJ avatar image
JeffJ answered JeffJ posted

First, create a procedure to do your login.

 

Secondly, create an analysis statement that queries prompt() and compares it to "login:".  For the true condition, add an analysis step "CallProcedure" and call the login procedure to login.  You can simply ignore the "if false" condition since you're already logged in.

3 comments
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sreenath avatar image sreenath commented ·

Hi emmauel,

 

Please find the attached test case.

Hope this is helpful to you.

 

Thanks

 

0 Likes 0 ·
new_testcase.fftc (10.4 KiB)
dclaar avatar image dclaar sreenath commented ·

I prefer to query promptName(), as that abstracts the actual data, meaning that--if the prompt changes from "login" to "Login"--you won't have to chase through your tests everywhere looking for the string "login", but just change the prompt, which should also be abstracted to the highest common session profile.

0 Likes 0 ·
emmanuel avatar image emmanuel dclaar commented ·

Thank you very much for the answers Jeff, Sreenath and Dclaar.

 

So we have the queries prompt() and promptName() for handling the prompts. 

I am using promptName() with the prompts put in the session profile.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.