Problem with KeyDown function

4 posts, 0 answers
  1. Amos
    Amos avatar
    11 posts
    Member since:
    Oct 2010

    Posted 13 Dec 2011 Link to this post

    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
  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 13 Dec 2011 Link to this post

    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.
  3. Amos
    Amos avatar
    11 posts
    Member since:
    Oct 2010

    Posted 15 Dec 2011 Link to this post

    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?
  4. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 15 Dec 2011 Link to this post

    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.
Back to Top
  Cast Your Vote at DevPro Connections! Cast Your Vote at  Win IT Pro Connections!