Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2039472
  • 博文数量: 519
  • 博客积分: 10070
  • 博客等级: 上将
  • 技术积分: 3985
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-29 14:05
个人简介

只问耕耘

文章分类

全部博文(519)

文章存档

2016年(1)

2013年(5)

2011年(46)

2010年(220)

2009年(51)

2008年(39)

2007年(141)

2006年(16)

我的朋友

分类:

2009-11-21 18:21:33

随便用一个小例子来解释一下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;
}

阅读(665) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~