summaryrefslogtreecommitdiff
path: root/app/src/androidTest/legacy/BaseTestDashboardFragment.java
blob: 4730cecc2d88daf3945c06d9e83cf411b5b22b3b (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package se.leap.bitmaskclient.test;

import android.content.Context;
import android.graphics.Rect;
import android.test.ActivityInstrumentationTestCase2;
import android.view.View;

import com.robotium.solo.Solo;

import se.leap.bitmaskclient.ProviderListActivity;
import se.leap.bitmaskclient.R;

public abstract class BaseTestDashboardFragment extends ActivityInstrumentationTestCase2<Dashboard> {

    Solo solo;
    Context context;
    UserStatusTestController user_status_controller;
    VpnTestController vpn_controller;

    public BaseTestDashboardFragment() { super(Dashboard.class); }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        context = getInstrumentation().getContext();
        solo = new Solo(getInstrumentation(), getActivity());
        Screenshot.initialize(solo);
        user_status_controller = new UserStatusTestController(solo);
        vpn_controller = new VpnTestController(solo);
        ConnectionManager.setMobileDataEnabled(true, context);
        solo.unlockScreen();
        if (solo.searchText(solo.getString(R.string.configuration_wizard_title))) {
            toDashboardAnonymously("demo.bitmask.net");
        }
    }

    void changeProviderAndLogIn(String provider) {
        tapSwitchProvider();
        solo.clickOnText(provider);
        useRegistered();
    }

    void tapSwitchProvider() {
        solo.clickOnMenuItem(solo.getString(R.string.switch_provider_menu_option));
        solo.waitForActivity(ProviderListActivity.class);
    }

    private void useRegistered() {
        solo.waitForFragmentById(R.id.provider_detail_fragment);
        String text = solo.getString(R.string.signup_or_login_button);
        clickAndWaitForDashboard(text);
        user_status_controller.logIn("parmegvtest10", "holahola2");
    }

    private void clickAndWaitForDashboard(String click_text) {
        solo.clickOnButton(click_text);
        assertTrue(solo.waitForActivity(Dashboard.class, 80 * 1000));
    }

    static boolean isShownWithinConfinesOfVisibleScreen(View view) {
        Rect scrollBounds = new Rect();
        view.getHitRect(scrollBounds);
        return view.getLocalVisibleRect(scrollBounds);
    }


    private void toDashboardAnonymously(String provider) {
        selectProvider(provider);
        useAnonymously();
    }

    private void useAnonymously() {
        String text = solo.getString(R.string.use_anonymously_button);
        clickAndWaitForDashboard(text);
    }


    private void selectProvider(String provider) {
        solo.clickOnText(provider);
        Screenshot.setTimeToSleep(1);
        Screenshot.take("Configuring provider");
        waitForProviderDetails();
    }

    private void waitForProviderDetails() {
        String text = solo.getString(R.string.provider_details_title);
        assertTrue("Provider details dialog did not appear", solo.waitForText(text, 1, 60*1000));
        Screenshot.take("Provider details");
    }



}