facebook-wda
facebook-wda copied to clipboard
横屏tap点击出现了一些问题
环境
机型:iPhone 7 系统版本:11.2.1 显示宽度:375 显示高度:667 (横屏相反)
问题描述
在横屏状态下LANDSCAPE_RIGHT
,LANDSCAPE
,当i
值出现大于等于750时,就会出现点击错位的问题
代码如下
import wda
client = wda.Client()
session = client.session()
session.orientation = wda.LANDSCAPE
def tap(x, y):
session.tap_hold(x / 2, y / 2, 0.1)
def main():
for v in range(100, 500, 100):
for i in range(100, 1300, 100):
tap(v, i)
# 当`i`值出现大于等于750时,就会出现点击错位的问题
if __name__ == "__main__":
main()
错误截图
我尝试在备忘录中重现Bug状态,请参考以下截图
LANDSCAPE模式下的点击截图
LANDSCAPE_RIGHT模式下的点击截图
我也遇到了 iPhone 7 10.0.1
去 https://github.com/facebook/WebDriverAgent 这个地方提issue,这个我也解决不了。记得提问用英文
@codeskyblue 临时的话 把坐标除2就行了
def tap(self, x, y):
if(orientation!="PORTRAIT"):
x/=2.0
y/=2.0
return self.http.post('/wda/tap/0', dict(x=x, y=y))
@codeskyblue 嗯,已经提交issue了,谢谢。 https://github.com/facebook/WebDriverAgent/issues/836
@Arrow-Li 抱歉,我不太明白你除以2的作用,这样并不能解决点击位置超过屏幕中心线时导致出现偏移的问题。
你是不是弄错坐标了 横屏下tap的第一个参数是长,第二个是宽,iPhone7的屏幕宽度就是750 超过这个值自然会错位。
def test():
#weight, height = 1334,750
# 中心点 667,375
for i in range(667, 1334, 50):
for j in range(375, 750, 50):
s.tap(x / 2.0, y / 2.0)
import wda
client = wda.Client()
session = client.session()
print("设备尺寸", session.window_size())
# 这将会打印出 '设备尺寸 Size(width=667, height=375)'
def tap(x, y):
session.tap(x / 2.0, y / 2.0)
def main():
for i in range(667, 1334, 50):
for j in range(375, 750, 50):
tap(i, j)
main()
@Arrow-Li 我和你并不一样。 你的设备是什么?系统版本是什么?
iPhone7 10.0.1
On Wed, 10 Jan 2018 at 14:15 大王饶命 [email protected] wrote:
import wda client = wda.Client() session = client.session() print("设备尺寸", session.window_size())# 这将会打印出 '设备尺寸 Size(width=667, height=375)' def tap(x, y): session.tap(x / 2.0, y / 2.0)
def main(): for i in range(667, 1334, 50): for j in range(375, 750, 50): tap(i, j)
main()
[image: img_6691] https://user-images.githubusercontent.com/7522275/34758051-34d79c3a-f610-11e7-8b9c-4424752dff16.jpg
@Arrow-Li https://github.com/arrow-li 我和你并不一样。 你的设备是什么?系统版本是什么?
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/openatx/facebook-wda/issues/42#issuecomment-356510186, or mute the thread https://github.com/notifications/unsubscribe-auth/ARIXlh40EwclVZRFw56MYbyM-l4WJH1Mks5tJFWRgaJpZM4RVRKp .
很不巧,我 11.0.1 SE,也是遇到了同样的问题,难道是 11 苹果又换了定位的方式???
有个临时的解决办法,需要修改WebDriverAgent的代码。
找到WebDriverAgent/WebDriverAgentLib/Commands/FBElementCommands.m文件。
定位到 + (id<FBResponsePayload>)handleTap:(FBRouteRequest *)request 方法。
修改如下:
+ (id<FBResponsePayload>)handleTap:(FBRouteRequest *)request
{
FBElementCache *elementCache = request.session.elementCache;
CGPoint tapPoint = CGPointMake((CGFloat)[request.arguments[@"x"] doubleValue], (CGFloat)[request.arguments[@"y"] doubleValue]);
XCUIElement *element = [elementCache elementForUUID:request.parameters[@"uuid"]];
if (nil == element) {
// >> 修改代码开始
NSArray<XCUIElement *> *allElements = request.session.application.windows.allElementsBoundByIndex;
XCUIElement *window = nil;
for (XCUIElement *e in allElements) {
if (e.elementType == XCUIElementTypeWindow) {
window = e;
break;
}
}
XCUIElement *e = window ?: request.session.application;
XCUICoordinate *tapCoordinate = [self.class gestureCoordinateWithCoordinate:tapPoint application:(id)e shouldApplyOrientationWorkaround:isSDKVersionLessThan(@"11.0")];
// << 修改代码结束
[tapCoordinate tap];
} else {
NSError *error;
if (![element fb_tapCoordinate:tapPoint error:&error]) {
return FBResponseWithError(error);
}
}
return FBResponseWithOK();
}
在方法 + (XCUICoordinate *)gestureCoordinateWithCoordinate:(CGPoint)coordinate application:(XCUIApplication *)application shouldApplyOrientationWorkaround:(BOOL)shouldApplyOrientationWorkaround 中,原本传入application参数的值是FBApplication对象,现在改为XCUIElementType为Window的XCUIElement。
在iPhone 7的iOS 11.1.1上测试成功。 在iPhone 5S的iOS 10.3.3上测试 失败 。