From aa25e49fa9821960b08e9f4f3ea5891ebdf7d48d Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sat, 10 Feb 2024 20:59:38 +0100 Subject: [PATCH 1/2] feat: Add a possibility of starting a test with a deep link (#845) --- .../Commands/FBSessionCommands.m | 39 ++++++++++++++++++- WebDriverAgentLib/Utilities/FBCapabilities.h | 20 ++++++++++ WebDriverAgentLib/Utilities/FBCapabilities.m | 1 + package.json | 14 +------ 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index f5abdc55a..fe82a0a35 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -136,7 +136,9 @@ + (NSArray *)routes } NSString *bundleID = capabilities[FB_CAP_BUNDLE_ID]; + NSString *initialUrl = capabilities[FB_CAP_INITIAL_URL]; XCUIApplication *app = nil; + BOOL didOpenInitialUrl = NO; if (bundleID != nil) { app = [[XCUIApplication alloc] initWithBundleIdentifier:bundleID]; BOOL forceAppLaunch = YES; @@ -150,14 +152,47 @@ + (NSArray *)routes || [capabilities[FB_CAP_SHOULD_WAIT_FOR_QUIESCENCE] boolValue]; app.launchArguments = (NSArray *)capabilities[FB_CAP_ARGUMENTS] ?: @[]; app.launchEnvironment = (NSDictionary *)capabilities[FB_CAP_ENVIRNOMENT] ?: @{}; - [app launch]; + if (nil != initialUrl) { + NSError *openError; + didOpenInitialUrl = [XCUIDevice.sharedDevice fb_openUrl:initialUrl + withApplication:bundleID + error:&openError]; + if (!didOpenInitialUrl) { + NSString *errorMsg = [NSString stringWithFormat:@"Cannot open the URL %@ in %@ application. Original error: %@", + initialUrl, bundleID, openError.description]; + return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:errorMsg traceback:nil]); + } + } else { + [app launch]; + } if (![app running]) { NSString *errorMsg = [NSString stringWithFormat:@"Cannot launch %@ application. Make sure the correct bundle identifier has been provided in capabilities and check the device log for possible crash report occurrences", bundleID]; return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:errorMsg traceback:nil]); } } else if (appState == XCUIApplicationStateRunningBackground && !forceAppLaunch) { - [app activate]; + if (nil != initialUrl) { + NSError *openError; + didOpenInitialUrl = [XCUIDevice.sharedDevice fb_openUrl:initialUrl + withApplication:bundleID + error:&openError]; + if (!didOpenInitialUrl) { + NSString *errorMsg = [NSString stringWithFormat:@"Cannot open the URL %@ in %@ application. Original error: %@", + initialUrl, bundleID, openError.description]; + return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:errorMsg traceback:nil]); + } + } else { + [app activate]; + } + } + } + + if (nil != initialUrl && nil == bundleID) { + NSError *openError; + if (![XCUIDevice.sharedDevice fb_openUrl:initialUrl error:&openError]) { + NSString *errorMsg = [NSString stringWithFormat:@"Cannot open the URL %@. Original error: %@", + initialUrl, openError.description]; + return FBResponseWithStatus([FBCommandStatus sessionNotCreatedError:errorMsg traceback:nil]); } } diff --git a/WebDriverAgentLib/Utilities/FBCapabilities.h b/WebDriverAgentLib/Utilities/FBCapabilities.h index 116c408df..1045a9855 100644 --- a/WebDriverAgentLib/Utilities/FBCapabilities.h +++ b/WebDriverAgentLib/Utilities/FBCapabilities.h @@ -9,16 +9,36 @@ #import +/** Whether to use alternative elements visivility detection method */ extern NSString* const FB_CAP_USE_TEST_MANAGER_FOR_VISIBLITY_DETECTION; +/** Set the maximum amount of charatcers that could be typed within a minute (60 by default) */ extern NSString* const FB_CAP_MAX_TYPING_FREQUENCY; +/** this setting was needed for some legacy stuff */ extern NSString* const FB_CAP_USE_SINGLETON_TEST_MANAGER; +/** Whether to disable screneshots that XCTest automaticallly creates after each step */ extern NSString* const FB_CAP_DISABLE_AUTOMATIC_SCREENSHOTS; +/** Whether to terminate the application under test after the session ends */ extern NSString* const FB_CAP_SHOULD_TERMINATE_APP; +/** The maximum amount of seconds to wait for the event loop to become idle */ extern NSString* const FB_CAP_EVENT_LOOP_IDLE_DELAY_SEC; +/** Bundle identifier of the application to run the test for */ extern NSString* const FB_CAP_BUNDLE_ID; +/** + Usually an URL used as initial link to run Mobile Safari, but could be any other deep link. + This might also work together with `FB_CAP_BUNLDE_ID`, which tells XCTest to open + the given deep link in the particular app. + Only works since iOS 16.4 + */ +extern NSString* const FB_CAP_INITIAL_URL; +/** Whether to enforrce (re)start of the application under test on session startup */ extern NSString* const FB_CAP_FORCE_APP_LAUNCH; +/** Whether to wait for quiescence before starting interaction with apps laucnhes in scope of the test session */ extern NSString* const FB_CAP_SHOULD_WAIT_FOR_QUIESCENCE; +/** Array of command line arguments to be passed to the application under test */ extern NSString* const FB_CAP_ARGUMENTS; +/** Dictionary of environment variables to be passed to the application under test */ extern NSString* const FB_CAP_ENVIRNOMENT; +/** Whether to use native XCTest caching strategy */ extern NSString* const FB_CAP_USE_NATIVE_CACHING_STRATEGY; +/** Whether to enforce software keyboard presence on simulator */ extern NSString* const FB_CAP_FORCE_SIMULATOR_SOFTWARE_KEYBOARD_PRESENCE; diff --git a/WebDriverAgentLib/Utilities/FBCapabilities.m b/WebDriverAgentLib/Utilities/FBCapabilities.m index cafd0f168..1798c2195 100644 --- a/WebDriverAgentLib/Utilities/FBCapabilities.m +++ b/WebDriverAgentLib/Utilities/FBCapabilities.m @@ -16,6 +16,7 @@ NSString* const FB_CAP_SHOULD_TERMINATE_APP = @"shouldTerminateApp"; NSString* const FB_CAP_EVENT_LOOP_IDLE_DELAY_SEC = @"eventloopIdleDelaySec"; NSString* const FB_CAP_BUNDLE_ID = @"bundleId"; +NSString* const FB_CAP_INITIAL_URL = @"initialUrl"; NSString* const FB_CAP_FORCE_APP_LAUNCH = @"forceAppLaunch"; NSString* const FB_CAP_SHOULD_WAIT_FOR_QUIESCENCE = @"shouldWaitForQuiescence"; NSString* const FB_CAP_ARGUMENTS = @"arguments"; diff --git a/package.json b/package.json index 23248bbce..0df5e1b9c 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,8 @@ "dev": "npm run build -- --watch", "clean": "npm run build -- --clean", "lint": "eslint .", + "format": "prettier -w ./lib", "lint:fix": "npm run lint -- --fix", - "precommit-msg": "echo 'Pre-commit checks...' && exit 0", - "precommit-lint": "lint-staged", "prepare": "npm run build", "test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.js\"", "e2e-test": "mocha --exit --timeout 10m \"./test/functional/**/*-specs.js\"", @@ -23,20 +22,11 @@ "node": ">=14", "npm": ">=8" }, - "lint-staged": { - "*.js": [ - "eslint --fix" - ] - }, "prettier": { "bracketSpacing": false, "printWidth": 100, "singleQuote": true }, - "pre-commit": [ - "precommit-msg", - "precommit-lint" - ], "repository": { "type": "git", "url": "git+https://github.com/appium/WebDriverAgent.git" @@ -83,9 +73,7 @@ "eslint-plugin-import": "^2.28.0", "eslint-plugin-mocha": "^10.1.0", "eslint-plugin-promise": "^6.1.1", - "lint-staged": "^15.0.2", "mocha": "^10.0.0", - "pre-commit": "^1.2.2", "prettier": "^3.0.0", "semantic-release": "^23.0.0", "sinon": "^17.0.0", From ed06d2f2b60d546a9e7d0ffaa28dd3eb84d4fe3a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Sat, 10 Feb 2024 20:05:47 +0000 Subject: [PATCH 2/2] chore(release): 6.1.0 [skip ci] ## [6.1.0](https://github.com/appium/WebDriverAgent/compare/v6.0.0...v6.1.0) (2024-02-10) ### Features * Add a possibility of starting a test with a deep link ([#845](https://github.com/appium/WebDriverAgent/issues/845)) ([aa25e49](https://github.com/appium/WebDriverAgent/commit/aa25e49fa9821960b08e9f4f3ea5891ebdf7d48d)) --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e0aabb3e..e41776692 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [6.1.0](https://github.com/appium/WebDriverAgent/compare/v6.0.0...v6.1.0) (2024-02-10) + + +### Features + +* Add a possibility of starting a test with a deep link ([#845](https://github.com/appium/WebDriverAgent/issues/845)) ([aa25e49](https://github.com/appium/WebDriverAgent/commit/aa25e49fa9821960b08e9f4f3ea5891ebdf7d48d)) + ## [6.0.0](https://github.com/appium/WebDriverAgent/compare/v5.15.8...v6.0.0) (2024-01-31) diff --git a/package.json b/package.json index 0df5e1b9c..175c61b1a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "appium-webdriveragent", - "version": "6.0.0", + "version": "6.1.0", "description": "Package bundling WebDriverAgent", "main": "./build/index.js", "scripts": {