惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

美团技术团队
B
Blog RSS Feed
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Google DeepMind News
Google DeepMind News
D
Docker
Blog — PlanetScale
Blog — PlanetScale
M
MIT News - Artificial intelligence
C
Check Point Blog
The Cloudflare Blog
T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
量子位
The GitHub Blog
The GitHub Blog
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
T
The Blog of Author Tim Ferriss
博客园 - 【当耐特】
Vercel News
Vercel News
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
V
V2EX
博客园 - 司徒正美

博客园 - yufun

Windows GUI自动化测试技术的比较和展望 双屏(Daul Monitor)很爽 ChromePlus很好用,已经替代我的Firefox了 很久没来了,更新一下状态 小议云计算和Live Mesh、网络存储 [转载] 我的测试观点与经验 获取当前操作系统的版本 - yufun - 博客园 获取当前执行的函数(Testcase)名称 C#中三种截屏方式总结 搬家完成 你是否知道-你可把代码段拖拽到Toolbox里边 跟UI自动化测试有关的技术 转载:关于开发和测试 转载:再谈UI自动化测试 转载:用一个小例子来说明手工测试,自动化测试,系统命令,编程语言,API的关系 各类搜索网站 在自动化测试中,如果控件不能识别,你会怎么做? 在C#中如何模拟鼠标键盘操作 - yufun - 博客园 在C#中调用API进行截屏
转载:一个UI自动化的小例子
yufun · 2009-01-12 · via 博客园 - yufun

2009-01-12 17:03  yufun  阅读(635)  评论()    收藏  举报

转载自:http://peking2toronto.spaces.live.com/Blog/cns!A975CAF18FBB985B!411.entry?wa=wsignin1.0

随便用一个小例子来解释一下UI自动化的开发吧.

我先现在有一个Button是disable的状态,一旦Button enable,我们就Click弹出一个窗口.

我们使用的测试工具就有同步的功能.

1.自动化工具生成的程序(发现和操作控件,不能真正运行)

button=FindButton();

ClickButton(button);

2.傻瓜的自动化程序(通过加入sleep变成可以运行的程序)

button=FindButton();

Sleep(10);

ClickButton(button);

Sleep(10);

window=FindWindow();

3.简单的自动化程序(加入同步,使得更可靠和有效率)

button=FindButton();

WaitButtonEnable(button);

ClickButton(button);

window=WaitWindowOpen();

4.完整的自动化程序(保证100%可靠,没有测试程序bug,简单写了一下,没有包含exception的控制,时间急,可能也会有错误,不过就是这个意思)

Button button=null;
for(int i=0;button==null&&i<3;i++) //如果FindButton不稳定,调用三次in case
{
    button=FindButton();
    if(button==null)
    {
        Log.Error("Tryout{0}:Can not find button",i); //测试工具不稳定
    }
    else
    {
        break;
    }
}

if(button==null)
{
    Log.Error("Cannot find button. Quit"); //测试工具找不到button,或者产品问题
    Log.Screen();//截图,只是为了示例,以后不再单独写
    return;
}

if(!WaitButtonEnable(button))
{
    if(button.Enabled==true) //测试工具问题,没有得到enable的消息
    {
        Log.Error("enabled, but tool didn't detect");
    }
    else//测试工具问题,不能成功检测button的状态,或者产品问题没有enable
    {
        Log.Error("don't enable");                      return;                                                                                                                                                                                                                                                                                                                
    }
}

Window window=null;

for(i=0;window==null&i<3;i++)//ClickButton不稳定,或者没有得到open event,或者产品问题
{
    ClickButton(button);
    window=WaitWindowOpen();
    if(window==null)//没有click或者没有得到消息,或者产品问题
    {
        int count=0;
findwindow://FindWindow不稳定,重试3次
        window=FindWindow();
        if(window!=null) //没有得到消息,但是窗口弹出
        {
            Log.Error("didn't get event");
            break;
        }
        else //没有click,或者产品问题, 或者FindWindow不稳定
        {
            Log.Error("Tryout{0}:didn't get window",i);
            count++;
            if(count>3)
            {
            }
            else //FindWindow不稳定,workaround
            {
                Log.Error("goto{0}",count);
                goto findwindow;
            }
        }
    }
    else //成功
    {
        break;
    }
}

if(window==null)
{
    Log.Error("didn't get window, maybe tool or product problem.");
    return;
}