Java Code Examples for android.support.test.InstrumentationRegistry#getArguments()

The following examples show how to use android.support.test.InstrumentationRegistry#getArguments() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UIAutomatorWD.java    From UIAutomatorWD with MIT License 6 votes vote down vote up
@Test
public void MacacaTestRunner() throws Exception {
    Bundle args = InstrumentationRegistry.getArguments();

    int port = 9001;
    if (args.containsKey("port")) {
        port = Integer.parseInt(args.getString("port"));
    }

    UIAutomatorWDServer server = UIAutomatorWDServer.getInstance(port);
    Utils.print("UIAutomatorWD->" + "http://localhost:" + server.getListeningPort() + "<-UIAutomatorWD");

    if (args.containsKey("permissionPattern")) {
        JSONArray permissionPatterns = JSON.parseArray(args.getString("permissionPattern"));
        skipPermission(permissionPatterns, 15);
    }

    while (true) {
        SystemClock.sleep(1000);
    }
}
 
Example 2
Source File: TestMain.java    From AppCrawler with Apache License 2.0 5 votes vote down vote up
public static void getArguments() {
    Bundle arguments = InstrumentationRegistry.getArguments();
    if (arguments.getString("target") != null) {
        Config.sTargetPackage = arguments.getString("target");
    }
    if (arguments.getString("max-steps") != null) {
        Config.sMaxSteps = Integer.valueOf(arguments.getString("max-steps"));
    }
    if (arguments.getString("max-depth") != null) {
        Config.sMaxDepth = Integer.valueOf(arguments.getString("max-depth"));
    }
    if (arguments.getString("max-runtime") != null) {
        Config.sMaxRuntime = Integer.valueOf(arguments.getString("max-runtime"));
    }
    if (arguments.getString("max-screenshot") != null) {
        Config.sMaxScreenshot = Integer.valueOf(arguments.getString("max-screenshot"));
    }
    if (arguments.getString("max-screensloop") != null) {
        Config.sMaxScreenLoop = Integer.valueOf(arguments.getString("max-screenloop"));
    }
    if (arguments.getString("launch-timeout") != null) {
        Config.sLaunchTimeout = Integer.valueOf((arguments.getString("launch-timeout")));
    }
    if (arguments.getString("waitidle-timeout") != null) {
        Config.sWaitIdleTimeout = Integer.valueOf((arguments.getString("waitidle-timeout")));
    }
    if (arguments.getString("capture-steps") != null) {
        Config.sCaptureSteps = (arguments.getString("capture-steps").compareTo("true") == 0);
    }
    if (arguments.getString("random-text") != null) {
        Config.sRandomText = (arguments.getString("random-text").compareTo("true") == 0);
    }
}
 
Example 3
Source File: AndroidLibraryModuleIntegrationTest.java    From android-testing-templates with Apache License 2.0 5 votes vote down vote up
/**
 * This test class showcases passing arguments from the command line to the instrumentation.
 * <p>
 * Every @Test will fail if the argument "argument1" has the value "make_test_fail". See README
 * for more information.
 *
 */
@Before
public void checkCustomArgument() {
    // Get the arguments bundle.
    Bundle arguments = InstrumentationRegistry.getArguments();

    // Get the value if "argument1" exists
    String argument1 = arguments.getString("argument1");

    // Do something with the value. In this example it will make the test fail but it can be
    // used to modify a value in SharedPreferences or set the hostname of a backend server,
    // for example.
    assertThat(argument1, not(equalTo("make_test_fail")));
}
 
Example 4
Source File: SpotifyServiceAndroidTest.java    From spotify-web-api-android with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    Bundle arguments = InstrumentationRegistry.getArguments();
    String accessToken = arguments.getString("access_token");
    if (accessToken == null) {
        Assert.fail("Access token can't be null");
    }

    SpotifyApi spotifyApi = new SpotifyApi();
    spotifyApi.setAccessToken(accessToken);
    mService = spotifyApi.getService();

    mAuthHeader = Headers.of("Authorization", "Bearer " + accessToken);
}
 
Example 5
Source File: ExampleInstrumentedTest.java    From za-Farmer with MIT License 3 votes vote down vote up
/**
 * 执行案例,入口
 */
@Test
public void execute() throws IOException, JSONException {


    Bundle args = InstrumentationRegistry.getArguments();

    final String caseFileKey = "executeFile";
    final String resultPathKey = "executeResult";
    final String autoPermitKey = "autoPermit";
    if (!args.containsKey(caseFileKey)) {
        args.putString(caseFileKey, InstrumentationRegistry.getTargetContext().getExternalCacheDir().getPath() + "/case.json");
    }
    if (!args.containsKey(resultPathKey)) {
        args.putString(resultPathKey, InstrumentationRegistry.getTargetContext().getExternalCacheDir().getPath());
    }
    if (!args.containsKey(autoPermitKey)) {
        args.putString(autoPermitKey, "true");

    }

    instrumentation.sendStatus(1, args);

    String executeFile = args.getString(caseFileKey);
    String executeResult = args.getString(resultPathKey);
    String autoPermit = args.getString(autoPermitKey);


    TestCase testCase = TestCaseFactory.getTestCase(new File(executeFile));


    //全局处理权限弹窗(开关控制)
    if (autoPermit.equals("true")) {

        GlobalEventListener.getInstance().usePermissionsWindowHandler(true);
    }

    testCase.runCase(executeResult);

}