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

推荐订阅源

MyScale Blog
MyScale Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
博客园 - 叶小钗
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
爱范儿
爱范儿
小众软件
小众软件
K
Kaspersky official blog
P
Proofpoint News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - Franky
V
Vulnerabilities – Threatpost
博客园_首页
Microsoft Security Blog
Microsoft Security Blog
C
Cybersecurity and Infrastructure Security Agency CISA
V
V2EX
C
Check Point Blog
S
Schneier on Security
P
Palo Alto Networks Blog
IT之家
IT之家
GbyAI
GbyAI
T
Threat Research - Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tailwind CSS Blog
Project Zero
Project Zero
Y
Y Combinator Blog
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
S
Securelist
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理

博客园 - 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;
}