还是以calculator为例,验证add的function,并把测试结果输出到一个txt文件中,在识别pop up menu的时候,如果按照white文档所写会遇到一个问题,自己改了一下还是能识别出来,但不能保证不会有问题。
//Verify "add function"
Core.UIItems.Button nine_button = Window.Get<Core.UIItems.Button>(SearchCriteria.ByAutomationId("139"));
Assert.IsNotNull(nine_button);
nine_button.Click();
Core.UIItems.Button add_button = Window.Get<Core.UIItems.Button>(SearchCriteria.ByAutomationId("93"));
Assert.IsNotNull(nine_button);
add_button.Click();
Core.UIItems.Button eight_button = Window.Get<Core.UIItems.Button>(SearchCriteria.ByAutomationId("138"));
Assert.IsNotNull(eight_button);
eight_button.Click();
Core.UIItems.Button equal_button = Window.Get<Core.UIItems.Button>(SearchCriteria.ByAutomationId("121"));
Assert.IsNotNull(eight_button);
equal_button.Click();
Core.UIItems.Label result_textbox = Window.Get<Core.UIItems.Label>(SearchCriteria.ByAutomationId("150"));
string str;
str = result_textbox.Text;
string a;
a = @"17";
创建带时间戳的文件夹
string folder = "results" + DateTime.Now.ToString("s");
folder = folder.Replace(":", "-");
Directory.CreateDirectory(@"D:/" + folder);
string resultpath = @"D:/" + folder + @"//testresult.txt";
System.IO.FileStream ofs = new FileStream(resultpath, FileMode.CreateNew);
System.IO.StreamWriter sw = new StreamWriter(ofs);
或者是给文件名加不同的时间戳
string stamp = DateTime.Now.ToString("s");
stamp = stamp.Replace(":", "-");
string pathresult = @"D:/result/"+stamp+".txt";
System.IO.FileStream ofs = new FileStream(pathresult, FileMode.CreateNew);
System.IO.StreamWriter sw = new StreamWriter(ofs);
if (a==str)
{
Console.WriteLine("the result is correct!");
sw.WriteLine("pass");
Log.Instance.Info("the result is correct");
}
else
{
Console.WriteLine("the result is not correct!");
sw.WriteLine("Fail");
Log.Instance.Error("the result is not correct");
}
sw.Close();
ofs.Close();
// verify meun item
Core.UIItems.WindowStripControls.MenuBar menubar = Window.MenuBar;
Menu leve1menu = menubar.MenuItem("View", "Programmer");
Thread.Sleep(3000);
Core.UIItems.MenuItems.Menu pro_menu = Window.Get<Core.UIItems.MenuItems.Menu>(SearchCriteria.ByAutomationId("Item 306"));
Thread.Sleep(3000);
pro_menu.Click();
Window.Close();