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

Problem with KeyDown function

5 Answers 144 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Amos
Top achievements
Rank 1
Amos asked on 13 Dec 2011, 12:07 PM
Hi,
I have a problem with this code:

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

This code don't work correctly.
I have noticed that with this code during the test not the Alt key is pressed but the AltGr key  
For this test I use Windows 7 64 bit, IE 8, Visual Studio 2010 and Telerik.TestStudio.2011.2.1209.
Can you help me?
Thank you.
Amos

5 Answers, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 13 Dec 2011, 09:25 PM
Hello Amos,

I tested this code in the exact same environment and it worked as expected. Are you using an English US keyboard layout through the Control Panel? Does your physical keyboard actually have an AltGr key?

From a higher level, I'm curious why you're invoking this specific combination of key presses through Test Studio. As I'm sure you're aware, Alt+F4 is a Windows shortcut to close the active window or program. Browser or application windows should not be closed this way through Test Studio. The ActiveBrowser (or ActiveApplication) window will close automatically at the end of the test, and HTML popups are handled in code like this.

Kind regards,
Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Amos
Top achievements
Rank 1
answered on 15 Dec 2011, 12:30 PM
Hello Anthony,
I use an Italian keyboard and my physical keyboard has the AltGr key.
I use this code to close a page that contains a PDF document [http://www.telerik.com/automated-testing-tools/community/forums/test-studio-express/general-discussions/problem-with-pages-that-contain-pdf-documents.aspx].
With old version of Test Studio this code works correctly.
So, or I change my language setup or I have to downgrade my Test Studio?
0
Anthony
Telerik team
answered on 15 Dec 2011, 11:01 PM
Hello Amos,

Thank you for the clarification. The issue is that the HTML popup is loading a PDF file. A PDF file loaded in the browser does not have a DOM structure like a traditional web page, so Test Studio cannot read or verify against its contents. It is also not added to the ActiveBrowser collection, so you can't close it like a normal HTML popup with the ActiveBrowser.Close() code.

The work-around you found in that forum post is a crude way to handle this limitation. We recently made a change to the way coded key presses are interpreted in Test Studio, so I'll check with my developers and see if that affected the AltGr key.

I now do not believe the issue is with the keyboard country layout through the Control Panel (English vs. Italian), but whether the physical keyboard contains the AltGr key. In other words, if you test this with a keyboard without that key (and only the standard Alt key), I believe it will work.

From a higher level, we recommend not even opening the PDF popup because of the limitation previously mentioned. The only reason to open it would be to visually verify that the PDF loads. We came up with an alternative that verifies the PDF URL and returns a response without actually loading it in the window or downloading it:

public bool CheckAddress()
{
    try
    {
        WebRequest request = WebRequest.Create("http://www.someurl.com/test.pdf");
        WebResponse response = request.GetResponse();
    }
    catch (Exception ex)
    {
        return false;
    }
    return true;
}
         
[CodedStep(@"New Coded Step")]
public void PdfPopup_CodedStep1()
{  
    //Use the Log line (but not the Assert) if you want the step to always pass,
    //yet report a True or False to the log based on response
    Log.WriteLine(CheckAddress().ToString());
    //Use the Assert line if you want the step to pass if the response is True,
    //yet fail if it's False
    Assert.IsTrue(CheckAddress());
}

   Best wishes,
Anthony
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Francisco
Top achievements
Rank 1
answered on 23 Feb 2017, 04:19 PM

Is there an update to this? 

Trying to close a modal that loads a PDF file in IE.

0
Elena
Telerik team
answered on 28 Feb 2017, 12:40 PM
Hello Francisco,

Since you are referring to a quite old post I would like to ask for further details on the issue you are facing. Since the file is a PDF one loaded in the browser I would like to note that it wouldn't be possible to automate any of its content due to the same reason stated in the previous reply - there is no DOM tree. 

However you should be able to automate opening and closing the popup window with Test Studio. What is the behavior you are observing? 

Regards,
Elena Tsvetkova
Telerik by Progress
 
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
 
Tags
General Discussions
Asked by
Amos
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Amos
Top achievements
Rank 1
Francisco
Top achievements
Rank 1
Elena
Telerik team
Share this question
or