Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

[Draft] shared web tests #3933

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
97c7254
Big ol backup
jonathanKingston Dec 20, 2024
8b76ca3
Backup of existing work
jonathanKingston Jan 24, 2025
39b2b03
Merge remote-tracking branch 'origin/main' into jkt/shared-web-tests
jonathanKingston Jan 24, 2025
7803231
Use launch args and logging
jonathanKingston Feb 4, 2025
7c02f28
Merge remote-tracking branch 'origin/main' into jkt/shared-web-tests
jonathanKingston Feb 4, 2025
f8ec2b4
Remove maestro specific changes
jonathanKingston Feb 4, 2025
6549f46
Add github workflow
jonathanKingston Feb 4, 2025
9051f24
Remove maestro specific setup
jonathanKingston Feb 4, 2025
8467795
Reorder action
jonathanKingston Feb 4, 2025
f3ab4cc
Move changes to extensions
jonathanKingston Feb 6, 2025
3c11508
Separate out automation steps into their own methods
jonathanKingston Feb 6, 2025
7043bf3
Merge remote-tracking branch 'origin/main' into jkt/shared-web-tests
jonathanKingston Feb 6, 2025
463ab99
Remove debug if statements
jonathanKingston Feb 6, 2025
d46f947
Remove force try in automation server
jonathanKingston Feb 6, 2025
8f82b7d
Rename startAutomationServer to startAutomationServerIfNeeded
jonathanKingston Feb 11, 2025
f05c8d7
Remove making controller public
jonathanKingston Feb 11, 2025
93ac4df
Make AutomationServer final
jonathanKingston Feb 11, 2025
7b00a95
Remove stray commented out global connection handler for Automation
jonathanKingston Feb 11, 2025
cbcd86f
Move currentURL method into direct access within the server
jonathanKingston Feb 11, 2025
e76cd77
Reduce nesting in AutomationServer
jonathanKingston Feb 11, 2025
4313f26
Return early by using guards for error states
jonathanKingston Feb 11, 2025
2fd77ec
Switch object identifiers to use tabModel.uid
jonathanKingston Feb 11, 2025
8f4a97f
Merge remote-tracking branch 'origin/main' into jkt/shared-web-tests
jonathanKingston Feb 11, 2025
784ddb5
Merge remote-tracking branch 'origin/main' into jkt/shared-web-tests
jonathanKingston Feb 12, 2025
6d71981
Automation fixes
jonathanKingston Feb 12, 2025
ef7df0c
Get mainViewController in automation server
jonathanKingston Feb 13, 2025
2b558e9
Simplify configuration of tests
jonathanKingston Feb 13, 2025
af83c26
Move testing steps to npm
jonathanKingston Feb 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/ios-shared-web-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: iOS - PR Checks

on:
push:
branches: [ main, "release/**", 'jkt/shared-web-tests' ]
pull_request:
workflow_call:
inputs:
branch:
description: "Branch name"
required: false
type: string
skip-release:
description: "Skip release build"
required: false
default: false
type: boolean
secrets:
APPLE_API_KEY_BASE64:
required: true
APPLE_API_KEY_ID:
required: true
APPLE_API_KEY_ISSUER:
required: true
ASANA_ACCESS_TOKEN:
required: true
MATCH_PASSWORD:
required: true
SSH_PRIVATE_KEY_FASTLANE_MATCH:
required: true

jobs:
shared-web-tests:
name: Shared web tests

runs-on: macos-15
timeout-minutes: 20
steps:
- name: Check out the code
if: github.event_name == 'pull_request' || github.event_name == 'push'
uses: actions/checkout@v4
with:
submodules: recursive

- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_$(<.xcode-version).app/Contents/Developer

- name: Checkout shared web tests
uses: actions/checkout@v4
with:
submodules: recursive
repository: duckduckgo/shared-web-tests
path: shared-web-tests
ref: jkt/webdriver
token: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Test
run: |
cd shared-web-tests
npm run build
sudo npm run install-hosts

- name: Build iOS
run: |
source .maestro/common.sh
project_root=$(pwd)
build_app

- name: Run tests
run: |
cd shared-web-tests
npm run test


29 changes: 29 additions & 0 deletions .maestro/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ derived_data_path="$project_root"/DerivedData
app_location="$derived_data_path/Build/Products/Debug-iphonesimulator/DuckDuckGo.app"
device_uuid_path="$derived_data_path/device_uuid.txt"

# The simulator command requires the hyphens
target_device="iPhone-16"
target_os="iOS-18-2"

# Convert the target_device and target_os to the format required by the -destination flag
destination_device="${target_device//-/ }"
destination_os_version="${target_os#iOS-}"
destination_os_version="${destination_os_version//-/.}"

echo
echo "Configuration: "
echo "project_root: $project_root"
Expand All @@ -32,4 +41,24 @@ check_command() {
fi
}

