Hi, Habr. Quite often, when covering various services with autotests (selenium or appium), we have to use accounts of other social networks. This may be necessary, for example, if we test the registration on our service through this social network, or authorization, sharing, likes, and so on.
And, of course, quite often social networks ban our test users, because they consider them not at all test, but “suspicious”. In this article I will tell you how to deal with Instagram bans and why
you have to do it.

The essence of the problem
So, let's understand in order. Let's start with the fact that we have a service that we need to cover with UI tests. And there is some functionality on it that depends on any social networks. For example, we have the opportunity to log in to the site through Instagram. How to cover this functionality with tests?
')
At first glance, everything is simple. We create a user on Instagram and write his email and password in the test (in a specially created place for this):
class InstagramUsers: EMAIL = "some_email@example.com" PASS = "secret"
Next, we write a test that finds the necessary icon and clicks on it.
Running the test in the browser, of course, we run a "clean" session. This means that we do not have any authorization on any of the sites (there are no corresponding cookies). The same applies to the native application: raising the emulator or launching the application "honestly", we should not be authorized on any service.
The test does the following. He opens the desired screen, finds the social network icon and clicks on it. The authorization process on Instagram begins. In the required window, we enter the email and password of our account (example for web):

Accordingly, the test is authorized and then there is a check of the interaction of our service with Instagram. We see the desired status of the test "success" and rejoice - everything is in order.
After that we add the test to the CI and begin to run it on a schedule. And after a few days or even hours, the test begins to fall. Open a screenshot with an error and see the following:

Instagram banned our user and the test stopped working ... At first glance, the only thing that can be done about it is to create a new Instagram account. But then the essence of test automation is lost. :)
There are two solutions to this problem.
First decision
We can save cookies from Instagram between test runs. And log in only when necessary. True, here I see a few problems.
First, if we have a lot of tests, sooner or later we will want to parallelize them, so that the testing process goes faster. In this case, it is necessary to solve the problem of parallel data access. When the
expire date of the authorization cookie ends, we need to somehow guarantee that two or more tests will not try to log in to Instagram at the same time from parallel streams.
Secondly, when approaching with “pre-installed” authorization, we will not check the full process of interaction with the social network from authorization there to, for example, authorization on our service. How can we ensure that the service works if our auto tests test only half of the cases?
Second solution
Actually, for the sake of what I sat down to write an article ... We can log in to Instagram via Facebook. It sounds weird, right? Now I will tell more.
For some reason, Instagram does not ban accounts, which are now logged in through Facebook instead of an authorization form. Honestly, I do not know why this is happening, I came across this feature from hopelessness, trying to resolve the issue with the ban of accounts. And decided to share with you.
So, the sequence of actions is as follows. We create a user on Facebook. Next, we create an Instagram user immediately linked to a Facebook user. In the tests we register only access to the Facebook user.
The test itself must be taught to login to Instagram via Facebook. There should be no difficulties.
Total
I do not like
workouts . The simpler the approach we use in testing, the more honest it is. Accordingly, the calmer you can sleep at night. But, unfortunately, sometimes you have to "get out".
Unlike Instagram, Facebook has the ability to honestly create test users who are not banned when using them in autotests. About this in detail described in this
article .
I really hope that one day all the major services will have a similar API. Even more, I hope that if the guys from Instagram see this material, they will not just fix this feature, but make an adequate way to get test accounts for automated testing.
I have everything, thank you for your attention.