diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..00a3539 Binary files /dev/null and b/.DS_Store differ diff --git a/Landmarks.xcodeproj/project.xcworkspace/xcuserdata/fylyppo.xcuserdatad/UserInterfaceState.xcuserstate b/Landmarks.xcodeproj/project.xcworkspace/xcuserdata/fylyppo.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..ecce9e9 Binary files /dev/null and b/Landmarks.xcodeproj/project.xcworkspace/xcuserdata/fylyppo.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/LandmarksUITests/LandmarksUITests.m b/LandmarksUITests/LandmarksUITests.m index 87fc9a7..8ab06cd 100644 --- a/LandmarksUITests/LandmarksUITests.m +++ b/LandmarksUITests/LandmarksUITests.m @@ -6,46 +6,25 @@ @interface LandmarksUITests : XCTestCase @implementation LandmarksUITests -- (void)testFavorite { - XCUIApplication *app = [[XCUIApplication alloc] init]; - [app launch]; +- (void)testHomeScreen { + + XCUIApplication *app = [[XCUIApplication alloc] init]; + [app launch]; + + XCUIElementQuery *element = [[app descendantsMatchingType:XCUIElementTypeAny] + matchingIdentifier:@"Turtle Rock"]; + [[element firstMatch] tap]; + + // Simulate pressing the home button + [[XCUIDevice sharedDevice] pressButton:XCUIDeviceButtonHome]; + + sleep(10); + + // Return to the app + [app activate]; + + sleep(2); - XCUIElementQuery *element = [[app descendantsMatchingType:XCUIElementTypeAny] - matchingIdentifier:@"Turtle Rock"]; - [[element firstMatch] tap]; -} - -- (void)testFavoriteUsingPredicates { - XCUIApplication *app = [[XCUIApplication alloc] init]; - [app launch]; - - // Open landmark page - NSPredicate *predicate = - [NSPredicate predicateWithFormat:@"label = %@", @"Turtle Rock"]; - XCUIElementQuery *query = [[app descendantsMatchingType:XCUIElementTypeAny] - matchingPredicate:predicate]; - [[query firstMatch] tap]; - - // Mark landmark as favorite - predicate = [NSPredicate predicateWithFormat:@"identifier = %@", @"favorite"]; - query = [[app descendantsMatchingType:XCUIElementTypeAny] - matchingPredicate:predicate]; - [[query firstMatch] tap]; - - // Go to landmarks list - predicate = [NSPredicate predicateWithFormat:@"label = %@", @"Landmarks"]; - query = [[app descendantsMatchingType:XCUIElementTypeAny] - matchingPredicate:predicate]; - [[query firstMatch] tap]; - - // Assert that landmark is favorited - predicate = [NSPredicate - predicateWithFormat:@"label = %@", @"Turtle Rock, favorited"]; - query = [[app descendantsMatchingType:XCUIElementTypeAny] - matchingPredicate:predicate]; - XCUIElement *element = query.allElementsBoundByIndex.firstObject; - - XCTAssertTrue(element.exists); } @end diff --git a/bs_ios b/bs_ios new file mode 100755 index 0000000..274c212 --- /dev/null +++ b/bs_ios @@ -0,0 +1,106 @@ +#!/usr/bin/env bash +set -euo pipefail + +# bs_ios uploads app binaries for UI testing on BrowserStack. + +if [ -z "${BROWSERSTACK_CREDS:-}" ]; then + echo "Error: missing BROWSERSTACK_CREDS env var" >&2 + exit 1 +fi + +if [ -z "${PROJECT_NAME:-}" ]; then + default_project="Unnamed iOS project" + echo 1>&2 "PROJECT_NAME not set, using default: $default_project" + PROJECT_NAME="$default_project" +fi + +if [ -z "${IOS_DEVICES:-}" ]; then + default_devices="[\"iPhone 14-16\"]" + echo 1>&2 "IOS_DEVICES not set, using default: $default_devices" + IOS_DEVICES="$default_devices" +fi + +if [ -z "${TEST_CASE_TIMEOUT:-}" ]; then + test_case_timeout=180 + echo 1>&2 "TEST_CASE_TIMEOUT not set, using default: $test_case_timeout" + TEST_CASE_TIMEOUT="$test_case_timeout" +fi + +if [ -z "${BUILD_TAG:-}" ]; then + BUILD_TAG="" + echo 1>&2 "BUILD_TAG not set" +fi + +printf 1>&2 "\n" + +rm -rf ./Build + +xcodebuild build-for-testing -scheme Landmarks -destination 'generic/platform=iOS' -derivedDataPath ./Build + +printf 1>&2 "\nZipping test files...\n" + +cd Build/Build/Products/Debug-iphoneos + +mkdir -p Payload +cp -r Landmarks.app Payload +zip -r Landmarks.ipa Payload >/dev/null + +mv ../Landmarks_TestPlan_iphoneos16.0-arm64.xctestrun . + +zip --symlinks -r LandmarksUITests-Runner.zip Landmarks_TestPlan_iphoneos16.0-arm64.xctestrun LandmarksUITests-Runner.app + +printf 1>&2 "Completed zipping\n" + +printf 1>&2 "\nUploading app...\n" + +# https://www.browserstack.com/docs/app-automate/api-reference/xcuitest/apps#upload-an-app +app_url="$( + curl -u "$BROWSERSTACK_CREDS" \ + -X POST "https://api-cloud.browserstack.com/app-automate/xcuitest/v2/app" \ + -F "file=@$PWD/Landmarks.ipa" | jq --raw-output .app_url +)" + +echo 1>&2 "Uploaded app, url: $app_url" + +printf 1>&2 "\nUploading test...\n" + +# https://www.browserstack.com/docs/app-automate/api-reference/xcuitest/tests#upload-a-test-suite +test_url="$( + curl -u "$BROWSERSTACK_CREDS" \ + -X POST "https://api-cloud.browserstack.com/app-automate/xcuitest/v2/test-suite" \ + -F "file=@$PWD/LandmarksUITests-Runner.zip" | + jq --raw-output .test_suite_url +)" + +echo 1>&2 "Uploaded test, url: $test_url" + +printf 1>&2 "\nScheduling test execution...\n" + +# https://www.browserstack.com/docs/app-automate/api-reference/xcuitest/builds#execute-a-build +if ! run_response="$( + curl -u "$BROWSERSTACK_CREDS" \ + -X POST "https://api-cloud.browserstack.com/app-automate/xcuitest/v2/xctestrun-build" \ + -H "Content-Type: application/json" \ + --data-binary @- <&2 "Error: failed to schedule test execution" + echo 1>&2 "$run_response" + exit 1 +fi + +printf 1>&2 "\nScheduled test execution\n" +echo 1>&2 "$run_response" + +build_id="$(echo "$run_response" | jq --raw-output .build_id)" +echo "$build_id"