This is a migrated thread and some comments may be shown as answers.

Alert dialog with If condition

6 Answers 163 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nithya
Top achievements
Rank 1
Veteran
Nithya asked on 09 Jun 2020, 12:35 PM

Hi , 

I need to execute the steps in my project based on the appearance of the Alert box.

My secnario : 

If the Alert box appears, then I have to do some pair of  steps ( ex: 1,2,3 )

If the Alert box doesn't appear, I want to do nothing, and continue my other steps. (ex 5,6,7)

 

I am not sure, how to do handle this ?  Is it possible to detect and check if the alert box appears on the screen or not ?

could you please help.

 

Regards,

Nithya A.

6 Answers, 1 is accepted

Sort by
0
Paul
Top achievements
Rank 1
Veteran
answered on 09 Jun 2020, 03:42 PM

Maybe this will help you:   an IF..ELSE with Exists / Contains() on the text of textblock of the Messagebox.   Maybe with an wait before to wait to be sure the dialog is open.

Using this to verify if the correct dialog is open (Contains() with part of the name of the dialog title / Data driven) on the beginning of every test after opening an dialog.

0
Elena
Telerik team
answered on 10 Jun 2020, 09:14 AM

Hi,

@ Paul: Hey, Paul, thanks for continuing the discussion and providing ideas about it. The approach you proposed is actually in the correct direction, but due to the specifics of dialog handling in Test Studio, there are some differences - you can refer to the below notes for details. 

@ Nithya: Thanks for describing the scenario in details. 

Test Studio allows you to handle such a scenario and you will need to use a coded step for this. Then, you can define the dialog you are waiting for and insert its handling in a try...catch block - an example is illustrated in this article

Since you have two possible ways to continue the test scenario depending on the dialog behavior, you can insert the respective steps in the try or catch block. This is similar to the if..else construction - the try block contains the follow up steps if the dialog appears and is handled, and the catch block contains the steps if the dialog does not appear.

These steps can be recorded in a separate test and then called as test as step in the code:

this.ExecuteTest("theNameofTheTest.tstest");

I hope this information will be helpful for you. Of course, if you need further assistance on the topic, please, get back to us.

Regards,
Elena
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Nithya
Top achievements
Rank 1
Veteran
answered on 10 Jun 2020, 09:22 AM
Thanks Paul for your ideas!!
0
Nithya
Top achievements
Rank 1
Veteran
answered on 10 Jun 2020, 09:34 AM

Hi @Elena , 

Thanks for the detailed explanation. 
This is what exactly, I am looking for. But when I try this, I have few questions popping out.

Qn  1 : In the example article, They are finding the button by content. My dialog looks like below with the ok button. I am not sure, how to find this by content?

 

"www.pages.xxx says

Test failed"

 

Qn  2 : When I compiled the code, it says "Alertdialog" is not defined. Do you know , should I add any reference ?

Could you please help me on this.

 

Regards,

Nithya A.

0
Nithya
Top achievements
Rank 1
Veteran
answered on 10 Jun 2020, 10:03 AM

Hi again , 

Qn 2 : I solved it by adding 

Imports ArtOfTest.WebAii.Win32.Dialogs

Imports System.Windows.Forms

 

Now the only problem line in the code is 

"Manager.ActiveBrowser.Frames("iframeResult").Find.ByContent(Of HtmlButton)("Try it").Click()"

I used this code in my application. In my application , The alert dialong appears after I click the ok button in frame2.

But I am not sure, if I am using the correct frame and correct content.

I tried some frames and content , but it says "Object reference not set to an instance of an object"

 

could you please help!

0
Elena
Telerik team
answered on 11 Jun 2020, 03:07 PM

Hi Nithya,

I am glad to know that you managed to sort out one of the issues you encountered. 

In regards identifying the frame, in which the button to click is located, you will need to explore the specific page you are automating. The example shared in the article is built against a sample page, which uses some frames, though, these will not be the same as in the application you are automating. Thus, the code needs to be adjusted as per the specifics of the page under test. 

Here are some useful resources how you can identify elements using coded solutions. As you mentioned that the application under test is also using frames, it will  be of further help for you to review the respective article how frames are identified when using code. 

I hope these will be helpful for you to sort out the case. If you still cannot identify the frame, please, prepare a snapshot of the DOM tree on the page, where the button to click on, is. This will help me explore the specific application and provide you more precise advice. 

Thank you in advance for your cooperation.

Regards,
Elena
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
General Discussions
Asked by
Nithya
Top achievements
Rank 1
Veteran
Answers by
Paul
Top achievements
Rank 1
Veteran
Elena
Telerik team
Nithya
Top achievements
Rank 1
Veteran
Share this question
or