Telerik blogs

Have you thought of including interactions with desktop applications in your tests?

In the “wide” web space you might find many tough ways to use a desktop application in a web test. The main aim of this post is to show you a very simple and fast way to achieve such an interaction.

Speaking from my own experience, I had to create a test that copies the content of a MS Word document in a web control and verify that the pasted content is correct. Since I started my career as a Quality assurance engineer, I had made only web automated tests and making a web test that opens MS Word was a challenge for me.

The tasks to overcome

The most common problems you would face when creating interaction between your web test and a certain desktop application are: how you could open the desktop application, how you could get its content and so on.

The first thing you have to decide is what tool you will use in order to test a desktop application together with a web page.

After some research I tried Sikuli. Sikuli is a tool used to automate and test graphical user interfaces using screenshot images. The tough part in using Sikuli was testing a web page because there was not an easy way to navigate to a page via the screenshot images, so that you can test the behavior of a web control and so on.

Both Sikuli and Telerik Testing Framework are free and here I will tell you why I chose the Telerik Testing Framework:

  • It is the most convenient approach as I could easily integrate this kind of test with the existing suite of web-based unit tests already in place.
  • It is easy and very intuitive to include the interaction with desktop application into a web test.
  • I was able to easily create a data-driven test with more than 10 Word documents.
  • There is no effort in creating a test for each browser as Telerik Testing Framework offers cross-browser test recording and execution.

Telerik Testing Framework gives you the opportunity to not only automate Browser Actions (DOM & UI) but to integrate your test with desktop applications too. You can set references to any namespace you would like to use in your test and extend the diversity of scenarios that a test may cover.

Time for some hands-on experience

I will present you an example of how you can make an automated test that pastes content from Word into a web module. Let’s now see how you can write a test in just four steps!

  1. Open the word document

    In order to open the Word document I use the Process class of the System.Diagnostics namespace that gives you access to start or stop the local system processes on your machine. You just need the path to the document that you’d like to open and the name of its executable file:

    string pathToWordFile = "C:\\Desktop\\Test.docx";
    Process process = Process.Start(new ProcessStartInfo("WINWORD.EXE", pathToWordFile));
  2. Get the content and copy it in the clipboard

    I found at least two ways to use keyboard interactions in your test:

    • Using the System.Windows.Forms.SendKeys class:
      SendKeys.SendWait("enter");
      SendKeys.SendWait("^a");
    • Using the KeyBoard Manager of the Telerik Testing Framework
      Desktop.KeyBoard.KeyPress(Keys.Enter, 1000, 1);
      Desktop.KeyBoard.KeyPress(ArtOfTest.WebAii.Win32.KeyBoard.KeysFromString("Ctrl+A"), 150, 1);

      If you want, you can use System.Windows.Forms.Clipboard to paste some content:

      Clipboard.SetText("testing");
  3. Paste in web control

    I will show you an example with our RadEditor control from Telerik UI for ASP.NET AJAX:

    ActiveBrowser.WaitUntilReady();
    RadEditor editor = Find.ById<RadEditor>("ctl00_ContentPlaceHolder1_RadEditor1");
    Browser contentIframe = ActiveBrowser.Frames.ById("RadEditor1_contentIframe");
    contentIframe.WaitUntilReady();
    contentIframe.Find.AllByTagName<HtmlControl>("body")[0].MouseClick();
     
    SendKeys.SendWait("^v");
  4. Verify that the pasted content is correct
    string expectedContent = "…"; //here in the quotes you should set the expected content
    Assert.AreEqual(expectedContent, filteredContent.ToLower());

The following video shows how the execution of this kind of test goes if you are looking at the screen of the machine that runs it:

Other scenarios that might be covered using this approach:

  • Taking an image from a specified folder and getting it to a web control
  • Copying data from Word, Excel or other text document and pasting it in another application.
  • Test exporting/importing documents (Markdown, PDF etc.) from web controls functionality

Of course, this is not all. Share your experience and what you build with your fellow QAs in the comments below!


Joana Ivanova
About the Author

Joana Ivanova

 

Joana Ivanova has been part of Progress for 10 years. She started her career in the company as a QA Engineer, then changed the track to Software Engineer, and today she is the Manager of the Telerik UI Blazor Team. She is passionate about workflow optimizations, improving productivity and programming. In her spare time, Joana loves playing pool, dancing, driving anything on wheels, hiking and traveling.

 

Related Posts

Comments

Comments are disabled in preview mode.