Detox does not complete test which runs a network request - detox

I have a button where it calls an API, even though the API is completed the test button click does not complete.
[APP_STATUS] The app is busy with the following tasks: • The event
"Network Request" is taking place with object: "URL:
“https://clientstream.launchdarkly.com/meval/eyJjdXN0b20iOnsiaW5zdGFsbGF0aW9uSWQiOiIxMTlhYmY2NC03ZTU3LTQ3MmMtYjRmYS04Nzk5N2QzOWVhNWMiLCJhZ2VudElkIjoiNzZlYjhmMTgtNWVmNi00MzI5LTk3YmUtNzg4YWM0ODUzYjgxIiwiZGV2aWNlIjoiaVBob25lMTIsMSIsIm9zIjoiMTUuMCJ9LCJhbm9ueW1vdXMiOmZhbHNlLCJrZXkiOiIxMTlhYmY2NC03ZTU3LTQ3MmMtYjRmYS04Nzk5N2QzOWVhNWMifQ==”".
• Run loop "Main Run Loop" is awake. • The event "Network Request" is
taking place with object: "URL:
“https://companionmobilebackenddev.azurewebsites.net/api/v2/custommedia”".
• There are 1 work items pending on the dispatch queue: "Main Queue
(<OS_dispatch_queue_main: com.apple.main-thread>)". • 1 enqueued
JavaScript timers:
Timer #1:
JS timer ID: 775.
Duration: 0.001.
Is recurring: NO.

Related

Testing countdown timer with cypress

I have a web app that in one part of it a timer needs to count 1 minute. Now for doing the end to end testing I am using Cypress, In Cypress documentation I found cy.clock and cy.tick. The documentaion is vague to me. So which of these should I use for testing a countdown timer?
Cypress cy.clock() has a "freeze frame" effect on timers in your app.
The passing of time can be controlled with cy.tick() to move the time frame on.
It makes your test run much quicker than waiting for a timeout to actually happen.
cy.clock(); // take control of timers
cy.get('#timer-btn').click();
cy.tick(30000); // move time frame +30 seconds
cy.get('.btn').should('be.enabled') // button still available
cy.tick(60100); // move time frame +60.1 seconds
cy.get('#timer').should('have.text', 'TIME IS UP, your score is: 0');
cy.get('.btn').should('be.disabled') // button is not available
This only works if the timer is using the setInterval function.

How can I react to a message with a pub/sub bot

I have created a Card with a button and a onClick action that successfully sends a message to my client with type "CARD_CLICKED".
When I try to respond to this message with either a type "NEW_MESSAGE" or "UPDATE_MESSAGE" message, this is displayed as a new message, while the API tries for three times to send that CARD_CLICKED event to my bot until it gives up with the visual error: "Unable to contact [bot]. Try again later."
I guess this is similar to
Interactive button doesn't work properly when using pub/sub
Interactive cards hangout chat Api
but I am using a golang client and the answer to these questions didn't help me...
My code to respond to the "CARD_CLICKED" message:
func handleClick(message *chat.DeprecatedEvent) *chat.Message {
log.Debugf("User %s instructed me to execute %s", message.User.DisplayName, message.Action.ActionMethodName)
response := &chat.Message{
ActionResponse: &chat.ActionResponse{Type: "UPDATE_MESSAGE"},
Thread: &chat.Thread{Name: message.Message.Thread.Name},
Space: &chat.Space{Name: message.Message.Space.Name, Type: message.Message.Space.Type},
Text: "CARD CLICKED!",
}
return response
}
My code is based on this project: https://github.com/jforman/hangbot
Found out what the main issue was... I was calling the .Create() function - which created a new message and thus - even though the Action Response was set correctly - this was not interpreted as a response to the click event:
https://github.com/jforman/hangbot/blob/master/hangbot.go#L79
After I switched to calling .Update() - Chat would not display the "Unable to contact" message about my bot any more.
What remains is that the click event is still sent to me three times, but I'm filtering events now based on the eventTime, which works ok for now.

Main Thread Checker: UI API called on a background thread iOS 11 Xcode 9 GM Seed

