Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump the recent fixes from FB WDA repository #134

Closed
wants to merge 32 commits into from
Closed

Conversation

mykola-mokhnach
Copy link

No description provided.

Marek Cirkos and others added 30 commits December 13, 2017 01:35
Summary: We have duplicated scrolling tests for regular tableViews and simple scrollviews. It was usefull to have them, but now testing scrolling on scrollviews covers both cases anyway and we will waste less time testing.

Reviewed By: antiarchit

Differential Revision: D6543548

fbshipit-source-id: 35e717c43208b8f138a706798d9aa8a9e34b302a
Summary:
Some alert integration tests are flaky on our CI. I suspect this happens due to failing `tap` command, which might be failing to tap on animated view. This know XCTest issue.
Fortunately we have `fb_tapWithError` that handels are common pitfalls.

Reviewed By: antiarchit

Differential Revision: D6543616

fbshipit-source-id: f12ea7da67058253deff53fa980ebf2e55a93899
Summary: Rather then depending on XCUITest information on orientation, we should test what is application perception

Reviewed By: antiarchit

Differential Revision: D6543511

fbshipit-source-id: 192e50d0202f96bd6119921c9353a72789b33ad4
Summary:
This test is super device/simulator specific, that was used to interate on visibility improvements.
Right now it does not bring much value anyway.

Reviewed By: antiarchit

Differential Revision: D6543627

fbshipit-source-id: ffbda3b0b5ecde6a632e88030e84fae5af614347
Summary: It is time to move on.

Reviewed By: antiarchit

Differential Revision: D6692223

fbshipit-source-id: 81913167551191b2f9e177ff1ead943f6fc25752
Summary:
`XCUICoordinate` seems to have a bug that will return half of offset in case coordinate referance point goes off screen. I suspect this has something to do with retina displays.
Instead of using Apple's implementation of `screenPoint` I implemented our own.

Reviewed By: antiarchit

Differential Revision: D6702218

fbshipit-source-id: b01ef061732281cdf8c6707de38a11b6e31b9c28
Summary:
With all visibility changes tested pageindicator is no longer considered invisible. For the time being this is ok with us.
This diff uses different invisible elements to run same test of search for invisible elements

Reviewed By: antiarchit

Differential Revision: D6702252

fbshipit-source-id: a2bd5198d14f05cb1b33afe76a6b5bda7e34a847
Summary: This test was not intended to run on iPad, so we should turn it off so that we can make Travis green again :).

Reviewed By: antiarchit

Differential Revision: D6726707

fbshipit-source-id: db92f23b2dc755e7c1464069c04b1838717b8ff4
Summary:
With new xcode it looks like, calling `query`, `resolve` on XCUIApplication will in some sense break it. Not sure exactly what goes wrong, but final result is that it's missing some children and description of that object is empty.
Instead we can use new API for fetching snapshots for debugging.

Reviewed By: lawrencelomax

Differential Revision: D6723102

fbshipit-source-id: a33d9caf03eef4450f3879996493493c2cb257b4
Summary:
Using views frame for calculating scroling vector might be buggy when application is doing tricky stuff with scolling views eg. nesting scrollview within scrollview.
In that case frame of the second scrollview will be huge and make scrolling imposible as we will try to use points of the screen. Instead we should visible frame.

Reviewed By: antiarchit

Differential Revision: D6819626

fbshipit-source-id: 27062f593485b4ec55ae8bd1a9c9a32a89630b92
Summary:
[XCUIDevice sharedDevice].orientation may get values like FaceUp, which cause wrong calculation of the app frame size, in landscape.

With devices in Lab, standing portrait, this problem is less common. Working on development with devices on the table it happens more often causing a great deal of confusion.

From my tests, using app interfaceOrientation gives always the reality of the App.
Closes facebookarchive#875

Reviewed By: marekcirkos

Differential Revision: D7067153

Pulled By: antiarchit

fbshipit-source-id: c6aa8f8823d0f43e5072a190c34df931d0d6b8b8
Summary:
It might be there is more than one `IntegrationApp` icon on the dashboard while integration tests are running on Travis. Addresses https://travis-ci.org/facebook/WebDriverAgent/jobs/349725814
Closes facebookarchive#883

