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

How does one go about testing an offline scenario? #1501

Closed
JanithaR opened this issue Jul 3, 2019 · 8 comments
Closed

How does one go about testing an offline scenario? #1501

JanithaR opened this issue Jul 3, 2019 · 8 comments

Comments

@JanithaR
Copy link

JanithaR commented Jul 3, 2019

I did my fair bit of Googling and others but couldn't exactly find a reliable suggestion other than
"You have to do it manually" for this but I feel like this is a very common use case and one that must be taken into account when automating e2e tests.

A typical scenario would be, there's a button which would toggle its enabled state based on the device having an active internet connection or not.

@support
Copy link

support bot commented Jul 3, 2019

We use the issue tracker exclusively for bug reports and feature requests. This issue appears to be a general usage or support question. Instead, please ask a question on Stack Overflow with the detox tag.
Feel free to post your Stack Overflow question here for more visility. We'll take a look at it.
For more information on bots in this reporsitory, read this discussion.

@support support bot closed this as completed Jul 3, 2019
@noomorph
Copy link
Collaborator

noomorph commented Jul 3, 2019

@JanithaR, it is a bit tricky for iOS, AFAIC. So I don't see ways it can be done in a straightforward fashion with a uniform API.

While for Android, the way to do is rather quick: https://stackoverflow.com/questions/10506591/turning-airplane-mode-on-via-adb

But for iOS, the responses are less optimistic: https://stackoverflow.com/questions/4808433/is-it-possible-to-disable-the-network-in-ios-simulator

w6ehv

@JanithaR
Copy link
Author

JanithaR commented Jul 3, 2019

Oh no, not the tinfoil solution! I cracked up when I saw that. xD

The app I'm working on is an offline-first app. So there are so many things that I must ensure that behaves as per specifications when the device is offline. And that takes way too much of my time per release.

I'm at the moment thinking of introducing a toggle button in the UI of all root level components which is linked to the same boolean I use to keep track of the actual state of the connection in the 'dev' builds so that I could then use Detox to toggle that.

@idlework
Copy link

idlework commented Jul 3, 2019

We are also looking for a way to test this. And it's weird that the bot closed this issue. I see this ticket as a feature request because detox doesn't contain this functionality yet.

@LeoNatan
Copy link
Contributor

LeoNatan commented Jul 3, 2019

Guys, please take these discussions to Stack Overflow so they are much more visible. There is a reason why there is a bit closing these issues.

@LeoNatan
Copy link
Contributor

LeoNatan commented Jul 3, 2019

As for a feature request, I’m not sure there is anything to do on iOS. The network stack is shared with the underlying Mac network stack. So I fear a feature request will help in this case. PRs are welcome 🙂

@JanithaR
Copy link
Author

JanithaR commented Jul 4, 2019

Guys, please take these discussions to Stack Overflow so they are much more visible. There is a reason why there is a bit closing these issues.

I beg to differ. StackOverflow is helpful for sure but my last couple of questions has gone unanswered for so long, experimenting on things by myself proved to be way quicker. I bet taken 10 people from here vs StackOverflow, chances are that more people here would be interested in this because they have, is or will run into this.

With that aside, I wasn't exactly asking for a feature request but was hoping that this issue would lead up to a discussion that would end up in a new page being added to the documentation about what strategies one could utilize to test these scenarios. Because this was certainly one of the first things I looked for when I wanted to use Detox and I'm sure thousands of us who have used Detox have come up with clever alternatives.

The scenarios I want to test are mainly 2 types. UI updates and application behaviour on failed API requests. I know it's not doable on iOS simulator and on doable on Android emulators through the command line. But what if we could unify the behaviour for both platforms through,

  • Like I mentioned before, trick the UI into being in offline mode by toggling a switch. The device isn't offline at all but just for the sake of testing the UI we're tricking it. That would take care of one set of tests.
  • As for the other, you guys use fbsimctl to do stuff, so why not expose an API to a proxy which can be controlled via command line

I don't know how practical these are but I have a gut feeling that these two approaches, which may not be ideal, would at least help us cover some percentage of the offline tests.

@LeoNatan
Copy link
Contributor

LeoNatan commented Jul 4, 2019

Fbsimctl is not used anymore. And it can’t provide you with what you want. If you really want offline mode, pull the cable out of your Mac.

The solution here is simple. Use mocking. It’s well documented, and you can notify your code that it’s offline when it’s really not. This is something you can implement right now and no features are needed for it in Detox.

Also allow me to say that your comment is out of line. The reason we blocked help questions here is because it clutters our tracker. This is the main reason we push to Stack Overflow. We just don’t have the man power to support people. The bot explained this when closing the issue, yet you continued. Had you asked in Stack Overflow and posted your question here, you would have gotten an answer from @noomorph and/or me there.

Further discussion of our Stack Overflow policy are to be had on the bots issue that is linked in the bot comment.

@wix wix locked and limited conversation to collaborators Jul 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants