Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reduce motion #760

Merged
merged 15 commits into from
Oct 1, 2018
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ Differences noted here
|`realDeviceScreenshotter`|Name of the alternative screenshot system to use for real devices. Defaults to the XCUITest screenshot functionality through WebDriverAgent. Possible value is `idevicescreenshot` to use the screenshot program from libimobiledevice.|e.g., `idevicescreenshot`|
|`mjpegServerPort`|The port number on which WDA broadcasts screenshots stream encoded into MJPEG format from the device under test. It might be necessary to change this value if the default port is busy because of other tests running in parallel. Default value: `9100`|e.g. `12000`|
|`waitForQuiescence`| It allows to turn on/off waiting for application quiescence in WebDriverAgent, while performing queries. The default value is `true`. You can avoid [this kind of issues](https://github.com/appium/appium/issues/11132) if you turn it off. |e.g `false`|
|`reduceMotion`| It allows to turn on/off reduce motion accestibility preference. Setting reduceMotion `on` helps to reduce flakyness during tests. Only fon simulators | e.g `true` |

## Development<a id="development"></a>

Expand Down
3 changes: 3 additions & 0 deletions lib/desired-caps.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ let desiredCapConstraints = _.defaults({
},
mjpegServerPort: {
isNumber: true,
},
reduceMotion: {
isBoolean: true
}
}, iosDesiredCapConstraints);

Expand Down
5 changes: 5 additions & 0 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ class XCUITestDriver extends BaseDriver {
await shutdownOtherSimulators(this.opts.device);
}

// set reduceMotion if capability is set
if (util.hasValue(this.opts.reduceMotion)) {
this.opts.device.setReduceMotion(this.opts.reduceMotion);
}

this.localConfig = await iosSettings.setLocaleAndPreferences(this.opts.device, this.opts, this.isSafari(), async (sim) => {
await shutdownSimulator(sim);
// we don't know if there needs to be changes a priori, so change first.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"appium-base-driver": "^3.0.0",
"appium-ios-driver": "^2.4.3",
"appium-ios-simulator": "^3.0.0",
"appium-ios-simulator": "^3.3.0",
"appium-remote-debugger": "^3.16.0",
"appium-support": "^2.13.0",
"appium-xcode": "^3.2.0",
Expand Down
6 changes: 5 additions & 1 deletion test/functional/desired.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ const UICATALOG_SIM_CAPS = _.defaults({
}, GENERIC_CAPS);
delete UICATALOG_SIM_CAPS.noReset; // do not want to have no reset on the tests that use this

const SETTINGS_CAPS = _.defaults({
bundleId: "com.apple.Preferences"
}, GENERIC_CAPS);

const SAFARI_CAPS = _.defaults({
browserName: 'Safari',
testobject_api_key: process.env.SAUCE_RDC_WEB_ACCESS_KEY,
Expand All @@ -98,5 +102,5 @@ const W3C_CAPS = {

export {
UICATALOG_CAPS, UICATALOG_SIM_CAPS, SAFARI_CAPS, TESTAPP_CAPS,
PLATFORM_VERSION, TOUCHIDAPP_CAPS, DEVICE_NAME, W3C_CAPS
PLATFORM_VERSION, TOUCHIDAPP_CAPS, DEVICE_NAME, W3C_CAPS, SETTINGS_CAPS
};
75 changes: 75 additions & 0 deletions test/functional/driver/motion-e2e-specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { getSimulator } from 'appium-ios-simulator';
import { shutdownSimulator } from '../helpers/simulator';
import { createDevice, deleteDevice } from 'node-simctl';
import { retryInterval } from 'asyncbox';
import { MOCHA_TIMEOUT, initSession, deleteSession } from '../helpers/session';
import { SETTINGS_CAPS } from '../desired';

const SIM_DEVICE_NAME = 'xcuitestDriverMotionTest';
const PREDICATE_SEARCH = '-ios predicate string';

const should = chai.should(); // eslint-disable-line no-unused-vars
chai.use(chaiAsPromised);

const deleteDeviceWithRetry = async function (udid) {
try {
await retryInterval(10, 1000, deleteDevice, udid);
} catch (ign) {}
};

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

let baseCaps;
let caps;

let driver;
before(async function () {
const udid = await createDevice(SIM_DEVICE_NAME,
SETTINGS_CAPS.deviceName, SETTINGS_CAPS.platformVersion);
baseCaps = Object.assign({}, SETTINGS_CAPS, {udid});
caps = Object.assign({usePrebuiltWDA: true, reduceMotion: true}, baseCaps);
});

after(async function () {
const sim = await getSimulator(caps.udid);
await shutdownSimulator(sim);
await deleteDeviceWithRetry(caps.udid);
});

afterEach(async function () {
// try to get rid of the driver, so if a test fails the rest of the
// tests aren't compromised
await deleteSession();
const sim = await getSimulator(caps.udid);
await shutdownSimulator(sim);
});

if (!process.env.REAL_DEVICE) {
it('should enable reduce motion', async function () {
driver = await initSession(caps);
let el = await driver.element(PREDICATE_SEARCH, "type == 'XCUIElementTypeCell' AND name == 'General'");
await el.click();
el = await driver.element(PREDICATE_SEARCH, "type == 'XCUIElementTypeCell' AND name == 'Accessibility'");
await el.click();
el = await driver.element(PREDICATE_SEARCH, "type == 'XCUIElementTypeCell' AND name == 'Reduce Motion'");
await el.click();
el = await driver.element(PREDICATE_SEARCH, "type == 'XCUIElementTypeSwitch' AND name == 'Reduce Motion'");
(await el.getAttribute('value')).should.eql('1');
});
it('should disable reduce motion', async function () {
caps.reduceMotion = false;
driver = await initSession(caps);
let el = await driver.element(PREDICATE_SEARCH, "type == 'XCUIElementTypeCell' AND name == 'General'");
await el.click();
el = await driver.element(PREDICATE_SEARCH, "type == 'XCUIElementTypeCell' AND name == 'Accessibility'");
await el.click();
el = await driver.element(PREDICATE_SEARCH, "type == 'XCUIElementTypeCell' AND name == 'Reduce Motion'");
await el.click();
el = await driver.element(PREDICATE_SEARCH, "type == 'XCUIElementTypeSwitch' AND name == 'Reduce Motion'");
(await el.getAttribute('value')).should.eql('1');
});
}
});