Differential Revision: D7289614

Pulled By: marekcirkos

fbshipit-source-id: e5060888f2a752c039fcf815984e24579a3cef06
Reviewed By: antiarchit

Differential Revision: D7615943

fbshipit-source-id: 9cb82dce23c02970d0c29613c7de4ebca0838361
Summary:
Include RoutingHTTPServer in copy to fix ISSUE #902
Closes facebookarchive#915

Differential Revision: D7947944

Pulled By: marekcirkos

fbshipit-source-id: ca60238fc3f715f753f084493aec5afa4524b21b
Summary:
If SDK >= 11, the tap coordinate based on application is not correct when
  the application orientation is landscape and
  tapX > application portrait width or tapY > application portrait height.
  Pass the window element to the method [FBElementCommands gestureCoordinateWithCoordinate:element:] will resolve the problem.
  More details about the bug, please see the following issues: #705, #798, #856.
  Notice: On iOS 10, if the application is not launched by wda, no elements will be found. See issue #732.
Closes facebookarchive#878

Differential Revision: D7947931

Pulled By: marekcirkos

fbshipit-source-id: 4f8ef1484761b79c69f67df40293eea70bc08984
Differential Revision: D8220228

fbshipit-source-id: cf08317ab2e50282373576fedb7c2b26b47969ad
Summary:
In case testmanagerd has problems in calculating frames it may return 'inf' instead which does not behave well with JSON encoding.
Therfore checing for infs when formating JSON reponse

Reviewed By: antiarchit

Differential Revision: D7067158

fbshipit-source-id: 180400186af49f1353d93e9eb61d7306b8a1a0f6
Summary:
A couple of commands which make possible to force touch given element or point by coordinates. In fact – copy of the tap extension. Baked with integration tests.

Updated with mykola-mokhnach improvements in  #79
Closes facebookarchive#917

Differential Revision: D8220249

Pulled By: marekcirkos

fbshipit-source-id: 2a14ab5759894577a1f5e40f20b4a6d79e519419
Summary:
Every time a user finds an element using the `element` or `elements` route, a new `XCUIElement` object is added to the session cache. The elements are never removed from the cache.

A very naïve script which goes to the home screen and queries for the 'Phone' element 1000 times in a row, will cause memory consumption (as measured by Xcode) of the WebDriverAgent to grow to approximately 126 MB. Net, it appears that every `XCUIElement` object consumes about 100KB of memory.

For sessions which persist for a long period of time (say, 30 minutes or more), this can eventually lead to an out of memory situation in which the WebDriverAgent crashes.

This PR tries to provide an 'escape hatch' for applications which want long-running sessions, by allowing them to:
- query the amount of elements in the cache
- clear the element cache
by adding two custom routes.

We're looking at other approaches to keep the cache size under control as well - e.g. by checking the element cache for duplicates and adding an option to remove 'stale' elements (elements which no longer exist); we'll try to submit PRs for that as well.

As usual, let me know what you think & happy to discuss further.
Closes facebookarchive#896

Differential Revision: D8254682

Pulled By: marekcirkos

fbshipit-source-id: a200a570d9b4e71a6f2171419b39126dd9affca3
Summary:
In XCUIElementTypeTable,attribute values of many XCUIElementTypeCell
instances are null.When fb_scrollToVisibleWithNormalizedScrollDistance
function is called by XCUIElementTypeCell instance,it is unable to
accurately slide the specified UI element.
Closes facebookarchive#879

Differential Revision: D8255752

Pulled By: marekcirkos

fbshipit-source-id: 930f478417823ae0c0f79d1699d61af616f3c781
Summary:
Integrations tests under latest release Xcode are failing with `Unknown selector 'hitPoint'`. This is because Apple changed hitpoint interface a bit.
This diff bridges 'old' & 'new' interface under one methods.

