Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy
No Result Found

Test using passcode-protected devices

This feature is available only under Device Cloud Pro, Device Cloud Pro + Visual Cloud, and Enterprise Pro plans. For more details check out our pricing page.

For certain use cases, you might need to perform tests on devices that are passcode-protected. Some apps that deal with sensitive data, such as banking apps, require devices to be protected with a passcode as a layer of security.

Since BrowserStack remote devices are not passcode-protected as a default, App Automate provides the capability to use in the test script for getting access to passcode-protected devices.

In this guide, you’ll learn:

Supported OS versions

Currently, this feature is supported on the following OS versions:

  • Android: version 8.0 and above
  • iOS: version 13.0 and above

Set the capability

Use the passcode capability to enable the passcode protection in your test scripts:

If you are using BrowserStack SDK, you can set the following capability within the browserstack.yml file:

Capability Description Values
enablePasscode Use passcode-protected devices to run tests. true, false
Default: false
browserstack.yml
Copy icon Copy

BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.

Use the following code snippet to specify minor versions:

Capability Description Values
enablePasscode Use passcode-protected devices to run tests. true, false
Default: false

Example:

DesiredCapabilities capabilities = new DesiredCapabilities();
HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
browserstackOptions.put("enablePasscode", "true");
var capabilities = {
    'bstack:options' : {
        "enablePasscode" : "true",
    },
}
desired_cap = {
	'bstack:options' : {
		"enablePasscode" : "true",
	},
}
capabilities = {
    'bstack:options' => {
        "enablePasscode" => "true",
    },
}
AppiumOptions capabilities = new AppiumOptions();
Dictionary<string, object> browserstackOptions = new Dictionary<string, object>();
browserstackOptions.Add("enablePasscode", "true");
Capability Description Values
browserstack.enablePasscode Use passcode-protected devices to run tests. true, false
Default: false

Example:

DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability("browserstack.enablePasscode", "true");
var capabilities = {
    "browserstack.enablePasscode" : "true"
}
desired_cap = {
	"browserstack.enablePasscode" : "true"
}
desired_caps = {
    "browserstack.enablePasscode" => "true"
}
DesiredCapabilities capability = new DesiredCapabilities();
desiredCapabilities.SetCapability("browserstack.enablePasscode", "true");

Sample code to unlock device

To unlock a device during testing, if required, use the information in the following tabs.

Use the following Appium command to unlock a device during test execution.

The supporting capabilities for the unlock appium command, namely unlockType and unlockKey, are passed automatically to your tests by BrowserStack.

// your test script goes here
driver.pressKey(new KeyEvent(AndroidKey.DIGIT_1));
driver.pressKey(new KeyEvent(AndroidKey.DIGIT_2));
driver.pressKey(new KeyEvent(AndroidKey.DIGIT_3));
driver.pressKey(new KeyEvent(AndroidKey.DIGIT_4));
driver.pressKey(new KeyEvent(AndroidKey.ENTER));

// your test script goes here
await driver.pressKeycode(8);
await driver.pressKeycode(9);
await driver.pressKeycode(10);
await driver.pressKeycode(11);
await driver.pressKeycode(66);
# your test script goes here
driver.press_keycode(8);
driver.press_keycode(9);
driver.press_keycode(10);
driver.press_keycode(11);
driver.press_keycode(66);
# your test script goes here
@driver.press_keycode 8
@driver.press_keycode 9
@driver.press_keycode 10
@driver.press_key 11
@driver.press_keycode 66
// your test script goes here
driver.PressKey(new KeyEvent(AndroidKey.Digit1));
driver.PressKey(new KeyEvent(AndroidKey.Digit2));
driver.PressKey(new KeyEvent(AndroidKey.Digit3));
driver.PressKey(new KeyEvent(AndroidKey.Digit4));
driver.PressKey(new KeyEvent(AndroidKey.Enter));

For Android devices, the unlock pin is 1234.

You can also write an automation code that taps and sets the device passcode to 1234 to unlock the device.

For iOS devices, the unlock pin is 123456.

In your test script, write an automation code that taps and sets the device passcode to 123456.

Need some help?

If you need any help with this feature, get in touch with us.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle