Skip to content

Instantly share code, notes, and snippets.

Created April 20, 2017 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/aad5667d32f53378a0ec9b464c234f69 to your computer and use it in GitHub Desktop.
Save anonymous/aad5667d32f53378a0ec9b464c234f69 to your computer and use it in GitHub Desktop.
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace CodedUITestProject7.Test_Cases.Workload_List
{
public class Shared_Methods
{
public enum PropertyType
{
InnerText,
Id,
Name
}
/// <summary>
/// Enters text into any HtmlEdit text box using InnerText, ID, or Name to search for the text box.
/// </summary>
public static void EnterText(UITestControl parent, object controlType, PropertyType type, string propertyValue, string text) // Change to generic statement with time
{
if (controlType is HtmlEdit)
{
HtmlEdit edit = new HtmlEdit(parent);
if (type == PropertyType.InnerText)
{
edit.SearchProperties[HtmlEdit.PropertyNames.InnerText] = propertyValue;
}
else if (type == PropertyType.Id)
{
edit.SearchProperties[HtmlEdit.PropertyNames.Id] = propertyValue;
}
else if (type == PropertyType.Name)
{
edit.SearchProperties[HtmlEdit.PropertyNames.Name] = propertyValue;
}
else
{
Debug.WriteLine("The Property Name you tried to enter for method EnterText is not currently supported");
}
edit.Text = text;
//Keyboard.SendKeys(text);
}
else
{
Debug.WriteLine("Attempted to enter text in form that is not currently supported");
}
}
/// <summary>
/// Clicks on any permutation of HtmlCustom, HtmlHyperLink, and HtmlButton with identifiers InnerText, Id, and Name.
/// </summary>
public static void ClickItem(UITestControl parent, object controlType, PropertyType type, string propertyValue) // Change to generic statement with time
{
if (controlType is HtmlCustom)
{
HtmlCustom custom = new HtmlCustom(parent);
if (type == PropertyType.InnerText)
{
custom.SearchProperties[HtmlCustom.PropertyNames.InnerText] = propertyValue;
}
else if (type == PropertyType.Id)
{
custom.SearchProperties[HtmlCustom.PropertyNames.Id] = propertyValue;
}
else if (type == PropertyType.Name)
{
custom.SearchProperties[HtmlCustom.PropertyNames.Name] = propertyValue;
}
else
{
Debug.WriteLine("The Property Name you tried to use for method ClickItem is not currently supported");
}
Mouse.Click(custom);
}
else if (controlType is HtmlHyperlink)
{
HtmlHyperlink link = new HtmlHyperlink(parent);
if (type == PropertyType.InnerText)
{
link.SearchProperties[HtmlHyperlink.PropertyNames.InnerText] = propertyValue;
}
else if (type == PropertyType.Id)
{
link.SearchProperties[HtmlHyperlink.PropertyNames.Id] = propertyValue;
}
else if (type == PropertyType.Name)
{
link.SearchProperties[HtmlHyperlink.PropertyNames.Name] = propertyValue;
}
else
{
Debug.WriteLine("The Property Name you tried to use for method ClickItem is not currently supported");
}
Mouse.Click(link);
}
else if (controlType is HtmlButton)
{
HtmlButton button = new HtmlButton(parent);
if (type == PropertyType.InnerText)
{
button.SearchProperties[HtmlButton.PropertyNames.InnerText] = propertyValue;
}
else if (type == PropertyType.Id)
{
button.SearchProperties[HtmlButton.PropertyNames.Id] = propertyValue;
}
else if (type == PropertyType.Name)
{
button.SearchProperties[HtmlButton.PropertyNames.Name] = propertyValue;
}
else
{
Debug.WriteLine("The Property Name you tried to use for method ClickItem is not currently supported");
}
Mouse.Click(button);
}
else
{
Debug.WriteLine("The control type you attempted to click on is currently unupported");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment