appium / WebDriverAgent

A WebDriver server for iOS and tvOS
Other
1.19k stars 371 forks source link

window/size sometimes returns an incorrect size #879

Closed Jayxiang closed 6 months ago

Jayxiang commented 6 months ago

Simulator iPhone 15 Pro,wda 8.2.1 1 test wda 2 When I click on WDA again and the simulator is in a black screen state, the size I get is 320x480. 3 When I put WDA in the background, the size I get is 393x852.

KazuCocoa commented 6 months ago

Could you share the full appium log as well? I guess it's just wda's project resource config related. I'm not sure if we could do something right now, though.

Jayxiang commented 6 months ago

I did not use Appium, I only ran this project and tested window/size with Postman. I discovered this issue, and after debugging, I found that this change #834 caused the problem. Previously, [FBApplication fb_applicationWithPID:appElement.processIdentifier] would call the private API + (instancetype)applicationWithPID:(pid_t)processID; Now it calls fb_applicationWithPID, which results in different behavior when WDA is in the foreground. When applicationWithPID is used, it returns nil, and then [self fb_systemApplication] is called to obtain the correct size. However, when fb_applicationWithPID is used, it returns an application instance, but the size returned by this instance is incorrect.

截屏2024-03-30 截屏2024-03-30
KazuCocoa commented 6 months ago

I confirmed. That PR "fixed" the active device selection.

Before the PR, com.apple.springboard was selected as an active app, as you mentioned when WDA was active (foreground). After the PR, when WDA was active, WDA was selected as an active app, not "sprintgoard". So, the change itself was expected to get foreground app properly.

If you'd like to get the entire window size, It would be safe to check with com.apple.springboard, which is a home screen app for iOS. http://localhost:8100/wda/activeAppInfo endpoint helps to check what app is currently handled as active an WDA.

KazuCocoa commented 6 months ago

Btw, for example, when you activate an app that does not have resources for high resolution, the get window size would return the app's hight/width. it could be similar to the WDA in your comment. The size info itself is correct as WDA app.

Jayxiang commented 6 months ago

I see, it seems like adding an interface similar to device/size could be useful.

KazuCocoa commented 6 months ago

Perhaps https://github.com/appium/WebDriverAgent/pull/881 is good for it. It returns screen scale info as well (https://appium.github.io/appium-xcuitest-driver/latest/reference/execute-methods/#mobile-devicescreeninfo) so adding the screen size info should be good to add.

KazuCocoa commented 6 months ago

/wda/screen endpoint will return the screen size of springboard as well since wda 8.4.0