build_app() {
if [ -d "$derived_data_path" ] && [ "$1" -eq "0" ]; then
echo "⚠️ Removing previously created $derived_data_path"
rm -rf $derived_data_path
else
echo "ℹ️ Not cleaning derived data at $derived_data_path"
fi

echo "⏲️ Building the app"
set -o pipefail && xcodebuild -project "$project_root"/DuckDuckGo-iOS.xcodeproj \
-scheme "iOS Browser" \
-destination "platform=iOS Simulator,name=$destination_device,OS=$destination_os_version" \
-derivedDataPath "$derived_data_path" \
-skipPackagePluginValidation \
-skipMacroValidation \
ONLY_ACTIVE_ARCH=NO | tee xcodebuild.log
if [ $? -ne 0 ]; then
echo "‼️ Unable to build app into $derived_data_path"
exit 1
fi
}
35 changes: 1 addition & 34 deletions .maestro/setup_ui_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@

source $(dirname $0)/common.sh

## Constants

# The simulator command requires the hyphens
target_device="iPhone-16"
target_os="iOS-18-2"

# Convert the target_device and target_os to the format required by the -destination flag
destination_device="${target_device//-/ }"
destination_os_version="${target_os#iOS-}"
destination_os_version="${destination_os_version//-/.}"

## Functions

