Dark Mode testing with Appium
Dark mode is a setting, available on both Android and iOS, which toggles the interface appearance of the phone to use either the standard light mode setting or a dark mode.
When dark mode is enabled, the phone will switch to a dark background with lighter foreground colors, which enables better viewing in low-light conditions.
Changing Dark Mode
This example will use mobile: setAppearance
to set the appearance to dark (dark mode).
const wd = require('wd');
const assert = require('assert');
const asserters = wd.asserters;
const testingbotKey = "api_key",
testingbotSecret = "api_secret";
const desiredCaps = {
'name': 'My First App Test',
'deviceName' : 'Galaxy S8',
'platformName': 'Android',
'version': '9.0',
'app' : 'https://testingbot.com/appium/sample.apk',
'realDevice': true
};
const driver = wd.promiseRemote("http://" + testingbotKey + ":" + testingbotSecret + "@hub.testingbot.com/wd/hub");
driver
.init(desiredCaps)
.then(function () {
return driver.execute('mobile: setAppearance', [{ 'style': 'dark' }]);
})
.then(function () {
return driver.waitForElementByAccessibilityId('inputA', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (inputA) {
return inputA.sendKeys("10");
})
.then(function () {
return driver.waitForElementByAccessibilityId('inputB', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (inputB) {
return inputB.sendKeys("5");
})
.then(function () {
return driver.waitForElementByAccessibilityId('sum', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (textOutput) {
return textOutput.text().then(function(value) {
if (value === "15")
assert(true);
else
assert(false);
});
})
.fin(function() { return driver.quit(); })
.done();
Make sure to always stop your test (.done()), otherwise it will continue running, leading to a timeout.
const wd = require('wd');
const assert = require('assert');
const asserters = wd.asserters;
const testingbotKey = "api_key",
testingbotSecret = "api_secret";
const desiredCaps = {
'name': 'My First App Test',
'deviceName' : 'iPhone XR',
'platformName': 'iOS',
'version': '16.0',
'app' : 'https://testingbot.com/appium/sample.ipa',
'realDevice': true
};
const driver = wd.promiseRemote("http://" + testingbotKey + ":" + testingbotSecret + "@hub.testingbot.com/wd/hub");
driver
.init(desiredCaps)
.then(function () {
return driver.execute('mobile: setAppearance', [{ 'style': 'dark' }]);
})
.then(function () {
return driver.waitForElementByAccessibilityId('inputA', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (inputA) {
return inputA.sendKeys("10");
})
.then(function () {
return driver.waitForElementByAccessibilityId('inputB', asserters.isDisplayed && asserters.isEnabled, 30000);
})
.then(function (inputB) {
return inputB.sendKeys("5");
})
.fin(function() { return driver.quit(); })
.done();
Make sure to always stop your test (
.done()
), otherwise it will continue running, leading to a timeout.