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 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:
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.
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!
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));
I found at least two ways to use keyboard interactions in your test:
SendKeys.SendWait(
"enter"
);
SendKeys.SendWait(
"^a"
);
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"
);
I will show you an example with our RadEditor control from Telerik UI for ASP.NET AJAX:
ActiveBrowser.NavigateTo(
"http://demos.telerik.com/aspnet-ajax/editor/examples/overview/defaultcs.aspx"
,
true
);
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"
);
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:
Of course, this is not all. Share your experience and what you build with your fellow QAs in the comments below!
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.