By-product wins:
- fixed //EndToEndTests/WebDriverAgent:IntegrationTests2 - XCElementSnapshotHitPoint/testAccessibilityActivationPoint
- fixed //EndToEndTests/WebDriverAgent:IntegrationTests3 - XCUIElementFBFindTests_AttributesPage/testInvisibleDescendantWithXPathQuery

Reviewed By: antiarchit

Differential Revision: D8279751

fbshipit-source-id: b4ead8f459724bf7979a787ea6b1a851a1f35b59
Summary: We do not use flow annotations anymore so removing it for now.

Reviewed By: antiarchit

Differential Revision: D8297400

fbshipit-source-id: 791a121f879a5ae02220a4af9ff40f7c6f28076c
Summary: Make compiler happy

Reviewed By: antiarchit

Differential Revision: D8348679

fbshipit-source-id: 696b0e23f3b2df7cb153a359ebcb291ef58010f8
Summary:
D7947931 patches taping XY for rotated screens however it does not work in case window does not cover fullscreen.
In such case we need patch coordinates to take into account window's offset to correctly calculate final XY tap coordinates

Reviewed By: antiarchit

Differential Revision: D8820400

fbshipit-source-id: 3c526253d86b680a37fb55c25d237e4a9de459a2
Summary:
More and more classes are moved from public `XCTest` framework to private `XCTAutomationSupport` one.
It is not big of an issue, however in order to be able to compile WDA with new XCode we need to either:
- explicitly link both frameworks (this diff)
- or remove direct class allocations

Direct linking would remove requirement for future refactoring that might be necessary with potentially other moved classes so going for this approach.

Reviewed By: antiarchit

Differential Revision: D9081652

fbshipit-source-id: 94a8162eee491ced175a56f4381b2bba9ce31c16
…882)

Summary:
This should improve elements lookup flow if done by native clients by returning correct webdriver response codes for incorrect locator expressions.
Pull Request resolved: facebookarchive#882

Differential Revision: D9295734

Pulled By: marekcirkos

fbshipit-source-id: b9ffda5f51f5f5dc7a64e7383a866152000e5357
Summary:
It turns out, that `NSProcessInfo.processInfo.environment[@"USE_PORT"]` returns an empty string instead of nil if `USE_PORT` is not present in the environment which causes zero value to be assigned by default.
Pull Request resolved: facebookarchive#976

Differential Revision: D9294646

Pulled By: marekcirkos

fbshipit-source-id: 1501c754268f828ed922cfa978fb32ce0468cdad
…ive#979)

Summary:
Allows to forward NSKeyValueObserverRegistration methods.

Fixes issue facebookarchive#975 — Allows to work with Xcode 10 beta 5 and beta 6.

Tested for Xcode 9.4.1 as well
Pull Request resolved: facebookarchive#979

Differential Revision: D9399064

Pulled By: marekcirkos

fbshipit-source-id: f1976e0fdefdaaf2ed5c52eeeace6c99acb50ee8
Reviewed By: antiarchit

Differential Revision: D10525731

fbshipit-source-id: 25eb57d95d8ac556104c84ccc2642fbc36a4979b
Summary:
In case some object will start observing properties on `XCUIApplicationProcess`, which is proxied by `FBApplicationProcessProxy`.
All KVO's callbacks will pass unexpected observed object; XCUIApplicationProcess rather than `FBApplicationProcessProxy`.
So in case those objects make any checks based on that value, behaviour might be unexpected.

This solution creates separate observer proxies that will proxy KVO call with proper observed object value. IT also significantly simplifies "tracing" of all observer and their observered values.

Reviewed By: mkareta

Differential Revision: D13432956

fbshipit-source-id: 97c8e3d22facd1dcfa77e3bb6d433120ea0fde56
Marek Cirkos and others added 2 commits December 14, 2018 11:29
Summary:
We are changing `currentProcess` property in very sneaky way, and any pre-existing KVO observer on `XCUIApplicationImpl` will not get notified about it.
However they should get notified, otherwise KVO will complain about unnotified object change.

So this happens, because object it changeed, while already handling KVO notification.
A bit hacky way is to move this out-of KVO call stack, eg by async dispatch

Reviewed By: mkareta

Differential Revision: D13432958

