Combine automation technologies working with complicated desktop applications

Author: Alfonso Alarcón

This is a reality for automated testing engineers! This is the fact! In some occasions, it is practically impossible to generate functional testing on the user interface (UI) of some desktop applications.

Normally, the reason is that the desktop application is based on a code that is written in languages that are not recognized by spy tools or the recognition tool of the selected automation technology. This is very usual in legacy code that is created far of actual technologies.

The situation is more tragic when tools that are in principle powerful, such as the Coded UI Test tool of Visual Studio or HP UFT (to mention just two examples), fail!! In summary, it is a catastrophic situation for automated testing engineer especially when UI testing is essential and required by QA. What should you do? Fortunately, there are solutions.

The most logical solution is to combine different automation technologies (hybridize). I suggest using as the basis a solution of Visual Studio (a console project is enough) and over it work on other technologies. I mention two:

  • AutoIT: Autoit (https://www.autoitscript.com/site/autoit/) is a freeware software to provide automated testing on windows GUI.  You can work with the method of the class AutoItX3Lib. To do it you must download and install AutoIt from https://www.autoitscript.com/site/autoit/ and add the reference of AutoItX3Lib to the solution. Please, also read about https://autohotkey.com/.
  • White: It is a very interesting solution to extend the functionalities of Visual Studio to provide automation testing. It must be added via nuget: https://www.nuget.org/packages/TestStack.White/

It is noteworthy that it is not required any payment version of Visual Studio. With Visual Studio Express or Community versions is enough. In this scenario, you can provide a reliable automation without money expenses.

But possible your company desires to expend a lot of money in automation testing in this case I recommend Ranorex (http://www.ranorex.com/). This is a powerful and complete tool that can provide work on web and GUI, and also in mobiles devices in both android and iOS. My suggestion is to combine Ranorex with Visual Studio (again combine technologies!) for a definite automated testing experience.

Finally, in an ending case Microsoft indicates an extension of the of the Code UI test tool to provide automated solutions where the coded UI tool does not arrive. But this solution is only for heroic automated testing engineers! I provide the next URLs:

https://msdn.microsoft.com/en-us/library/ff398055.aspx

https://msdn.microsoft.com/en-us/library/hh552522.aspx

https://blogs.msdn.microsoft.com/visualstudioalm/2011/10/28/coded-ui-test-extension-for-3rd-party-controls-the-basics-explained/

In conclusion, there is always a hope to automate an inaccessible UI! And remember that the best solution is always combining different automated testing technologies.

 

Advertisements

Automated testing for web application with Visual Studio CodedIUTest without recordings

Author: Ferran Sánchez

If you want to do testing on a web application you can have an alternative with CodedIUTest tool of Visual Studio but without recordings. In this methodology you can use objects such as HtmlHyperlink, HtmlInputButton and HtmlEdit to access to their characteristics directly (see https://automatedtestingtools.wordpress.com/2016/04/19/strategy-to-get-automated-testing-without-recording-actions).

It is known that the recording tool of Visual Studio provides internet explorer as default browser. The key point to work with a different browser is to initialize a static variable BrowserWindow to select the browser and launch web page. For example, if you want to work with Chrome you must write: BrowserWindow.CurrentBrowser = “chrome”;

After that, you can begin the automated testing web. The following example shows this possibility providing data source like a .csv file for data input parameters.

Also, to work with a different browser you must take into account the next preconditions:

1 – Configuration of “Selenium Components for Coded IU Cross”: https://visualstudiogallery.msdn.microsoft.com/11cfc881-f8c9-4f96-b303-a2780156628d/

2 – Troubleshoot: If you have some error when you run tests on Chrome browser, you can download another version on http://selenium-release.storage.googleapis.com/index.html

[CodedUITest]
public class CodedUITest1
{
	// Static var for launch the browser window
	BrowserWindow browser;
	public CodedUITest1()
	{
	}
	// Initialize browser and web page
	[TestInitialize()]
	public void MyTestInitialize()
	{
		BrowserWindow.CurrentBrowser = "chrome";
		browser = BrowserWindow.Launch(new Uri("http://www.amazon.es"));
		browser.Maximized = true;
		browser.CloseOnPlaybackCleanup = false;
	}
	[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\dataAmazon.csv", "dataAmazon#csv", DataAccessMethod.Sequential), DeploymentItem("dataAmazon.csv"), TestMethod]
	public void CodedUITesAmazonHandcoding()
	{
		// Assert Vender tab string
		HtmlHyperlink VenderTabString = new HtmlHyperlink(browser);
		VenderTabString.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, "Vender");
		Assert.AreEqual(
"Vender", VenderTabString.InnerText.Trim());

		HtmlHyperlink VenderTab = new HtmlHyperlink(browser);
		VenderTab.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, "Vender");
		Mouse.Click(VenderTab);
		Playback.Wait(1000);
		// Assert "Vender tus productos" string
		HtmlSpan labelVender = new HtmlSpan(browser);
		labelVender.SearchProperties[HtmlSpan.PropertyNames.InnerText] = "Vende tus productos en Amazon";
		Assert.AreEqual("Vende tus productos en Amazon", labelVender.InnerText.Trim());
		// Assert Ofertas tab string
		HtmlHyperlink OfertasTabString = new HtmlHyperlink(browser);
		OfertasTabString.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, "Ofertas");
		Assert.AreEqual("Ofertas", OfertasTabString.InnerText.Trim());
		Playback.Wait(1000);

		// Assert Ayuda tab string
		HtmlHyperlink AyudaTabString = new HtmlHyperlink(browser);
		AyudaTabString.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, "Ayuda");
		Assert.AreEqual("Ayuda", AyudaTabString.InnerText.Trim());
		HtmlHyperlink AyudaTab = new HtmlHyperlink(browser);
		AyudaTab.SearchProperties.Add(HtmlHyperlink.PropertyNames.InnerText, "Ayuda");
		Mouse.Click(AyudaTab);
		Playback.Wait(1000);
		// Verify "contraseña" wrong
		HtmlHyperlink IdLink = new HtmlHyperlink(browser);
		IdLink.SearchProperties.Add(HtmlHyperlink.PropertyNames.Id, "nav-link-yourAccount");
		Mouse.Click(IdLink);
		//Assert "Contraseña" string
		HtmlLabel labelCont = new HtmlLabel(browser);
		labelCont.SearchProperties[HtmlLabel.PropertyNames.InnerText] = "Contraseña";
		Assert.AreEqual("Contraseña", labelCont.InnerText.Trim());

		HtmlEdit MailInput = new HtmlEdit(browser);
		MailInput.SearchProperties.Add(HtmlEdit.PropertyNames.Id, "ap_email");
		MailInput.Text = TestContext.DataRow["user"].ToString().Trim();
		HtmlEdit PasswordInput = new HtmlEdit(browser);
		PasswordInput.SearchProperties.Add(HtmlEdit.PropertyNames.Id, "ap_password");
		PasswordInput.Text = TestContext.DataRow["password"].ToString().Trim();

		HtmlInputButton IniciarButton = new HtmlInputButton(browser);
		IniciarButton.SearchProperties.Add(HtmlInputButton.PropertyNames.Id, "signInSubmit");
		Mouse.Click(IniciarButton);
		Playback.Wait(10000);
	}

HOW TO CLICK IN HYPERLINKS WITHOUT RECORDING ACTIONS

Author: Alfonso Alarcón

In Coded UI Test solutions of visual Studio (Enterprise, Ultimate or Premium versions) is recommendable to optimize efforts avoiding recording actions when a large numbers of elements must be recorded. See the general strategy from https://automatedtestingtools.wordpress.com/2016/04/19/strategy-to-get-automated-testing-without-recording-actions

In the next method is shown how to click on a hyperlink:

private static Dictionary objDict = UiTestHtmlHyperlinkDict.UiTestHtmlHyperlink();

public static void MouseClickInHyperlink(string dictKey)
{
	Mouse.Click(objDict[dictKey]);
}

As it is shown in the previous code the UI Control of the grid parent is stored in a dictionary. Please see the next post for more information of how to store UI Controls in dictionaries: https://automatedtestingtools.wordpress.com/2016/03/28/how-to-create-dictionaries-to-add-ui-controls

HOW TO CLICK IN BUTTONS WITHOUT RECORDING ACTIONS

Author: Alfonso Alarcón

In Coded UI Test solutions of visual Studio (Enterprise, Ultimate or Premium versions) is recommendable to optimize efforts avoiding recording actions when a large numbers of elements must be recorded. See the general strategy from https://automatedtestingtools.wordpress.com/2016/04/19/strategy-to-get-automated-testing-without-recording-actions

In the next class is shown a method to click in buttons such as ok, cancel, confirm, exit….

public static WinButton WinButton;

private static Dictionary<string, WinButton> objDict = UiTestWinButtonDict.UiTestWinButton();

public static void DoubleClickInButton(string tableKey)
{
	WinButton winButton = objDict[tableKey];
	if (winButton.WaitForControlReady(2000))
	{
		Mouse.DoubleClick(winButton);
	}
	else
	{
		Assert.Fail("The button is not ready or does not exist.");
	}
}

As it is shown in the previous code the UI Control of the grid parent is stored in a dictionary. Please see the next post for more information of how to store UI Controls in dictionaries: https://automatedtestingtools.wordpress.com/2016/03/28/how-to-create-dictionaries-to-add-ui-controls

HOW TO SET VALUES IN WINEDIT BOXES

Author: Alfonso Alarcón

In Coded UI Test solutions of visual Studio (Enterprise, Ultimate or Premium versions) is recommendable to optimize efforts avoiding recording actions when a large numbers of elements must be recorded. See the general strategy from https://automatedtestingtools.wordpress.com/2016/04/19/strategy-to-get-automated-testing-without-recording-actions

In the next class is shown a method to set data in a box using SetProperty():

private static Dictionary<string, WinEdit> objDict = UiTestWinEditDict.UiTestWinEdit();

public static void SetValueInWinEdit(string textComments, string tableKey)
{
	WinEdit winEdit = objDict[tableKey];
	if (winEdit.WaitForControlEnabled(2000))
	{
		winEdit.SetProperty("Text", textComments);
	}
	else
	{
		Assert.Fail("The next value cannot be written in the box: " + textComments);
	}
}

As it is shown in the previous code the UI Control of the grid parent is stored in a dictionary. Please see the next post for more information of how to store UI Controls in dictionaries: https://automatedtestingtools.wordpress.com/2016/03/28/how-to-create-dictionaries-to-add-ui-controls

HOW TO CLICK IN CELL ELEMENTS FROM A PARENT GRID

Author: Alfonso Alarcón

In Coded UI Test solutions of visual Studio (Enterprise, Ultimate or Premium versions) is recommendable to optimize efforts avoiding recording actions when a large numbers of elements must be recorded. See the general strategy from https://automatedtestingtools.wordpress.com/2016/04/19/strategy-to-get-automated-testing-without-recording-actions

Therefore, the best option is to get Coded UI controls from the parent control and to get from it all the children items using the Add a new control to the UIMap tool (see https://automatedtestingtools.wordpress.com/2016/04/11/how-to-capture-ui-control-with-coded-ui-test-builder-without-recording-actions).

In the next example a table grid is presented with two columns.  The strategy to follow is to get only the squared UI Control and from it get both all the cells of the grid.

tablegrid

A method to click in any cell of the grid from the parent element is shown in the next class. The key point is to use first GetCell():

private static Dictionary<string, WinTable> objDict = UiTestTableGridDict.UiTestGridTables();

public static void ClickInCellElement(int row, int colum, string dictKey)
{
	WinTable table = objDict[dictKey];
	UITestControl children = table.GetCell(row, colum);
	if (!children.Enabled)
	{
		Assert.Fail("The cell element is not enabled or does not exist.");
	}
	else
	{
		Mouse.Click(children);
	}
}

As it is shown in the previous code the UI Control of the grid parent is stored in a dictionary. Please see the next post for more information of how to store UI Controls in dictionaries: https://automatedtestingtools.wordpress.com/2016/03/28/how-to-create-dictionaries-to-add-ui-controls