Can anyone please help me in debugging this issue, from the time i started working with Xcode 9 GM seed with iOS 11 GM seed, my code throwing me a warning in the console saying:
2017-09-18 16:22:52.872716+0530 **** *****[359:20158] [reports] Main Thread Checker: UI API called on a background thread: -[UIApplication
applicationState] .PID: 359, TID: 20158,
Thread name: Runtime Network Callback Thread,
Queue name: com.apple.root.default-qos.overcommit, QoS: 21
Backtrace:
also, i'm using ESRI maps in my application, when ever i zoom in or zoom out in ESRI maps i'm getting this error:
2017-09-18 16:22:53.176524+0530 *** ***[359:20063] Task <5F9376DB-9335-
4A45-B3F0-1D6FD69A19A3>.<29> finished with error - code: -999
2017-09-18 16:22:53.178923+0530 *** ***[359:20142] Task <0DE282EA-3FBD-
4036-8298-C75EFA65F15A>.<40> HTTP load failed (error code: -999 [1:89])
2017-09-18 16:22:53.179821+0530 *** *[359:20063] Task <BE2D8BAE-FFB8-
43CA-8723-111326DEF4FD>.<31> finished with error - code: -999
2017-09-18 16:22:53.180089+0530 *** ***[359:20063] Task <E7C819D4-C11A-
4915-B021-A73F31BE89CD>.<33> finished with error - code: -999
2017-09-18 16:22:53.180365+0530 *** ***[359:20063] Task <3B871761-B006-
4220-B857-6204B385AD34>.<34> finished with error - code: -999
2017-09-18 16:22:53.180523+0530 *** ***[359:20142] Failed to get
TCPIOConnection in addInputHandler.
Application works fine with Xcode 8 iOS 10.3.3. Problem seems to be with Xcode 9. Can anyone please help me in debugging this issue. Thanks
Xcode 9 adds a new runtime checks which is the Main Thread Checker.
According to Apple documentation:
The Main Thread Checker is a standalone tool for Swift and C languages
that detects invalid usage of AppKit, UIKit, and other APIs on a
background thread. Updating UI on a thread other than the main thread
is a common mistake that can result in missed UI updates, visual
defects, data corruptions, and crashes.
You already had this issue in your app with Xcode 8. It's just that the tool to detect it was not there yet.
In your case, it seems that it's a call to UIApplication.shared.applicationState that is causing this runtime issue.
You can configure your app scheme to stop execution when it happens. It is a checkbox in the Diagnostics tab, under the Main Thread Checker section.

UI Automation Error: UI TESTING FAILURE-APP failed to quiesce within 30.0s

Since xCode updated i'm having trouble running any ui test case. It gives me this error when its expected to do a simple tapping action for example:
XCUIApplication *app = [[XCUIApplication alloc] init];
XCUIElement *passwordSecureTextField = app.secureTextFields[#"Password"];
[passwordSecureTextField tap];
Anyone have any ideas why am i getting this error? I've searched on google and here but haven't found any solutions.
Thank you.
Make sure you don't have any animations on screen during UI Automation tests. We had a text alert flashing on the login screen for debug/test builds of our app, and it would cause the "failed to quiesce" error until it was removed.
There are some other posts about this error that mention issues with UIRefreshControl, so I would suspect animating that or UIActivityIndicatorView would cause the same problem.
It might help to turn on the "All Exceptions" breakpoint. I used it and I recall getting the same error. It will break at the line with the problematic code and should show you the stack trace of the error with more info.
I had a similar error - as well as the simulator running very slowly. In my case it was fixed very simply by the method given in the accepted answer here: Xcode simulator extremely slow.
To save you a click: The issue was that I had accidentally pressed Cmd + T at some point, enabling "Slow animations".
I had to turn off the "Personal Hotspot" in order to get a working test environment (Because the blue bar in the top apparently disturbed XCTestRunner)
But as some tests need internet connection I can't do testing when being in the wild:-(
Anthony F's answer says it all. Likely something is still animating. The system seems to wait for the app UI to "settle" (go idle) and when that happens, it performs the tap action. However, when the UI constantly runs animations, it will never settle.
Xcode Console Output
Enable the console output in Xcode to see what happens when running the test.
Below is an example of the log, when it works well. The system waits for the app to go idle and when that has happened, it goes to find the button in the hierarchy.
t = 16.95s Tap "#go" Button
t = 16.95s Wait for app to idle
t = 17.00s Find the "#go" Button
t = 17.00s Snapshot accessibility hierarchy for XXX
t = 17.09s Find: Descendants matching type Button
t = 17.09s Find: Elements matching predicate '"#go" IN identifiers'
t = 17.10s Wait for app to idle
t = 17.15s Synthesize event
t = 17.41s Wait for app to idle
Below is an example when it fails. The system waits for the app to settle so that it can look for the button in the hierarchy. Since, it does not settle, it waits "forever" finally running into the timeout.
t = 18.88s Set device orientation to Unknown
t = 18.93s Tap "#go" Button
t = 18.93s Wait for app to idle
t = 79.00s Assertion Failure: UI Testing Failure - App failed to quiesce within 60s
In my case the "failed to quiesce" was caused, because at time t=18.90s, demo data was generated which caused repeated updates of a UIProgressView. From then on the app UI never settled ("quiesced").
("quiesce" as a word is not in my active vocabulary, which certainly has delayed my recognition of what was going on. The console output pushed me into the right direction. I'd bet "idle" rings more bells than "quiesce" for many developers.)

NSRunLoop only to run untill all the events are finished

There are method in NSRunLoop and CFRunLoop, To run to particular time
CFRunLoopInMode and NSRunLoop - runUntillDateT
These methods specify a time to run until.
But, I wanted process all the messages in the runLoop and exit if it is done and idle.
Because some of the runLoop sources can have indefinite time to process. So, I cannot mention the time.
You can use CFRunLoopRunInMode to run the event loop for one pass, and it tells you whether it handled any sources. So you can try something like this:
while (CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, 1) == kCFRunLoopRunHandledSource) {
// nothing
}
Another approach you could try is to create a CFRunLoopObserver with an activities argument of kCFRunLoopBeforeWaiting. This observer will be called just before the run loop goes to sleep waiting for a source or timer to fire. In the observer's callout, you can simply call CFRunLoopStop(CFRunLoopGetCurrent()).