Unable to close pdf of new window

13 posts, 1 answers
  1. Noorain
    Noorain avatar
    21 posts
    Member since:
    Feb 2018

    Posted 26 Mar Link to this post

    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

     

  2. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 29 Mar Link to this post

    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!
  3. Noorain
    Noorain avatar
    21 posts
    Member since:
    Feb 2018

    Posted 29 Mar in reply to Nikolay Petrov Link to this post

    Hi Nikolay,

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

     

    Regards,

    Noorain

  4. Noorain
    Noorain avatar
    21 posts
    Member since:
    Feb 2018

    Posted 29 Mar in reply to Nikolay Petrov Link to this post

    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

     

  5. Nikolay Petrov
    Admin
    Nikolay Petrov avatar
    308 posts

    Posted 02 Apr Link to this post

    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!
  6. Noorain
    Noorain avatar
    21 posts
    Member since:
    Feb 2018

    Posted 06 Apr in reply to Nikolay Petrov Link to this post

    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 

  7. Ivaylo
    Admin
    Ivaylo avatar
    775 posts

    Posted 11 Apr Link to this post

    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!
  8. Noorain
    Noorain avatar
    21 posts
    Member since:
    Feb 2018

    Posted 11 Apr Link to this post

    Hi Ivaylo,

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

    Regards,

    Noorain

  9. Noorain
    Noorain avatar
    21 posts
    Member since:
    Feb 2018

    Posted 11 Apr in reply to Noorain Link to this post

    As in the screenshot,  ViewAgreement is where i click and then a new window opens with the pdf
  10. Answer
    Ivaylo
    Admin
    Ivaylo avatar
    775 posts

    Posted 13 Apr Link to this post

    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!
  11. Noorain
    Noorain avatar
    21 posts
    Member since:
    Feb 2018

    Posted 13 Apr in reply to Ivaylo Link to this post

    Hi Ivaylo,

    It worked !!!!!

    Awesome. 

    Thanks for the solution. Great job .

    We can close this ticket. 

    Regards,

    Noorain

  12. Noorain
    Noorain avatar
    21 posts
    Member since:
    Feb 2018

    Posted 13 Apr Link to this post

    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

  13. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    938 posts

    Posted 18 Apr Link to this post

    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!
Back to Top