




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精选优质文档-倾情为你奉上软件测试实习报告 班级: 软件122 学号: 姓名: 孙剑峰 指导老师: 王晖 实习时间: 15.11.30-15.12.4 1、 需求分析说明书软件行业的产业化发展对软件的质量及其开发效率都提出了较高要 求,而软件测试作为软件开发项目管理中软件质量保证的关键,正发挥着越来越重要的作用,自动化测试作为提高软件测试效率的重要手段也被更多的软件开发者所 重视。本文根据Windows平台下UI自动化测试的需求,基于.NET框架,采用数据驱动模型设计并实现了一套UI自动化测试系 统。使用底层的Windows自动化测试技术通过用户界面(UI)来测试应用程序。这些技术涉及Win3
2、2API函数的调用(比如FindWindow()函数)以及向待测程序(AUT)发送Windows消息(比如WM_LBUTTONUP)。所有的Windows控件本质上都是一个窗体(window)。每个控件/窗体都有一个与之关联的句柄(handle),可以通过这个句柄来访问、操纵和检测这个控件和检测这个控件/窗体。对于轻量级的、底层的Windows窗体UI自动化测试程序来说,需要完成的工作主要有以下三类:找到目标窗体/控件的句柄操作这个窗体/控件检测这个窗体/控件2、 项目开发计划2.1、计划分项目阶段本项目分为如下部分:资料搜集:搜集关于Win32API的资料与一些官方测试资料。需求分析:分析本
3、项目的软件需求并细化。软件设计:设计软件结构。软件编写:使用不同语言编写软件。实验分析:设计数据库并进行实验。完成报告:完成最终试验测试报告。2.2、计划分项目工作内容系统阶段重点工作完成指标完成时间前期工作1. 了解Win32API2. 需求分析1. 利用官方提供进行WidowsUI2. 完成需求报告2015/12/2算法建立1. 项目设计2. 软件编写1. 完成项目设计报告书2. 编写程序2015/12/7试验测试1. 设计实验2. 结果分析1. 完成报告2015/12/83、软件设计说明书通过句柄获取待测程序的一个窗口,按钮,图标,输出设备,控件等。使用大量的Win32API调用来操作W
4、indows窗体应用程序。1. 使用System.Disgnostics.Process.Start()方法启动程序。2. 获得待测程序主窗体的句柄要获得待测程序主窗体的句柄,可使用FindWindow() Win32 API函数来解决这个问题。C#要使用Win32 API函数FindWindow(),可通过.Net平台的invoke(P/Invoke)机制,P/Invoke相关特性位于System.Runtime.InteropServices命名空间内。C#签名如下:DllImport("user32.dll", EntryPoint = "FindWindo
5、w", CharSet = CharSet.Auto) static extern IntPtr FindWindow(string lpClassName, string lpWindowName);3. 获得有名字控件的句柄C#签名如下:DllImport("user32.dll", EntryPoint = "FindWindowEx",CharSet = CharSet.Auto)9 static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, s
6、tring lpszClass, string lpszWindow);4. 获得无名字控件的句柄获得一没有名字空间的句柄,可通过隐含索引来查找相应控件。5. 发送字符给控件我们要发送一个。当按键按下时,VM_CHAR消息会发送给拥有键盘焦点的那个控件。实际上,VM_CHAR是一个Windows的常量符号,它定义为0x0102。wParam参数指定的是被按下按键的字符代码。lParam参数指定的是不同的按键状态码,比如重复次数、扫描码等。有了这些信息,就可以创建相应的C#签名: DllImport("user32.dll", EntryPoint = "SendM
7、essage", CharSet = CharSet.Auto) static extern void SendMessage1(IntPtr hWnd, uint Msg, int wParam, int lParam);6、鼠标单击一个控件PostMessage()和SendMessage()的参数列表完全一致,他们的不同是:SendMessage()会等相应的Windows消息之后才会返回;PostMessage()不会。相应的C#签名:DllImport("user32.dll", EntryPoint = "PostMessage",
8、 CharSet = CharSet.Auto)static extern bool PostMessage1(IntPtr hWnd, uint Msg, int wParam, int lParam);7. 处理消息对话框消息对话框是一个上层(top-level)窗体,使用FindWindow()函数捕获它。8、处理菜单9、检查应用程序状态10、 使用VM_GETTEXT和SendMessage()获得控件状态4、测试用例设计设计待测窗体: 待测程序是一个用来做颜色混合的应用程序,设计的窗口如下:菜单栏的结构如下:File Edit HelpNew Cut AboutSave Copy U
9、pdateExit Paste5、软件测试分析报告5.1 实验过程:系统:Windows10开发环境:VS20101. 安装VS2010开发环境2. 编写Form窗体,包括Textbox,ComboBox,Button,ListBox。其核心代码为: private void button1_Click(object sender, EventArgs e) string tb = textBox1.Text; string cb = comboBox1.Text; if (tb = "<enter color>" | cb = "<pick&g
10、t;") MessageBox.Show("You need 2 colors", "Error"); else if (tb = cb) listBox1.Items.Add("Result is " + tb); else if (tb = "red" && cb = "blue" | tb = "blue" && cb = "red") listBox1.Items.Add("Result is p
11、urple"); else listBox1.Items.Add("Result is black"); 3. 创建测试程序初始化测试程序5.2 实验结果与分析Launching application undertestWarning: process may already existForm not yet foundForm not yet foundForm has been foundMain windows handle = Finding handle to textBox1Handle to textbox1 is Handle to combo
12、x1 is Handle to button1 is Handle to listbox1 is Clicking button1Clicking away Error message boxForm has been foundTyping 'red' and 'blue' to applicationChecking the contents of textBox1Fetched 3charsTextBox1 contains = red Clicking on button1Checking listBox1 for 'purple'0Te
13、st scenario result = PassHandle to menu is Handle to main help is Index to about is 265Handle to HelpItem2 is Index to HelpItem2SubItem2 is 269Exiting app in 4 seconds . . .DoneForm窗体显示为:其中,得出分析:Main windows handle = 获得textbox控件句柄成功Handle to textbox1 is 获得Form中textbox控件句柄Handle to combox1 is 获得Form中
14、Comobox控件句柄Handle to button1 is 获得Form中Button控件句柄Handle to listbox1 is 获得Form中Listbox控件句柄Listbox中显示“Result is purple”,测试代码输出“Test scenario result = Pass”表明本次WindowsUI测试成功。6、源程序测试端主要用于测试的代码为static void Main(string args) try Console.WriteLine("nLaunching application undertest"); string path
15、= "D:ProjectWindowsUITestWinAppWinAppbinDebugWinApp.exe" Process p = Process.Start(path); if (p != null) Console.WriteLine("Warning: process may already exist"); IntPtr mwh = FindMainWindowsHandle("Form1",100,25); Console.WriteLine("Main windows handle = " + m
16、wh); Console.WriteLine("Finding handle to textBox1"); IntPtr tb = FindWindowEx(mwh, IntPtr.Zero, null, "<enter color>"); IntPtr cb = FindWindowByIndex(mwh, 3); IntPtr butt = FindWindowEx(mwh, IntPtr.Zero, null, "button1"); IntPtr lb = FindWindowByIndex(mwh, 1); if
17、 (tb=IntPtr.Zero) throw new Exception("Unable to find textbox1"); else Console.WriteLine("Handle to textbox1 is "+tb); if (cb = IntPtr.Zero) throw new Exception("Unable to find combox1"); else Console.WriteLine("Handle to combox1 is " + cb); if (butt = IntPtr.
18、Zero) throw new Exception("Unable to find button1"); else Console.WriteLine("Handle to button1 is " + butt); if (lb = IntPtr.Zero) throw new Exception("Unable to find listbox1"); else Console.WriteLine("Handle to listbox1 is "+lb); Console.WriteLine("Clic
19、king button1"); ClickOn(butt); Console.WriteLine("Clicking away Error message box"); Thread.Sleep(1000); IntPtr mb = FindMessageBox("Error"); if (mb = IntPtr.Zero) throw new Exception("Unable to find message box"); IntPtr okButt = FindWindowByIndex(mb,1); if (okBut
20、t = IntPtr.Zero) throw new Exception("Unable to find OK button"); ClickOn(okButt); Console.WriteLine("Typing 'red' and 'blue' to application"); SendChars(tb, "red"); Console.WriteLine("Checking the contents of textBox1"); uint WM_GETTEXT = 0x00
21、0D; byte buffer = new byte256; string text = null; int numFetched = SendMessage3(tb, WM_GETTEXT, 256, buffer); text = System.Text.Encoding.Unicode.GetString(buffer); Console.WriteLine("Fetched " + numFetched + "chars"); Console.WriteLine("TextBox1 contains = " + text);
22、ClickOn(cb); SendChars(cb, "bbblue"); Console.WriteLine("Clicking on button1"); ClickOn(butt); Console.WriteLine("Checking listBox1 for 'purple'"); Thread.Sleep(2000); uint LB_FINDSTRING = 0x018F; int result = SendMessage4(lb, LB_FINDSTRING, -1,"Result is p
23、urple"); Console.WriteLine(result); if (result >= 0) Console.WriteLine("Test scenario result = Pass"); else Console.WriteLine("Test scenario result = FAIL"); IntPtr hMainMenu = GetMenu(mwh); Console.WriteLine("Handle to menu is "+hMainMenu); IntPtr hHelp = GetSubMenu(hMainMenu, 2); Console.WriteLine("Handle to main help is " + hHelp); int iAbout = GetMenuItemID(hHelp, 0); Console.WriteLine("Index to about is " + iAbout); IntPtr hSub = GetSubMenu(hHelp, 2); Console.WriteLine("Handle to HelpItem2 is &q
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年螺旋型荧光灯管项目发展计划
- 网络安全评估与维护保障服务协议
- 咨询服务合同合同
- 劳动协议集体劳动协议
- 软件业软件开发与运维管理解决方案
- 汽车零部件行业供应链管理与优化方案设计
- 2025年抗高血压药物项目建议书
- 生活用品销售与售后服务合同
- 工程转让居间合同
- 2025年主任医师考试缴费指南:流程解析与高效备考策略
- 2024年陕西省普通高中学业水平合格性考试历史试题(解析版)
- 中国干眼临床诊疗专家共识(2024年)解读
- 2mm土工膜长丝土工布检测报告合格证
- 一年级家长会课件2024-2025学年
- 拉美文化学习通超星期末考试答案章节答案2024年
- 校长思政课课件-百年奥运
- 文艺复兴经典名著选读智慧树知到期末考试答案章节答案2024年北京大学
- 小小科学家《物理》模拟试卷A(附答案)
- 体能科学训练方法智慧树知到期末考试答案2024年
- 电力定额问题解答汇总
- 欧盟RoHS2.0指令附件III及附件IV豁免清单(45页)
评论
0/150
提交评论