diff --git a/detox/src/devices/IosDriver.js b/detox/src/devices/IosDriver.js index 0aafba869d..a16652c1d3 100644 --- a/detox/src/devices/IosDriver.js +++ b/detox/src/devices/IosDriver.js @@ -3,10 +3,10 @@ const fs = require('fs'); const DeviceDriverBase = require('./DeviceDriverBase'); const InvocationManager = require('../invoke').InvocationManager; const invoke = require('../invoke'); -const GREYConfiguration = require('./../ios/earlgreyapi/GREYConfiguration'); +const GREYConfigurationApi = require('./../ios/earlgreyapi/GREYConfiguration'); +const GREYConfigurationDetox = require('./../ios/earlgreyapi/GREYConfigurationDetox'); class IosDriver extends DeviceDriverBase { - constructor(client) { super(client); @@ -25,15 +25,29 @@ class IosDriver extends DeviceDriverBase { } async setURLBlacklist(urlList) { - await this.client.execute(GREYConfiguration.setURLBlacklist(urlList)); + await this.client.execute( + GREYConfigurationApi.setValueForConfigKey( + GREYConfigurationApi.sharedInstance(), + urlList, + "GREYConfigKeyURLBlacklistRegex" + ) + ); } async enableSynchronization() { - await this.client.execute(GREYConfiguration.enableSynchronization()); + await this.client.execute( + GREYConfigurationDetox.enableSynchronization( + GREYConfigurationApi.sharedInstance() + ) + ); } async disableSynchronization() { - await this.client.execute(GREYConfiguration.disableSynchronization()); + await this.client.execute( + GREYConfigurationDetox.disableSynchronization( + GREYConfigurationApi.sharedInstance() + ) + ); } async shake(deviceId) { @@ -44,10 +58,10 @@ class IosDriver extends DeviceDriverBase { // keys are possible orientations const orientationMapping = { landscape: 3, // top at left side landscape - portrait: 1 // non-reversed portrait + portrait: 1 // non-reversed portrait }; if (!Object.keys(orientationMapping).includes(orientation)) { - throw new Error(`setOrientation failed: provided orientation ${orientation} is not part of supported orientations: ${Object.keys(orientationMapping)}`) + throw new Error(`setOrientation failed: provided orientation ${orientation} is not part of supported orientations: ${Object.keys(orientationMapping)}`); } const call = invoke.call(invoke.EarlGrey.instance, diff --git a/detox/src/ios/earlgreyapi/GREYConfiguration.js b/detox/src/ios/earlgreyapi/GREYConfiguration.js index 4269f03b8b..11cc205fd1 100644 --- a/detox/src/ios/earlgreyapi/GREYConfiguration.js +++ b/detox/src/ios/earlgreyapi/GREYConfiguration.js @@ -1,39 +1,179 @@ +/** -const invoke = require('../../invoke'); + This code is generated. + For more information see generation/README.md. +*/ -/** - * An 'invoke' wrapper for https://github.com/google/EarlGrey/blob/master/EarlGrey/Common/GREYConfiguration.h - */ -/** - * - * @param blacklist - array of regular expressions, every matched URL will be ignored. example: [".*www\\.google\\.com", ".*www\\.youtube\\.com"] - * @returns {*} - */ -function setURLBlacklist(blacklist) { - return setValueForConfigKey(blacklist, 'GREYConfigKeyURLBlacklistRegex'); -} -function enableSynchronization() { - //return setValueForConfigKey(invoke.IOS.Boolean(true), 'kGREYConfigKeySynchronizationEnabled'); - return invoke.call(GREYConfigurationInstance(), 'enableSynchronization'); -} +class GREYConfiguration { + /*@return The singleton GREYConfiguration instance. +*/static sharedInstance() { + return { + target: { + type: "Class", + value: "GREYConfiguration" + }, + method: "sharedInstance", + args: [] + }; + } -function disableSynchronization() { - //return setValueForConfigKey(invoke.IOS.Boolean(false), 'kGREYConfigKeySynchronizationEnabled'); - return invoke.call(GREYConfigurationInstance(), 'disableSynchronization'); -} + /*If a user-configured value is associated with the given @c configKey, it is returned, +otherwise the default value is returned. If a default value is not found, or an +NSInvalidArgumentException is raised. -function setValueForConfigKey(value, configKey) { - return invoke.call(GREYConfigurationInstance(), 'setValue:forConfigKey:', value, configKey); -} +@param configKey The key whose value is being queried. Must be a valid @c NSString. + +@throws NSInvalidArgumentException If no value could be found associated with @c configKey. + +@return The value for the configuration stored associate with @c configKey. +*/static valueForConfigKey(element, configKey) { + if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")")))); + return { + target: { + type: "Invocation", + value: element + }, + method: "valueForConfigKey:", + args: [{ + type: "NSString", + value: configKey + }] + }; + } + + /*If a user-configured value is associated with the given @c configKey, it is returned, otherwise +the default value is returned. If a default value is not found, NSInvalidArgumentException is +raised. + +@param configKey The key whose value is being queried. Must be a valid @c NSString. + +@throws NSInvalidArgumentException If no value could be found for the given @c configKey. + +@return The @c BOOL value for the configuration associated with @c configKey. +*/static boolValueForConfigKey(element, configKey) { + if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")")))); + return { + target: { + type: "Invocation", + value: element + }, + method: "boolValueForConfigKey:", + args: [{ + type: "NSString", + value: configKey + }] + }; + } + + /*If a user-configured value is associated with the given @c configKey, it is returned, otherwise +the default value is returned. If a default value is not found, NSInvalidArgumentException is +raised. + +@param configKey The key whose value is being queried. Must be a valid @c NSString. + +@throws NSInvalidArgumentException If no value could be found for the given @c configKey. + +@return The integer value for the configuration associated with @c configKey. +*/static integerValueForConfigKey(element, configKey) { + if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")")))); + return { + target: { + type: "Invocation", + value: element + }, + method: "integerValueForConfigKey:", + args: [{ + type: "NSString", + value: configKey + }] + }; + } + + /*If a user-configured value is associated with the given @c configKey, it is returned, otherwise +the default value is returned. If a default value is not found, NSInvalidArgumentException is +raised. + +@param configKey The key whose value is being queried. Must be a valid @c NSString. + +@throws NSInvalidArgumentException If no value could be found for the given @c configKey. + +@return The @c double value for the configuration associated with @c configKey. +*/static doubleValueForConfigKey(element, configKey) { + if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")")))); + return { + target: { + type: "Invocation", + value: element + }, + method: "doubleValueForConfigKey:", + args: [{ + type: "NSString", + value: configKey + }] + }; + } + + /*Resets all configurations to default values, removing all the configured values. + +@remark Any default values added by calling GREYConfiguration:setDefaultValue:forConfigKey: +are not reset. +*/static reset(element) { + return { + target: { + type: "Invocation", + value: element + }, + method: "reset", + args: [] + }; + } + + /*Given a value and a key that identifies a configuration, set the value of the configuration. +Overwrites any previous value for the configuration. + +@remark To restore original values, call GREYConfiguration::reset. + +@param value The configuration value to be set. Scalars should be wrapped in @c NSValue. +@param configKey Key identifying an existing or new configuration. Must be a valid @c NSString. +*/static setValueForConfigKey(element, value, configKey) { + if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")")))); + return { + target: { + type: "Invocation", + value: element + }, + method: "setValue:forConfigKey:", + args: [value, { + type: "NSString", + value: configKey + }] + }; + } + + /*Associates configuration identified by @c configKey with the provided @c value. + +@remark Default values persist even after resetting the configuration +(using GREYConfiguration::reset) + +@param value The configuration value to be set. Scalars should be wrapped in @c NSValue. +@param configKey Key identifying an existing or new configuration. Must be a valid @c NSString. +*/static setDefaultValueForConfigKey(element, value, configKey) { + if (typeof configKey !== "string") throw new Error("configKey should be a string, but got " + (configKey + (" (" + (typeof configKey + ")")))); + return { + target: { + type: "Invocation", + value: element + }, + method: "setDefaultValue:forConfigKey:", + args: [value, { + type: "NSString", + value: configKey + }] + }; + } -function GREYConfigurationInstance() { - return invoke.call(invoke.IOS.Class('GREYConfiguration'), 'sharedInstance'); } -module.exports = { - setURLBlacklist, - enableSynchronization, - disableSynchronization -}; +module.exports = GREYConfiguration; \ No newline at end of file diff --git a/detox/src/ios/earlgreyapi/GREYConfigurationDetox.js b/detox/src/ios/earlgreyapi/GREYConfigurationDetox.js new file mode 100644 index 0000000000..a8cc4b397d --- /dev/null +++ b/detox/src/ios/earlgreyapi/GREYConfigurationDetox.js @@ -0,0 +1,34 @@ +/** + + This code is generated. + For more information see generation/README.md. +*/ + + + +class GREYConfiguration { + static enableSynchronization(element) { + return { + target: { + type: "Invocation", + value: element + }, + method: "enableSynchronization", + args: [] + }; + } + + static disableSynchronization(element) { + return { + target: { + type: "Invocation", + value: element + }, + method: "disableSynchronization", + args: [] + }; + } + +} + +module.exports = GREYConfiguration; \ No newline at end of file diff --git a/detox/src/ios/earlgreyapi/GREYMatchers.js b/detox/src/ios/earlgreyapi/GREYMatchers.js index 3ef6ce8cee..09775d094f 100644 --- a/detox/src/ios/earlgreyapi/GREYMatchers.js +++ b/detox/src/ios/earlgreyapi/GREYMatchers.js @@ -598,6 +598,61 @@ is required, please implement it similar to @c grey_closeTo. }; } + /*A Matcher that checks if a provided object is equal to the specified @c value. The equality is +determined by calling the @c isEqual: method of the object being examined. In case the @c +value is @c nil, then the object itself is checked to be @c nil. + +@param value The value to be checked for equality. Please ensure that scalar types are +passed in as boxed (object) values. + +@return A matcher that checks if an object is equal to the provided one. +*/static matcherForEqualTo(value) { + return { + target: { + type: "Class", + value: "GREYMatchers" + }, + method: "matcherForEqualTo:", + args: [value] + }; + } + + /*A Matcher that checks if a provided object is less than a specified @c value. The comparison +is made by calling the @c compare: method of the object being examined. + +@param value The value to be compared, which should return @c NSOrderedDescending. Please +ensure that scalar values are passed in as boxed (object) values. + +@return A matcher that checks an object is lesser than another provided @c value. +*/static matcherForLessThan(value) { + return { + target: { + type: "Class", + value: "GREYMatchers" + }, + method: "matcherForLessThan:", + args: [value] + }; + } + + /*A Matcher that checks if a provided object is greater than a specified @c value. The comparison +is made by calling the @c compare: method of the object being examined. + +@param value The value to be compared, which should return @c NSOrderedAscending. Please +ensure that scalar values are passed in as boxed (object) values. + +@return A matcher that checks an object is greater than another provided @c value. +*/static matcherForGreaterThan(value) { + return { + target: { + type: "Class", + value: "GREYMatchers" + }, + method: "matcherForGreaterThan:", + args: [value] + }; + } + /*Matcher that matches a UIScrollView scrolled to content @c edge. @param edge The content edge UIScrollView should be scrolled to. diff --git a/generation/adapters/ios.js b/generation/adapters/ios.js index 001f40f81a..731b4acd82 100644 --- a/generation/adapters/ios.js +++ b/generation/adapters/ios.js @@ -9,7 +9,8 @@ const { isGreyAction, isGreyMatcher, isGreyElementInteraction, - isArray + isArray, + isDefined } = require("../core/type-checks"); const { callGlobal } = require("../helpers"); @@ -29,7 +30,8 @@ const typeCheckInterfaces = { "id": isGreyAction, "id": isGreyMatcher, "GREYElementInteraction*": isGreyElementInteraction, - UIAccessibilityTraits: isArray + UIAccessibilityTraits: isArray, + id: isDefined, }; const contentSanitizersForType = { @@ -72,7 +74,8 @@ module.exports = generator({ "id", "id", "CFTimeInterval", - "UIAccessibilityTraits" + "UIAccessibilityTraits", + "id" ], renameTypesMap: { NSUInteger: "NSInteger", diff --git a/generation/core/generator.js b/generation/core/generator.js index 29642f95c7..4413dba855 100644 --- a/generation/core/generator.js +++ b/generation/core/generator.js @@ -179,6 +179,7 @@ module.exports = function getGenerator({ // These types need no wrapping with {type: ..., value: } const plainArgumentTypes = [ + "id", "id", "id", "GREYElementInteraction*", diff --git a/generation/core/type-checks.js b/generation/core/type-checks.js index e595fc64ef..9b9212774d 100644 --- a/generation/core/type-checks.js +++ b/generation/core/type-checks.js @@ -89,6 +89,16 @@ function isOfClass(className) { }); } +function isDefined() { + return ({ name }) => template(` + if (!ARG) { + throw new Error('${name} should be truthy, but it is "' + ARG + '"'); + } + `)({ + ARG: t.identifier(name) + }); +} + module.exports = { isNumber, isString, @@ -99,5 +109,6 @@ module.exports = { isGreyMatcher, isArray, isOfClass, - isGreyElementInteraction + isGreyElementInteraction, + isDefined }; diff --git a/generation/index.js b/generation/index.js index 7d63cde610..b44e41b7cb 100755 --- a/generation/index.js +++ b/generation/index.js @@ -12,7 +12,11 @@ const iosFiles = { "../detox/ios/Detox/GREYCondition+Detox.h": "../detox/src/ios/earlgreyapi/GREYConditionDetox.js", "../detox/ios/EarlGrey/EarlGrey/Synchronization/GREYCondition.h": - "../detox/src/ios/earlgreyapi/GREYCondition.js" + "../detox/src/ios/earlgreyapi/GREYCondition.js", + "../detox/ios/Detox/GREYConfiguration+Detox.h": + "../detox/src/ios/earlgreyapi/GREYConfigurationDetox.js", + "../detox/ios/EarlGrey/EarlGrey/Common/GREYConfiguration.h": + "../detox/src/ios/earlgreyapi/GREYConfiguration.js" }; generateIOSAdapters(iosFiles);