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

Unable to close pdf of new window

12 Answers 106 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Noorain
Top achievements
Rank 1
Noorain asked on 26 Mar 2018, 03:59 PM

Hi , 

I have an Agreement pdf file which is displayed on a new window,once i click on a link (with property of an button). I am not able to close that window as it is not detecting. Because of this new window , the old window steps are failing . 

Can you please help me with it . 

 

Thanks, 

Noorain

 

12 Answers, 1 is accepted

Sort by
0
Nikolay Petrov
Telerik team
answered on 29 Mar 2018, 11:31 AM
Hello Noorain,

In this case, you may try to handle this window using a key combination in a coded step or to apply a blind desktop click for example to close it. 

I hope this helps.

Best Regards,
Nikolay Petrov
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Noorain
Top achievements
Rank 1
answered on 29 Mar 2018, 06:36 PM

Hi Nikolay,

I tried doing it , but Manager.Desktop.KeyBoard.SendString() is not recognizable .

 

Regards,

Noorain

0
Noorain
Top achievements
Rank 1
answered on 29 Mar 2018, 08:30 PM

Hi Nikolay, 

As I mentioned its a PDF document which opens in a new window , I am not able to inspect the page at all, which means i cant see any elements. This narrows down that I am not able to use blind desktop click. 

 

Looking forward for your updates.

 

Regards,

Noorain

 

0
Nikolay Petrov
Telerik team
answered on 02 Apr 2018, 01:18 PM
Hi Noorain,

Indeed the PDF opened in a new window will not be accessible for automation. This is the reason to suggest here to use the blind mouse click or some desktop key sequence. 

Please, specify what problems you faced when trying to use send keystrokes in a coded step. Did you add a reference to the project and using on the System.Windows.Forms.dll as explained in the provided article? 

A blind desktop click is possible to add using this line of code when introduce X and Y coordinates of the point to be clicked on:

Manager.Desktop.Mouse.Click(ArtOfTest.WebAii.Core.MouseClickType.LeftClick, X_coordinate, Y_coordinate);

I hope this helps.

Best Regards,
Nikolay Petrov
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Noorain
Top achievements
Rank 1
answered on 06 Apr 2018, 05:49 PM

Hi Nikolay, 

Thanks for your updates. 

I downloaded systems.windows.form dll. 

And used the below code 

1. Its closing my application. 

           Manager.Desktop.KeyBoard.KeyDown(System.Windows.Forms.Keys.Alt);

            Manager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.F4);
            Manager.Desktop.KeyBoard.KeyUp(System.Windows.Forms.Keys.Alt);

2. Its doing nothing.(My PDF file in new window is still open)

             Manager.Desktop.KeyBoard.KeyDown(System.Windows.Forms.Keys.Alt);
             Manager.Desktop.KeyBoard.KeyDown(System.Windows.Forms.Keys.F);
             Manager.Desktop.KeyBoard.KeyDown(System.Windows.Forms.Keys.X);

Basically that new window is not recognizable by telerik.

Any workaround?

 

Thanks,

Noorain 

0
Ivaylo
Telerik team
answered on 11 Apr 2018, 11:10 AM
Hello Noorain,

Let me interject into this ticket as Nikolay is no longer with the company.

From all the previous posts it is not clear whether this is a separate browser window or this pdf is opened in Acrobat Reader. If the file is opened in Acrobat Reader you can simply kill the process in order to close is. Refer to the code snippet below on how to proceed:

var procs = System.Diagnostics.Process.GetProcessesByName("acrord32");
            foreach (var process in procs)
            {
                process.Kill();
            }

If the pdf opens in a new browser window please provide a screenshot of what is displayed so we can assist you further.

Regards,
Ivaylo
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Noorain
Top achievements
Rank 1
answered on 11 Apr 2018, 01:37 PM

Hi Ivaylo,

Thanks for the update. The PDF opens in a new browser window,please find attached screenshot for the same.

Regards,

Noorain

0
Noorain
Top achievements
Rank 1
answered on 11 Apr 2018, 01:41 PM
As in the screenshot,  ViewAgreement is where i click and then a new window opens with the pdf
0
Accepted
Ivaylo
Telerik team
answered on 13 Apr 2018, 02:00 PM
Hello Noorain,

Thank you for your update. This will be a bit more complicated scenario but not impossible to automate. You'll need to use two coded steps. One of the steps should be placed before the click which opens the PDF, the other one should be after the click.

The first coded step counts the browsers before the click:

private int browserCount;
        
       [CodedStep(@"Get Browser Count Before Click")]
       public void Bing_CodedStep()
       {
           browserCount = Manager.Browsers.Count;
           Log.WriteLine("Browser count before = " +browserCount);
       }

Make sure you define the global variable browserCount.

The second coded step waits and verifies that the browser count has increased and closes the last opened browser, which in your case should be the PDF window:


[CodedStep(@"Close last opened browser window")]
        public void Bing_CodedStep1()
        {
            int timeout = 0;
            int currentCount = browserCount;
            while(currentCount == browserCount)
            {
                System.Threading.Thread.Sleep(1000);
                if(timeout <10)
                {
                    browserCount = Manager.Browsers.Count;
                }
                else
                {
                    Assert.IsFalse(true,"Did not find new window");
                }
                timeout = timeout + 1;
            }
             
            Manager.Browsers.Last().Close();
        }

I am attaching you also a sample project demonstrating how this is working on my end with Bing.com website.

Hope that helps.

Regards,
Ivaylo
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Noorain
Top achievements
Rank 1
answered on 13 Apr 2018, 02:19 PM

Hi Ivaylo,

It worked !!!!!

Awesome. 

Thanks for the solution. Great job .

We can close this ticket. 

Regards,

Noorain

0
Noorain
Top achievements
Rank 1
answered on 13 Apr 2018, 02:21 PM

Hi Ivaylo, 

One quetion, not relating to this topic. 

Can we automate any field which does not detect as id.

For example: Click Div

 

Regards,

Noorain

0
Elena
Telerik team
answered on 18 Apr 2018, 07:47 AM
Hello Noorain,

The Testing Framework allows you to use all attributes to build a find expression for locating elements. So in the case when there is no id or it is dynamic you could choose another unique attribute or a set of unique attributes to identify an element. 

I hope this will be useful for you. Though in case you would need any further assistance please let us know. Thanks! 

Regards,
Elena Tsvetkova
Progress Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Noorain
Top achievements
Rank 1
Answers by
Nikolay Petrov
Telerik team
Noorain
Top achievements
Rank 1
Ivaylo
Telerik team
Elena
Telerik team
Share this question
or