check_maestro() {
Expand All @@ -36,36 +25,14 @@ check_maestro() {
else
echo "‼️ maestro not found install using the following commands:"
echo
echo "curl -Ls \"https://get.maestro.mobile.dev\" | bash"
echo "export MAESTRO_VERSION=$known_version; curl -Ls "https://get.maestro.mobile.dev" | bash"
echo "brew tap facebook/fb"
echo "brew install facebook/fb/idb-companion"
echo
exit 1
fi
}

build_app() {
if [ -d "$derived_data_path" ] && [ "$1" -eq "0" ]; then
echo "⚠️ Removing previously created $derived_data_path"
rm -rf $derived_data_path
else
echo "ℹ️ Not cleaning derived data at $derived_data_path"
fi

echo "⏲️ Building the app"
set -o pipefail && xcodebuild -project "$project_root"/DuckDuckGo-iOS.xcodeproj \
-scheme "iOS Browser" \
-destination "platform=iOS Simulator,name=$destination_device,OS=$destination_os_version" \
-derivedDataPath "$derived_data_path" \
-skipPackagePluginValidation \
-skipMacroValidation \
ONLY_ACTIVE_ARCH=NO | tee xcodebuild.log
if [ $? -ne 0 ]; then
echo "‼️ Unable to build app into $derived_data_path"
exit 1
fi
}

## Main Script

echo
Expand Down
12 changes: 12 additions & 0 deletions DuckDuckGo-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,10 @@
7B4F87EA2D0738F90010B18F /* SiriEducationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4F87E92D0738F40010B18F /* SiriEducationView.swift */; };
7B4F87EC2D07396A0010B18F /* SiriEducation.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7B4F87EB2D07396A0010B18F /* SiriEducation.xcassets */; };
7B4F87EE2D0739EB0010B18F /* SiriBubbleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B4F87ED2D0739E80010B18F /* SiriBubbleView.swift */; };
7B70CC3C2D15C0BC0096A1C6 /* AutomationServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B70CC3B2D15C0BC0096A1C6 /* AutomationServer.swift */; };
7B8E0EC62CC81B4900B2B722 /* TipKitController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8E0EC52CC81B4800B2B722 /* TipKitController.swift */; };
7B9D532F2D5431E400D9E937 /* MainViewController+Automation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B9D532E2D5431E400D9E937 /* MainViewController+Automation.swift */; };
7B9D53312D54321200D9E937 /* TabViewController+Automation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B9D53302D54321200D9E937 /* TabViewController+Automation.swift */; };
7BC571202BDBB877003B0CCE /* VPNActivationDateStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */; };
7BC571212BDBB977003B0CCE /* VPNActivationDateStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */; };
7BDBAD0E2CBFB3F1000379B7 /* VPN.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7BDBAD0D2CBFB3F1000379B7 /* VPN.xcassets */; };
Expand Down Expand Up @@ -1911,7 +1914,10 @@
7B4F87E92D0738F40010B18F /* SiriEducationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiriEducationView.swift; sourceTree = "<group>"; };
7B4F87EB2D07396A0010B18F /* SiriEducation.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = SiriEducation.xcassets; sourceTree = "<group>"; };
7B4F87ED2D0739E80010B18F /* SiriBubbleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SiriBubbleView.swift; sourceTree = "<group>"; };
7B70CC3B2D15C0BC0096A1C6 /* AutomationServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutomationServer.swift; sourceTree = "<group>"; };
7B8E0EC52CC81B4800B2B722 /* TipKitController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipKitController.swift; sourceTree = "<group>"; };
7B9D532E2D5431E400D9E937 /* MainViewController+Automation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MainViewController+Automation.swift"; sourceTree = "<group>"; };
7B9D53302D54321200D9E937 /* TabViewController+Automation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TabViewController+Automation.swift"; sourceTree = "<group>"; };
7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VPNActivationDateStore.swift; sourceTree = "<group>"; };
7BDBAD0D2CBFB3F1000379B7 /* VPN.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = VPN.xcassets; sourceTree = "<group>"; };
7BF78E012CA2CC3E0026A1FC /* TipKitAppEventHandling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipKitAppEventHandling.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -6685,6 +6691,7 @@
984147C224F026A300362052 /* Tab.storyboard */,
F1386BA31E6846C40062FC3C /* TabDelegate.swift */,
F159BDA31F0BDB5A00B4A01D /* TabViewController.swift */,
7B9D53302D54321200D9E937 /* TabViewController+Automation.swift */,
31D4CD4F2D4D3CD600BC27C6 /* Navigatable.swift */,
CBC88EE42C8097B500F0F8C5 /* URLCredentialCreator.swift */,
CB2A7EEE283D185100885F67 /* RulesCompilationMonitor.swift */,
Expand Down Expand Up @@ -7066,6 +7073,7 @@
85BA58541F34F49E00C6E8CA /* AppUserDefaults.swift */,
373608912ABB430D00629E7F /* FavoritesDisplayMode+UserDefaults.swift */,
850250B220D803F4002199C7 /* AtbAndVariantCleanup.swift */,
7B70CC3B2D15C0BC0096A1C6 /* AutomationServer.swift */,
983EABB7236198F6003948D1 /* DatabaseMigration.swift */,
853C5F6021C277C7001F7A05 /* global.swift */,
85C8E61C2B0E47380029A6BD /* BookmarksDatabaseSetup.swift */,
Expand All @@ -7088,6 +7096,7 @@
8577A1C4255D2C0D00D43FCD /* HitTestingToolbar.swift */,
85DDE03F2AC6FF65006ABCA2 /* MainView.swift */,
F17669D61E43401C003D3222 /* MainViewController.swift */,
7B9D532E2D5431E400D9E937 /* MainViewController+Automation.swift */,
31D4CD4A2D4D1C2600BC27C6 /* ToolbarStateHandling.swift */,
566B736F2BECD46800FF1959 /* MainViewController+SyncAlerts.swift */,
981CA7E92617797500E119D5 /* MainViewController+AddFavoriteFlow.swift */,
Expand Down Expand Up @@ -8273,6 +8282,7 @@
851672D12BED1FC900592F24 /* AutocompleteView.swift in Sources */,
7B1681022D106CCC005EAE24 /* UserTextShared.swift in Sources */,
3161D13227AC161B00285CF6 /* DownloadMetadata.swift in Sources */,
7B9D532F2D5431E400D9E937 /* MainViewController+Automation.swift in Sources */,
D664C7C72B289AA200CBFA76 /* PurchaseInProgressView.swift in Sources */,
9F465E1E2D3F5C2E00490109 /* Logger+MaliciousSiteProtection.swift in Sources */,
7BFD5FD72C9DB9D7000FF959 /* VPNGeoswitchingTip.swift in Sources */,
Expand Down Expand Up @@ -8391,6 +8401,7 @@
C12324C32C4697C900FBB26B /* AutofillBreakageReportTableViewCell.swift in Sources */,
8586A10D24CBA7070049720E /* FindInPageActivity.swift in Sources */,
9FB0271D2C293619009EA190 /* OnboardingIntroViewModel.swift in Sources */,
7B70CC3C2D15C0BC0096A1C6 /* AutomationServer.swift in Sources */,
9FE08BD62C2A60CD001D5EBC /* MetricBuilder.swift in Sources */,
1E1626072968413B0004127F /* ViewExtension.swift in Sources */,
31A42566285A0A6300049386 /* FaviconViewModel.swift in Sources */,
Expand Down Expand Up @@ -8617,6 +8628,7 @@
1EDE39D22705D4A200C99C72 /* FileSizeDebugViewController.swift in Sources */,
4B412ACC2BBB3D0900A39F5E /* LazyView.swift in Sources */,
7B10FF252D11A56300F36BF2 /* ControlWidgetVPNIntents.swift in Sources */,
7B9D53312D54321200D9E937 /* TabViewController+Automation.swift in Sources */,
85047C772A0D5D3D00D2FF3F /* SyncSettingsViewController+SyncDelegate.swift in Sources */,
C12552972D0B06A100A0FDAA /* FreeTrialsFeatureFlagExperiment.swift in Sources */,
85DDE0402AC6FF65006ABCA2 /* MainView.swift in Sources */,
Expand Down
13 changes: 12 additions & 1 deletion DuckDuckGo/AppLifecycle/AppStates/Launching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ struct Launching: AppState {
UserAgentConfiguration.configureUserBrowsingUserAgent()

setupWindow()
startAutomationServerIfNeeded()
}

private func setupWindow() {
Expand Down Expand Up @@ -179,7 +180,17 @@ struct Launching: AppState {
maliciousSiteProtectionService: maliciousSiteProtectionService
)
}


private func startAutomationServerIfNeeded() {
let launchOptionsHandler = LaunchOptionsHandler()
guard launchOptionsHandler.isUITesting && launchOptionsHandler.automationPort != nil else {
return
}
guard let rootViewController = window.rootViewController as? MainViewController else {
return
}
AutomationServer(main: rootViewController, port: launchOptionsHandler.automationPort)
}
}

extension Launching {
Expand Down
Loading
Loading