bytedance / Fastbot_iOS

About Fastbot(2.0) is a model-based testing tool for modeling GUI transitions to discover app stability problems
Other
563 stars 114 forks source link

stub过滤控件后,仍然会操作到 #68

Open songke opened 2 years ago

songke commented 2 years ago

1、/view 接口返回数据不稳定,同个控件有时候会获取不到label,label返回空,但是其他属性visible、rect都正常

2、在describeUIView中根据label过滤掉不想操作的黑名单控件,通过/view接口可以看到控件已经不返回,但是执行fastbot test时,仍然会操作到。且不一定是因为问题1导致,因为在过滤时加了日志,可以看到一直有访问/view,且每次都跳过了黑名单控件 fastbot test执行期间,stub日志:

默认  20:09:37.889425+0800    WDBWebViewDemo  receive request path = /view -- http://127.0.0.1:9797/, /view, application/json
默认  20:09:37.889487+0800    WDBWebViewDemo  request body data {}
默认  20:09:37.890296+0800    WDBWebViewDemo  跳过控件:AlertTest2

stub部分代码:

// describe current App windows
-(NSDictionary*) describePages
{
    ...
    for(UIView* view in sortedWindows)
    {
        NSDictionary *viewDesc = [self describeUIView:view];
        if (viewDesc) {
            [pages addObject:viewDesc];
        }
    }
}
-(NSDictionary *) describeUIView:(UIView *)view
{
    if (([view accessibilityLabel]) && ([[view accessibilityLabel]isEqualToString: @"AlertTest2"])) {
        NSLog(@"跳过控件:AlertTest2");
        return nil;
    }
   ...
    if (subviews.count > 0) {
        for (UIView *view in subviews) {
            NSDictionary *subViewDesc = [self describeUIView:view];
            if (subViewDesc) {
                [viewDesc[@"children"] addObject:subViewDesc];
            }            
        }
    }
}
geron-cn commented 2 years ago

可能是该位置有其他控件被解析到,建议可以根据区域(bounds)来裁剪。

发自我的iPhone

在 2021年11月19日,19:54,songke @.***> 写道:

 1、/view 接口返回数据不稳定,有时候会获取不到label,label返回空,但是其他属性visible、rect都正常

2、在describeUIView中根据label过滤掉不想操作的黑名单控件,通过/view接口可以看到控件已经不返回,但是执行fastbot test时,仍然会操作到。且不一定是因为问题1导致,因为在过滤时加了日志,可以看到一直有访问/view,且跳过了黑名单控件

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

geron-cn commented 2 years ago

可能是该位置有其他控件被解析到,建议可以根据区域(bounds)来裁剪。 发自我的iPhone 在 2021年11月19日,19:54,songke @.***> 写道:  1、/view 接口返回数据不稳定,有时候会获取不到label,label返回空,但是其他属性visible、rect都正常 2、在describeUIView中根据label过滤掉不想操作的黑名单控件,通过/view接口可以看到控件已经不返回,但是执行fastbot test时,仍然会操作到。且不一定是因为问题1导致,因为在过滤时加了日志,可以看到一直有访问/view,且跳过了黑名单控件 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

先利用属性定位到 bounds, 然后再用这个bounds 去筛选掉所有和中心点在这个 bounds 的控件。

songke commented 2 years ago

嗯,是有这种情况,比如操作页面的滑动,可能会点击到要屏蔽的黑名单控件。但是这个问题不是,为了实验,只画了两个button,要屏蔽的button是CGRectMake(50, 200, 100, 50); 坐标为:leftX:50, topY:200, rightX:150, bottomY:250

1、label方式屏蔽 fastbot test日志:

2021-11-22 14:03:13.031916+0800 FastbotRunner-Runner[1775:394756] ticker spy  desc cost 0.104022  netact  0.000321 second, left 34.116669s
2021-11-22 14:03:13.761341+0800 FastbotRunner-Runner[1775:394482] state g0s0 action CLICK pos[51,201,149,249] throttle 0.30
2021-11-22 14:03:14.100074+0800 FastbotRunner-Runner[1775:394922] get page desc from spy failed! :
[fastbot] : select new action from unvisited Unsaturated
[fastbot] : total visit count is 15
[fastbot] : state visited: 5
[fastbot] : action first visited, get reward 1.000000
[fastbot] : got reward: 15.7309
[fastbot] : build state cost: 0.000s action cost: 0.000s total cost 0.000s

stub日志:

默认    11:25:59.530545+0800    WDBWebViewDemo    receive request path = /view -- http://127.0.0.1:9797/, /view, application/json
默认    11:25:59.530602+0800    WDBWebViewDemo    request body data {
}
默认    11:25:59.531945+0800    WDBWebViewDemo    跳过控件:AlertTest2

通过CLICK pos[51,201,149,249] 的坐标来看,操作的就是黑名单控件。

2、下面试下坐标的方式,去掉包含在黑名单控件坐标内的控件和中心点在黑名单控件中的控件,一样的结果,还是会操作到pos[51,201,149,249]:

    if (leftX >= 50 && topY >= 200 && rightX <= 150 && bottomY <= 250) {
        NSLog(@"跳过控件通过坐标:%@", viewProp[@"rect"]);
        return nil;
    } else if (middleX >= 50 && middleY >= 200 && middleX <= 150 && bottomY <= 250) {
        NSLog(@"跳过控件通过坐标中心点:%@", viewProp[@"rect"]);
        return nil;
    }
2021-11-22 14:27:04.839280+0800 FastbotRunner-Runner[1866:405969] state g0s0 action SCROLL_TOP_DOWN pos[51,201,149,249] throttle 0.30
2021-11-22 14:27:05.178035+0800 FastbotRunner-Runner[1866:406492] get page desc from spy failed! :
[fastbot] : select new action from unvisited Unsaturated
[fastbot] : total visit count is 7
[fastbot] : state visited: 4
[fastbot] : action first visited, get reward 1.000000
[fastbot] : got reward: 16.6354
[fastbot] : build state cost: 0.000s action cost: 0.000s total cost 0.000s
默认  14:27:02.402576+0800    WDBWebViewDemo  receive request path = /view -- http://127.0.0.1:9797/, /view, application/json
默认  14:27:02.406054+0800    WDBWebViewDemo  request body data {
}
默认  14:27:02.406338+0800    WDBWebViewDemo  跳过控件通过坐标:{
    height = 50;
    left = 50;
    top = 200;
    width = 100;
}
ianisme commented 2 years ago

老哥 这个问题你解决了吗?遇到了同样的问题,感觉这个stub模式不管用