Being a bignner in CodedUI i have small query suppose we write some UI tests for "Login" Screen in UIMap class like below
public void IsValidUser()
{
//Define sample app Main window
WpfWindow mainWindow = new WpfWindow();
mainWindow.SearchProperties.Add(WpfWindow.PropertyNames.Name, "ValidatingControlsView");
mainWindow.SearchProperties.Add(WpfWindow.PropertyNames.ControlType, "Window");
mainWindow.WindowTitles.Add("ValidatingControlsView");
//Username text box
WpfEdit txtusrname = new WpfEdit(mainWindow);
txtusrname.SearchProperties.Add(WpfButton.PropertyNames.AutomationId, "txtUsername");
txtusrname.WindowTitles.Add("ValidatingControlsView");
Keyboard.SendKeys(txtusrname, "XXXXX");
//Passsowrd Textbox
WpfEdit txtpasword = new WpfEdit(mainWindow);
txtpasword.SearchProperties.Add(WpfButton.PropertyNames.AutomationId, "txtpassword");
txtpasword.WindowTitles.Add("ValidatingControlsView");
txtpasword.Text = "XXXXX";
//Login button Click
WpfButton blogin = new WpfButton(mainWindow);
blogin.SearchProperties.Add(WpfButton.PropertyNames.AutomationId, "btnLogin");
Playback.Wait(1000);
Mouse.Click(blogin);}
Now Suppose i want to check all validation checks i.e both Positive ad negative what is best way to write them .i have tried below but i dont know it is the best way or not.
//validation checks
string expectedUsername = "XXXX";
string expectedPassword = "XXXXX";
if (!string.IsNullOrEmpty(txtusrname.ToString()) && !string.IsNullOrEmpty(txtpasword.ToString()))
{
if (txtusrname.ToString() == expectedUsername && txtpasword.ToString() == expectedPassword)
{
Assert.IsTrue(true, "Message.");
}
else { Assert.IsFalse(false, "Message"); }
}
else
{
Assert.IsFalse(false, "Message.");
}
Aucun commentaire:
Enregistrer un commentaire