summaryrefslogtreecommitdiff
path: root/app/src/androidTestCustom/java/se/leap/bitmaskclient/base/CustomProviderTest.java
blob: 92416af46442d2e32bebd564abd8f4370b178226 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package se.leap.bitmaskclient.base;

import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.RootMatchers.isDialog;
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
import static utils.CustomInteractions.tryResolve;

import android.net.VpnService;

import androidx.test.espresso.ViewInteraction;
import androidx.test.uiautomator.UiObject;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.UiSelector;

import org.junit.Test;

import se.leap.bitmaskclient.R;
import tools.fastlane.screengrab.Screengrab;

public class CustomProviderTest extends ProviderBaseTest {

    @Test
    @Override
    public void test01_vpnStartTest() throws InterruptedException, UiObjectNotFoundException {
        // handle VPN permission dialog
        if (VpnService.prepare(getApplicationContext()) != null) {
            UiObject okButton = device.findObject(new UiSelector().packageName("com.android.vpndialogs").resourceId("android:id/button1"));
            okButton.waitForExists(30000);
            okButton.click();
        }

        ViewInteraction mainButtonStop;
        mainButtonStop = tryResolve(
                onView(withId(R.id.main_button)),
                matches(isDisplayed()),
                30);
        Screengrab.screenshot("VPN_connected");

        mainButtonStop.perform(click());
        Screengrab.screenshot("VPN_ask_disconnect");

        ViewInteraction alertDialogOKbutton = tryResolve(onView(withText(android.R.string.yes))
                .inRoot(isDialog()),
                matches(isDisplayed()));
        alertDialogOKbutton.perform(click());
        Screengrab.screenshot("VPN_disconnected");

        mainButtonStop.perform(click());
        Thread.sleep(50);
        Screengrab.screenshot("VPN_connecting");
    }

    @Override
    public boolean configureProviderIfNeeded() {
        return false;
    }
}