Skip to content

Commit

Permalink
feat: add reduceTransparency (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
rerorero committed Dec 13, 2022
1 parent eeb2914 commit 82e7c23
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 79 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ If a test is executed on a Simulator then UI locale is changed as well. You can
|`appium:keepKeyChains`|Set the capability to `true` in order to preserve Simulator keychains folder after full reset. This feature has no effect on real devices. Defaults to `false`|e.g. `true`|
|`appium:keychainsExcludePatterns`|This capability accepts comma-separated path patterns, which are going to be excluded from keychains restore while full reset is being performed on Simulator. It might be useful if you want to exclude only particular keychain types from being restored, like the applications keychain. This feature has no effect on real devices.|e.g. `*keychain*.db*` to exclude applications keychain from being restored|
|`appium:reduceMotion`| It allows to turn on/off reduce motion accessibility preference. Setting reduceMotion `on` helps to reduce flakiness during tests. Only on simulators | e.g `true` |
|`appium:reduceTransparency`| It allows you to turn on/off reduce transparency accessibility preference. Setting reduceTransparency `on` helps to reduce screenshot image distortion during tests. Only on simulators | e.g `true` |
|`appium:permissions`| Allows to set permissions for the specified application bundle on Simulator only. The capability value is expected to be a valid JSON string with `{"<bundleId1>": {"<serviceName1>": "<serviceStatus1>", ...}, ...}` format. Since Xcode SDK 11.4 Apple provides native APIs to interact with application settings. Check the output of `xcrun simctl privacy booted` command to get the list of available permission names. Use `yes`, `no` and `unset` as values in order to `grant`, `revoke` or `reset` the corresponding permission. Below Xcode SDK 11.4 it is required that `applesimutils` package is installed and available in PATH. The list of available service names and statuses can be found at https://github.com/wix/AppleSimulatorUtils. | e. g. `{"com.apple.mobilecal": {"calendar": "YES"}}` |
|`appium:iosSimulatorLogsPredicate`|Set the `--predicate` flag in the ios simulator logs|e.g.: `'process != "locationd" AND process != "DTServiceHub"' AND process != "mobileassetd"`|
|`appium:simulatorPasteboardAutomaticSync`| Handle the `-PasteboardAutomaticSync` flag when simulator process launches. It could improve launching simulator performance not to sync pasteboard with the system when this value is `off`. `on` forces the flag enabled. `system` does not provide the flag to the launching command. `on`, `off`, or `system` is available. They are case insensitive. Defaults to `off` | e.g. `system` |
Expand Down
3 changes: 3 additions & 0 deletions lib/desired-caps.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ const desiredCapConstraints = {
reduceMotion: {
isBoolean: true
},
reduceTransparency: {
isBoolean: true
},
mjpegScreenshotUrl: {
isString: true
},
Expand Down
5 changes: 5 additions & 0 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,11 @@ class XCUITestDriver extends BaseDriver {
await this.setReduceMotion(this.opts.reduceMotion);
}

if (_.isBoolean(this.opts.reduceTransparency) && this.isSimulator()) {
this.log.info(`Setting reduceTransparency to ${this.opts.reduceTransparency}`);
await this.opts.device.setReduceTransparency(this.opts.reduceTransparency);
}

if (this.opts.orientation) {
await this.setInitialOrientation(this.opts.orientation);
this.logEvent('orientationSet');
Expand Down
92 changes: 92 additions & 0 deletions test/functional/device/accessibility-e2e-specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { PREDICATE_SEARCH } from '../helpers/element';
import { MOCHA_TIMEOUT, initSession, deleteSession } from '../helpers/session';
import { SETTINGS_CAPS, amendCapabilities } from '../desired';

chai.should();
chai.use(chaiAsPromised);

describe('Accessibility', function() {
this.timeout(MOCHA_TIMEOUT);

let driver, caps;

beforeEach(function() {
caps = amendCapabilities(SETTINGS_CAPS, { 'appium:usePrebuiltWDA': true });
});

afterEach(async function() {
await driver.terminateApp('com.apple.Preferences');

// try to get rid of the driver, so if a test fails the rest of the
// tests aren't compromised
await deleteSession();
});

async function showAccessibilityTab(driver) {
let hasGeneralTab = false;
try {
// iOS 13 has Accessibility outside the General tab
await driver
.$(`${PREDICATE_SEARCH}:type == 'XCUIElementTypeCell' AND name == 'Accessibility'`)
.click();
} catch (err) {
await driver
.$(`${PREDICATE_SEARCH}:type == 'XCUIElementTypeCell' AND name == 'General'`)
.click();
await driver
.$(`${PREDICATE_SEARCH}:type == 'XCUIElementTypeCell' AND name == 'Accessibility'`)
.click();
hasGeneralTab = true;
}
return hasGeneralTab;
}

describe('ReduceMotion', function() {
async function getReduceMotion(driver) {
const hasGeneralTab = await showAccessibilityTab(driver);
const motionCellName = hasGeneralTab ? 'Reduce Motion' : 'Motion';
await driver
.$(`${PREDICATE_SEARCH}:type == 'XCUIElementTypeCell' AND name == '${motionCellName}'`)
.click();
return await driver
.$(`${PREDICATE_SEARCH}:type == 'XCUIElementTypeSwitch' AND name == 'Reduce Motion'`)
.getAttribute('value');
}

it('should enable reduce motion', async function() {
caps = amendCapabilities(caps, { 'appium:reduceMotion': true });
driver = await initSession(caps);
await getReduceMotion(driver).should.eventually.be.eql('1');
});
it('should disable reduce motion', async function() {
caps = amendCapabilities(caps, { 'appium:reduceMotion': false });
driver = await initSession(caps);
await getReduceMotion(driver).should.eventually.be.eql('0');
});
});

describe('ReduceTransparency', function() {
async function getReduceTransparency(driver) {
await showAccessibilityTab(driver);
await driver
.$(`${PREDICATE_SEARCH}:type == 'XCUIElementTypeCell' AND name == '${'Display & Text Size'}'`)
.click();
return await driver
.$(`${PREDICATE_SEARCH}:type == 'XCUIElementTypeSwitch' AND name == 'Reduce Transparency'`)
.getAttribute('value');
}

it('should enable reduce transparency', async function() {
caps = amendCapabilities(caps, { 'appium:reduceTransparency': true });
driver = await initSession(caps);
await getReduceTransparency(driver).should.eventually.be.eql('1');
});
it('should disable reduce transparency', async function() {
caps = amendCapabilities(caps, { 'appium:reduceTransparency': false });
driver = await initSession(caps);
await getReduceTransparency(driver).should.eventually.be.eql('0');
});
});
});
63 changes: 0 additions & 63 deletions test/functional/device/motion-e2e-specs.js

This file was deleted.

56 changes: 40 additions & 16 deletions test/unit/driver-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,31 @@ describe('driver commands', function () {
describe('createSession', function () {
let driver;
let sandbox;
let device;
let realDevice;

beforeEach(function () {
driver = new XCUITestDriver();
sandbox = sinon.createSandbox();
sandbox.stub(driver, 'determineDevice').callsFake(async function () { // eslint-disable-line require-await
device = {
shutdown: _.noop,
isRunning() {
return true;
},
stat() {
return { state: 'Booted' };
},
clearCaches: _.noop,
getWebInspectorSocket() {
return '/path/to/uds.socket';
},
setReduceTransparency: _.noop,
};
realDevice = null;
sandbox.stub(driver, 'determineDevice').callsFake(async function() { // eslint-disable-line require-await
return {
device: {
shutdown: _.noop,
isRunning () {
return true;
},
stat () {
return {state: 'Booted'};
},
clearCaches: _.noop,
getWebInspectorSocket () {
return '/path/to/uds.socket';
},
},
udid: null,
realDevice: null
device,
realDevice,
};
});
sandbox.stub(driver, 'configureApp').callsFake(_.noop);
Expand Down Expand Up @@ -155,6 +159,26 @@ describe('driver commands', function () {
resCaps[1].javascriptEnabled.should.be.true;
driver.startLogCapture.called.should.be.false;
});
it('should call setReduceTransparency for a simulator', async function() {
this.timeout(MOCHA_LONG_TIMEOUT);
realDevice = false;
const spy = sinon.stub(device, 'setReduceTransparency');
await driver.createSession(null, null, _.merge({}, caps, {
alwaysMatch: { 'appium:reduceTransparency': true }
}));
spy.calledOnce.should.be.true;
spy.firstCall.args[0].should.eql(true);
});

it('should not call setReduceTransparency for a real device', async function() {
this.timeout(MOCHA_LONG_TIMEOUT);
realDevice = true;
const spy = sinon.stub(device, 'setReduceTransparency');
await driver.createSession(null, null, _.merge({}, caps, {
alwaysMatch: { 'appium:reduceTransparency': true }
}));
spy.notCalled.should.be.true;
});
});
});

Expand Down

0 comments on commit 82e7c23

Please sign in to comment.