fbshipit-source-id: 015dc0dd950003a1044a9f0a850f07ea17e1fa86
@jsf-clabot
Copy link

jsf-clabot commented Dec 21, 2018

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
3 out of 9 committers have signed the CLA.

✅ aabalaban
✅ qmfrederik
✅ fr0l
❌ marekcirkos
❌ Jon Gabilondo
❌ Mykola Mokhnach
❌ Anton Kushpil
❌ Liu Junqi
❌ 林名君


Jon Gabilondo, Mykola Mokhnach, Anton Kushpil, Liu Junqi, 林名君 seem not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.

@mykola-mokhnach
Copy link
Author

Unfortunately some tests are still crashing for this PR: https://travis-ci.org/appium/WebDriverAgent/jobs/470950738#L1888

@Dan-Maor
Copy link
Collaborator

Dan-Maor commented Dec 21, 2018

I'm pretty sure that it's because of the bug I've opened on Facebook's repository after @marekcirkos added the KVO forward mechanism to the FBApplicationProcessProxy class.

While it fixes the shouldWaitForQuiescence issue there is a problem with re-activating apps (initBundleWithPrivatePath fails if there's already an XCUIApplicationProcess for it).

facebookarchive#1044

Edit: Unfortunately it's also making createSession a bit slower (2.5 seconds before, 4.5 seconds after for opening the Settings app).

@mykola-mokhnach
Copy link
Author

@Dan-Maor Do you have any ideas on how to address it? I cannot merge these fixes in their current state, since it is going to break existing tests for application switching.

@mykola-mokhnach
Copy link
Author

Test Case '-[FBSessionIntegrationTests testMainAppCanBeRestartedInScopeOfTheCurrentSession]' started.
    t =     0.00s Start Test at 2018-12-21 14:25:09.134
2018-12-21 14:25:09.191012+0100 IntegrationTests_1-Runner[74917:1090225] [AXMediaCommon] Unable to look up screen scale
2018-12-21 14:25:09.196431+0100 IntegrationTests_1-Runner[74917:1090225] [AXMediaCommon] Unable to look up screen scale
2018-12-21 14:25:09.196961+0100 IntegrationTests_1-Runner[74917:1090225] [AXMediaCommon] Unexpected physical screen orientation
    t =     0.08s Set Up
    t =     0.12s     Open com.facebook.wda.integrationApp
    t =     0.17s         Launch com.facebook.wda.integrationApp
    t =     4.84s             Wait for com.facebook.wda.integrationApp to idle
    t =     6.39s     Find the "Alerts" Button
    t =     6.40s         Snapshot accessibility hierarchy for app with pid 75011
    t =     6.45s         Find: Descendants matching type Button
    t =     6.45s         Find: Elements matching predicate '"Alerts" IN identifiers'
2018-12-21 14:25:15.581566+0100 IntegrationTests_1-Runner[74917:1090225] Using singleton test manager
    t =     7.50s     Set device orientation to Portrait
    t =     9.09s Terminate com.facebook.wda.integrationApp:75011
    t =    10.18s Open com.facebook.wda.integrationApp
    t =    10.22s     Launch com.facebook.wda.integrationApp
2018-12-21 14:25:19.439879+0100 IntegrationTests_1-Runner[74917:1090225] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot remove an observer <_XCKVOExpectationImplementation 0x6000030d7890> for the key path "currentProcess.applicationState" from <XCUIApplicationImpl 0x6000030da990>, most likely because the value for the key "currentProcess" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the XCUIApplicationImpl class.'
*** First throw call stack:
(
	0   CoreFoundation                      0x000000010a6a929b __exceptionPreprocess + 331
	1   libobjc.A.dylib                     0x0000000109c45735 objc_exception_throw + 48
	2   CoreFoundation                      0x000000010a6a90f5 +[NSException raise:format:] + 197
	3   Foundation                          0x0000000109689a32 -[NSKeyValueNestedProperty object:didRemoveObservance:recurse:] + 659
	4   Foundation                          0x0000000109688c04 -[NSKeyValueUnnestedProperty object:didRemoveObservance:recurse:] + 231
	5   Foundation                          0x00000001096833fb -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 255
	6   Foundation                          0x000000010968396b -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 84
	7   Foundation                          0x000000010968388e -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] + 177
	8   XCTest                              0x000000010951f985 __42-[_XCKVOExpectationImplementation cleanup]_block_invoke + 98
	9   libdispatch.dylib                   0x000000010f1e9587 _dispatch_client_callout + 8
	10  libdispatch.dylib                   0x000000010f1f5f87 _dispatch_lane_barrier_sync_invoke_and_complete + 94
	11  XCTest                              0x000000010951f91d -[_XCKVOExpectationImplementation cleanup] + 76
	12  XCTest                              0x000000010951eda3 -[XCTKVOExpectation cleanup] + 48
	13  XCTest                              0x0000000109503b38 -[XCTWaiter _queue_setExpectations:] + 619
	14  libdispatch.dylib                   0x000000010f1e9587 _dispatch_client_callout + 8
	15  libdispatch.dylib                   0x000000010f1f5f87 _dispatch_lane_barrier_sync_invoke_and_complete + 94
	16  XCTest                              0x0000000109502676 -[XCTWaiter waitForExpectations:timeout:enforceOrder:] + 1222
	17  XCTest                              0x000000010950585e +[XCTWaiter waitForExpectations:timeout:enforceOrder:] + 104
	18  XCTest                              0x0000000109526d9f -[XCUIApplicationImpl _waitOnActivationExpectation:] + 138
	19  XCTest                              0x0000000109525525 __42-[XCUIApplicationImpl _launchWithRequest:]_block_invoke + 799
	20  XCTest                              0x0000000109518367 -[XCTContext _runActivityNamed:type:block:] + 245
	21  XCTest                              0x00000001094b932c -[XCTestCase startActivityWithTitle:type:block:] + 218
	22  XCTest                              0x00000001094b9509 -[XCTestCase startActivityWithTitle:block:] + 60
	23  XCTest                              0x00000001095251d0 -[XCUIApplicationImpl _launchWithRequest:] + 216
	24  XCTest                              0x0000000109518367 -[XCTContext _runActivityNamed:type:block:] + 245
	25  XCTest                              0x00000001094b932c -[XCTestCase startActivityWithTitle:type:block:] + 218
	26  XCTest                              0x00000001094b9509 -[XCTestCase startActivityWithTitle:block:] + 60
	27  XCTest                              0x0000000109524d3f -[XCUIApplicationImpl serviceOpenRequest:] + 247
	28  XCTest                              0x00000001094e9d78 -[XCUIApplication _launchUsingXcode:] + 301
	29  WebDriverAgentLib                   0x00000001262abcd3 -[FBApplication launch] + 243
	30  WebDriverAgentLib                   0x0000000126290dcf -[FBSession launchApplicationWithBundleId:shouldWaitForQuiescence:arguments:environment:] + 623
	31  IntegrationTests_1                  0x00000001262103d5 -[FBSessionIntegrationTests testMainAppCanBeRestartedInScopeOfTheCurrentSession] + 2549
	32  CoreFoundation                      0x000000010a6b011c __invoking___ + 140
	33  CoreFoundation                      0x000000010a6ad5b5 -[NSInvocation invoke] + 325
	34  XCTest                              0x00000001094b0b6e __24-[XCTestCase invokeTest]_block_invoke.192 + 78
	35  XCTest                              0x00000001095082e8 -[XCTestCase(Failures) performFailableBlock:testCaseRun:shouldInterruptTest:] + 57
	36  XCTest                              0x0000000109508205 -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 96
	37  XCTest                              0x00000001094b082f __24-[XCTestCase invokeTest]_block_invoke + 848
	38  XCTest                              0x000000010950e1ee -[XCUITestContext performInScope:] + 248
	39  XCTest                              0x00000001094b0424 -[XCTestCase testContextPerformInScope:] + 98
	40  XCTest                              0x00000001094b04d2 -[XCTestCase invokeTest] + 137
	41  XCTest                              0x00000001094b200d __26-[XCTestCase performTest:]_block_invoke_2 + 43
	42  XCTest                              0x00000001095082e8 -[XCTestCase(Failures) performFailableBlock:testCaseRun:shouldInterruptTest:] + 57
	43  XCTest                              0x0000000109508205 -[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 96
	44  XCTest                              0x00000001094b1f24 __26-[XCTestCase performTest:]_block_invoke.326 + 88
	45  XCTest                              0x0000000109518a3b +[XCTContext runInContextForTestCase:block:] + 225
	46  XCTest                              0x00000001094b1653 -[XCTestCase performTest:] + 675
	47  XCTest                              0x00000001094f4802 -[XCTest runTest] + 57
	48  XCTest                              0x00000001094ac85b __27-[XCTestSuite performTest:]_block_invoke + 365
	49  XCTest                              0x00000001094ac033 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 55
	50  XCTest                              0x00000001094ac2f6 -[XCTestSuite performTest:] + 296
	51  XCTest                              0x00000001094f4802 -[XCTest runTest] + 57
	52  XCTest                              0x00000001094ac85b __27-[XCTestSuite performTest:]_block_invoke + 365
	53  XCTest                              0x00000001094ac033 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 55
	54  XCTest                              0x00000001094ac2f6 -[XCTestSuite performTest:] + 296
	55  XCTest                              0x00000001094f4802 -[XCTest runTest] + 57
	56  XCTest                              0x00000001094ac85b __27-[XCTestSuite performTest:]_block_invoke + 365
	57  XCTest                              0x00000001094ac033 -[XCTestSuite _performProtectedSectionForTest:testSection:] + 55
	58  XCTest                              0x00000001094ac2f6 -[XCTestSuite performTest:] + 296
	59  XCTest                              0x00000001094f4802 -[XCTest runTest] + 57
	60  XCTest                              0x0000000109522ea6 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 171
	61  XCTest                              0x0000000109522fc7 __44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.80 + 68
	62  XCTest                              0x00000001094c486a -[XCTestObservationCenter _observeTestExecutionForBlock:] + 594
	63  XCTest                              0x0000000109522c1a -[XCTTestRunSession runTestsAndReturnError:] + 623
	64  XCTest                              0x000000010949125a -[XCTestDriver runTestsAndReturnError:] + 422
	65  XCTest                              0x0000000109514fbd _XCTestMain + 1478
	66  IntegrationTests_1-Runner           0x000000010916002d -[_XCTRunnerAppDelegate applicationWillResignActive:] + 0
	67  IntegrationTests_1-Runner           0x000000010915ff2b _XCTRunnerRunTests + 0
	68  CoreFoundation                      0x000000010a60ca3c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
	69  CoreFoundation                      0x000000010a60c1f0 __CFRunLoopDoBlocks + 336
	70  CoreFoundation                      0x000000010a606a64 __CFRunLoopRun + 1284
	71  CoreFoundation                      0x000000010a606221 CFRunLoopRunSpecific + 625
	72  GraphicsServices                    0x0000000112d4b1dd GSEventRunModal + 62
	73  UIKitCore                           0x000000010ba7e115 UIApplicationMain + 140
	74  IntegrationTests_1-Runner           0x00000001091601f5 main + 183
	75  libdyld.dylib                       0x000000010f259551 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

@Dan-Maor
Copy link
Collaborator

The KVO changes are really good, but I don't think they can be safely merged at this point.

I started looking into it this week but I'm afraid I don't have any solid directions yet. Looks like something with the KVO forwarding isn't clicking nicely:

  • From what I gather, it looks like replacing the XCUIApplicationProcess inside dispatch_async causes initial KVO observers to "go around" the new mechanism (verified by adding logs to the proxied addObserver and removeObserver calls). However, when trying to create a new session when the target app already has a session the proxy mechanism is being used, and causes an exception.
  • Removing the dispatch_async from FBApplication causes observers to register through the KVO proxy, however the one of "applicationState" breaks the process when there's an attempt to remove it for some reason.

Perhaps we should revert the KVO PRs until we figure it out.

Unfortunately my Mac is at work so I won't be able to dig into it until next week.

P.S. I had an idea for fixing shouldWaitForQuiescence but @marekcirkos's solution is more generic and I like it more, we just need to figure out what's the missing link here.

@mykola-mokhnach
Copy link
Author

Thanks for your investigation @Dan-Maor. I see the topic is quite complicated and I possibly cannot help much with that. What I can only say, that the problem that we have is not present for FB WDA, since they don't have application switching implemented. Perhaps, the current way it is done in our fork is not very optimal and needs to be improved.

Please keep us updated and, again, big thanks to you and @marekcirkos for taking care about such problems.

@Dan-Maor
Copy link
Collaborator

I made some progress on identifying the issue.

From what I understand, it appears that while we replace XCUIApplicationProcess in the context of XCUIApplicationImpl, XCUIApplicationMonitor still has references to the old XCUIApplicationProcess objects inside internal structures (_launchedApplications, _applicationProcessesForPID and _applicationImplDepot) which link between the XCUIApplicationImpl and its equivalent XCUIApplicationProcess. It can be accessed using "[XCUIApplicationMonitor sharedMonitor]".

Violently purging the sharedMonitor and its depot using KVC allows creating another session with a previously launched application, however I'd rather find a more gentle way of modifying the internal dictionaries and change the references to our newly created FBApplicationProcessProxy, if that's possible (pretty sure it is). I'm not certain about other effects of the violent approach.

Might take me a while to continue with it since I'm working on other urgent tasks at the moment (I've analyzed it while waiting for a rare exception on another issue I'm working on), so if the changes are urgent I suggest to perhaps merge all but the last two commits since these are the ones in need of attention.

@mykola-mokhnach
Copy link
Author

@Dan-Maor We could easily wait, there is no rush. We'd rather merge a correct fix, which does not fail any tests.

@marekcirkos
Copy link

@Dan-Maor I think the problem is that dispatch_async is executed in next runloop run, but check probably takes place in the same call stack later (however proxy is already nested). We can either delay nesting proxy, but then we will miss some calls to it, or take completely different approach and replace proxy and modify XCUIApplicationProcess methods at runtime.
I really wanted to avoid that, but it might be our next best move.

@mykola-mokhnach
Copy link
Author

@Dan-Maor Do you by any chance have time to work on this fix. BTW, have you seen
facebookarchive#1076? It looks like everything will stop working again soon.

@Dan-Maor
Copy link
Collaborator

Not anytime soon I’m afraid, I’m extremely overloaded at the moment.

About Xcode 10.2 - from what I can tell the sharedClient has been removed in favor of a property of XCUIDevice (accessibilityClient), hopefully just using it instead will give the same behavior. This is also the case for the sharedMonitor from XCUIApplicationMonitor, by the way.

@mykola-mokhnach
Copy link
Author

Thanks for the hint @Dan-Maor
I'll try to provide a fix for that

@Dan-Maor
Copy link
Collaborator

After looking into it a bit more I tend to agree with @marekcirkos - I could't find a way for still using the FBApplicationProcessProxy with the KVO changes while maintaining the ability to re-activate applications. Looks like we'll have to resort to overriding some methods on runtime (I'm working on it).

By the way - there's an issue currently in master where setting waitForQuiescence to false doesn't make a difference with Xcode 9.4 and above due to not registering for an observer in FBApplication if applicationProcessTracker exists (it has been added in 9.4, not 10.2).

@coinhu1995
Copy link

coinhu1995 commented Dec 5, 2019

@Dan-Maor still facing this issue. The environment:

Xcode 11.2.1
iOS 12.1.2

2019-12-05 12:46:36.332030+0700 WebDriverAgentRunner-Runner[1530:118687] Starting screenshots broadcast to 127.0.0.1:63335

2019-12-05 12:46:36.386360+0700 WebDriverAgentRunner-Runner[1530:119043] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot remove an observer <NSKeyValueObservance 0x282401da0> for the key path "currentProcess.applicationState" from <XCUIApplicationImpl 0x2809af6b0>, most likely because the value for the key "currentProcess" has changed without an appropriate KVO notification being sent. Check the KVO-compliance of the XCUIApplicationImpl class.'

*** First throw call stack:
(0x1c8fa1ea4 0x1c8171a50 0x1c8ea8484 0x1c9996410 0x1c996f1c4 0x1c996ef78 0x1c996edf8 0x1c999627c 0x1c996f1c4 0x1c996ef78 0x1c996edf8 0x1c996eb38 0x1013927ec 0x1c89da484 0x1c89875c8 0x10139276c 0x101391c0c 0x101372c6c 0x1c89da484 0x1c89875c8 0x1013717d4 0x101374804 0x101330208 0x101358c28 0x101358548 0x1012fdd04 0x1024b7fc8 0x1024b25e4 0x1024ada78 0x1024b2044 0x1024b1944 0x10247c3c4 0x10247c088 0x10247bae0 0x1c89da484 0x1c897d82c 0x1c898db9c 0x1c8981a9c 0x1c8982718 0x1c898aeb8 0x1c8bbd0dc 0x1c8bbfcec)

libc++abi.dylib: terminating with uncaught exception of type NSException

@Dan-Maor
Copy link
Collaborator

Dan-Maor commented Dec 5, 2019

Are you setting shouldWaitForQuiescence to false?
If not - that's a different issue.
Also - does it happen at a certain point or randomly?

@coinhu1995
Copy link

coinhu1995 commented Dec 5, 2019

@Dan-Maor

Are you setting shouldWaitForQuiescence to false?

Yes, it is "NO" from WDA.
static BOOL FBShouldWaitForQuiescence = NO;

Also - does it happen at a certain point or randomly?

it is randomly

@Dan-Maor
Copy link
Collaborator

Dan-Maor commented Dec 5, 2019

Are you setting it explicitly to false? appium-xcuitest-driver sends it as 'true' by default unless the capability is manually set to false.
let shouldWaitForQuiescence = util.hasValue(this.opts.waitForQuiescence) ? this.opts.waitForQuiescence : true;

@coinhu1995
Copy link

coinhu1995 commented Dec 5, 2019

@Dan-Maor
I just run WDA from xcodebuild command (Not run with appium).

Also i changed
requirements = FBParseCapabilities((NSDictionary *)request.arguments[@"capabilities"] [FBConfiguration setShouldWaitForQuiescence:[requirements[@"shouldWaitForQuiescence"] boolValue]];
to
[FBConfiguration setShouldWaitForQuiescence:NO];

in FBSessionCommand.m but it did not work

@Dan-Maor
Copy link
Collaborator

Dan-Maor commented Dec 5, 2019

  • If you want to disable the mechanism you should set the value to YES, like it is being received from Appium by default.
  • I've noticed that you're mirroring the screen, does it happen when the screen is not being mirrored?
  • Please completely reset the project, and try to reproduce the issue.
  • If the issue still happens - try to create a session with shouldWaitForQuiescence capability set to true and check whether the issue still happens.

If the issue doesn't happen when the capability is set to true, please open an issue in the main Appium repo with all of the details.

  • Complete scenario, including which app is in the front when the issue happens.
  • A gist with a full syslog of the session of the occurrence.
  • Nice to have - since you're running it manually, please run it with Xcode directly and attach a screenshot of the stacktrace.

@coinhu1995
Copy link

coinhu1995 commented Dec 5, 2019

I ran it with Xcode and set shouldWaitForQuiescence to TRUE and also FALSE. After WDA start successfully (ServerURLHere->http://172.27.168.30:8100<-ServerURLHere). I open localhost:9100, the error occurred.
I am running Xocde 11.2.1 and using XCTAutomationSupport.framework, XCTest.framework from Xcode 10.1. Does it affect to this issue ?

@Dan-Maor
Copy link
Collaborator

Dan-Maor commented Dec 5, 2019

If setting shouldWaitForQuiescence to true doesn't make a difference then it's not the same issue as before.

Opening localhost:9100 is what triggers the video stream to start, so it may be related, however mix and matching like that is never a good idea and may well be the cause of the issue.

We can't really help with this sort of setup since it is not intended to run this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants