From 998457914623909a881944a4b3c401649ead09b2 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Thu, 18 Jul 2024 21:59:48 +0200 Subject: [PATCH 01/12] fix: Add a test for the keyboard input and perform related fixes --- .../IntegrationTests/AMW3CActionsTests.m | 45 ++++++++++++ .../Utilities/FBW3CActionsSynthesizer.m | 71 +++++++++---------- .../xcdebugger/Breakpoints_v2.xcbkptlist | 14 ++++ 3 files changed, 93 insertions(+), 37 deletions(-) diff --git a/WebDriverAgentMac/IntegrationTests/AMW3CActionsTests.m b/WebDriverAgentMac/IntegrationTests/AMW3CActionsTests.m index c35246d..20ddf98 100644 --- a/WebDriverAgentMac/IntegrationTests/AMW3CActionsTests.m +++ b/WebDriverAgentMac/IntegrationTests/AMW3CActionsTests.m @@ -261,6 +261,18 @@ - (void)testErroneousGestures }, ], + // Keys are not balanced + @[@{ + @"type": @"key", + @"id": @"keyboard", + @"actions": @[ + @{@"type": @"keyDown", @"value": @"n"}, + @{@"type": @"keyUp", @"value": @"n"}, + @{@"type": @"keyUp", @"value": @"b"}, + ], + }, + ], + ]; for (NSArray *> *invalidGesture in invalidGestures) { @@ -274,6 +286,7 @@ - (void)testErroneousGestures - (void)testClick { + [self switchToButtonsTab]; XCUIElement *checkbox = self.testedApplication.checkBoxes.firstMatch; NSNumber *value = checkbox.value; @@ -300,6 +313,7 @@ - (void)testClick - (void)testRightClick { + [self switchToButtonsTab]; XCUIElement *checkbox = self.testedApplication.checkBoxes.firstMatch; NSNumber *value = checkbox.value; @@ -324,5 +338,36 @@ - (void)testRightClick XCTAssertTrue([checkbox.value boolValue] == [value boolValue]); } +- (void)testKeys +{ + [self switchToEditsTab]; + XCUIElement *edit = self.testedApplication.textFields.firstMatch; + [edit click]; + + NSArray *> *gesture = + @[@{ + @"type": @"key", + @"id": @"keyboard", + @"actions": @[ + @{@"type": @"keyDown", @"value": @"\uE008"}, + @{@"type": @"pause", @"duration": @500}, + @{@"type": @"keyDown", @"value": @"n"}, + @{@"type": @"keyUp", @"value": @"n"}, + @{@"type": @"keyDown", @"value": @"b"}, + @{@"type": @"keyUp", @"value": @"b"}, + @{@"type": @"keyDown", @"value": @"a"}, + @{@"type": @"keyUp", @"value": @"a"}, + @{@"type": @"pause", @"duration": @500}, + @{@"type": @"keyUp", @"value": @"\uE008"}, + ], + }, + ]; + NSError *error; + XCTAssertTrue([self.testedApplication fb_performW3CActions:gesture + elementCache:nil + error:&error]); + XCTAssertNil(error); + XCTAssertEqualObjects(edit.value, @"NBA"); +} @end diff --git a/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBW3CActionsSynthesizer.m b/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBW3CActionsSynthesizer.m index ac5c741..1cb2c56 100644 --- a/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBW3CActionsSynthesizer.m +++ b/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBW3CActionsSynthesizer.m @@ -80,7 +80,7 @@ @interface FBW3CKeyItem : FBBaseActionItem @property (nullable, readonly, nonatomic) FBW3CKeyItem *previousItem; -- (NSUInteger)calculateModifierForChain:(NSArray *)allItems +- (NSUInteger)calculateModifiersForChain:(NSArray *)allItems lastItemIndex:(NSUInteger)lastItemIndex; @end @@ -436,7 +436,7 @@ - (nullable instancetype)initWithActionItem:(NSDictionary *)acti return self; } -- (NSUInteger)calculateModifierForChain:(NSArray *)allItems +- (NSUInteger)calculateModifiersForChain:(NSArray *)allItems lastItemIndex:(NSUInteger)lastItemIndex { NSUInteger result = 0; @@ -501,7 +501,7 @@ - (BOOL)hasDownPairInItems:(NSArray *)allItems BOOL isKeyDown = [item isKindOfClass:FBKeyDownItem.class]; BOOL isKeyUp = !isKeyDown && [item isKindOfClass:FBKeyUpItem.class]; if (!isKeyUp && !isKeyDown) { - break; + continue; } NSString *value = [item performSelector:@selector(value)]; @@ -536,36 +536,46 @@ + (NSUInteger)defaultTypingFrequency } NSNumber *modifier = AMToMetaModifier(self.value); - NSTimeInterval offsetSeconds = FBMillisToSeconds(self.offset); - XCPointerEventPath *result = nil == eventPath ? [[XCPointerEventPath alloc] initForTextInput] : eventPath; if (nil != modifier) { - NSUInteger previousModifier = [self calculateModifierForChain:allItems lastItemIndex:currentItemIndex - 1]; - [result setModifiers:previousModifier & ~[modifier unsignedIntValue] -mergeWithCurrentModifierFlags:NO - atOffset:offsetSeconds]; - return @[result]; + return @[]; } + NSTimeInterval offsetSeconds = FBMillisToSeconds(self.offset); + XCPointerEventPath *result = nil == eventPath ? [[XCPointerEventPath alloc] initForTextInput] : eventPath; + NSString *specialKey = AMToSpecialKey(self.value); + NSUInteger modifiers = [self calculateModifiersForChain:allItems lastItemIndex:currentItemIndex]; if (nil != specialKey) { - NSUInteger previousModifier = [self calculateModifierForChain:allItems lastItemIndex:currentItemIndex]; - if ([specialKey isEqualToString:@""]) { - // NOOP - [result setModifiers:previousModifier -mergeWithCurrentModifierFlags:NO - atOffset:offsetSeconds]; - } else { + if (specialKey.length > 0) { [result typeKey:specialKey - modifiers:previousModifier + modifiers:modifiers atOffset:offsetSeconds]; } return @[result]; } - [result typeText:self.value - atOffset:offsetSeconds - typingSpeed:[self.class defaultTypingFrequency] - shouldRedact:NO]; + NSUInteger len = [self.value length]; + unichar buffer[len + 1]; + [self.value getCharacters:buffer range:NSMakeRange(0, len)]; + for (int i = 0; i < 1; i++) { + unichar charCode = buffer[i]; + NSString *oneChar = [NSString stringWithFormat:@"%C", charCode]; + // 0x7F is the end of the first half of the ASCII table, where (almoust) all + // chars have their own key representations + if (charCode <= 0x7F) { + [result typeKey:oneChar + modifiers:modifiers + atOffset:offsetSeconds]; + } else { + // The typeText API does not respect modifiers + // while the typeKey API can only enter keys + [result typeText:oneChar + atOffset:offsetSeconds + typingSpeed:[self.class defaultTypingFrequency] + shouldRedact:NO]; + } + } + return @[result]; } @@ -608,7 +618,7 @@ - (BOOL)hasUpPairInItems:(NSArray *)allItems BOOL isKeyDown = [item isKindOfClass:FBKeyDownItem.class]; BOOL isKeyUp = !isKeyDown && [item isKindOfClass:FBKeyUpItem.class]; if (!isKeyUp && !isKeyDown) { - break; + continue; } NSString *value = [item performSelector:@selector(value)]; @@ -635,20 +645,7 @@ - (BOOL)hasUpPairInItems:(NSArray *)allItems return nil; } - NSNumber *modifier = AMToMetaModifier(self.value); - if (nil == modifier) { - return @[]; - } - NSUInteger previousModifier = [self calculateModifierForChain:allItems lastItemIndex:currentItemIndex - 1]; - if ([modifier unsignedIntValue] == previousModifier) { - return @[]; - } - - XCPointerEventPath *result = nil == eventPath ? [[XCPointerEventPath alloc] initForTextInput] : eventPath; - [result setModifiers:previousModifier | [modifier unsignedIntValue] -mergeWithCurrentModifierFlags:NO - atOffset:FBMillisToSeconds(self.offset)]; - return @[result]; + return @[]; } @end diff --git a/WebDriverAgentMac/WebDriverAgentMac.xcodeproj/xcuserdata/elf.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/WebDriverAgentMac/WebDriverAgentMac.xcodeproj/xcuserdata/elf.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 551471a..b3625ab 100644 --- a/WebDriverAgentMac/WebDriverAgentMac.xcodeproj/xcuserdata/elf.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/WebDriverAgentMac/WebDriverAgentMac.xcodeproj/xcuserdata/elf.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,4 +3,18 @@ uuid = "EB05C65E-1678-400C-AEEC-EE53AC4C3816" type = "1" version = "2.0"> + + + + + + From 0350df0978ab8fd15dfef97109bbf7331809e5ab Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Thu, 18 Jul 2024 22:01:04 +0200 Subject: [PATCH 02/12] revert --- .../xcdebugger/Breakpoints_v2.xcbkptlist | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/WebDriverAgentMac/WebDriverAgentMac.xcodeproj/xcuserdata/elf.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/WebDriverAgentMac/WebDriverAgentMac.xcodeproj/xcuserdata/elf.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index b3625ab..551471a 100644 --- a/WebDriverAgentMac/WebDriverAgentMac.xcodeproj/xcuserdata/elf.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/WebDriverAgentMac/WebDriverAgentMac.xcodeproj/xcuserdata/elf.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,18 +3,4 @@ uuid = "EB05C65E-1678-400C-AEEC-EE53AC4C3816" type = "1" version = "2.0"> - - - - - - From fd3984af467ffd6725c162a77b75ae0f35da9757 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 19 Jul 2024 08:55:35 +0200 Subject: [PATCH 03/12] eslint --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index bf1d867..57ea551 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "appium": "^2.4.1" }, "devDependencies": { + "@appium/eslint-config-appium": "^8.0.5", "@appium/eslint-config-appium-ts": "^0.x", "@appium/tsconfig": "^0.x", "@appium/types": "^0.x", From e8ef76950b5f6e2ef8f6edc577d1883899d5f72e Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 19 Jul 2024 09:02:48 +0200 Subject: [PATCH 04/12] try npx --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index 57ea551..c906f36 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "clean": "npm run build -- --clean", "rebuild": "npm run clean; npm run build", "dev": "npm run build -- --watch", - "lint": "eslint .", + "lint": "npx eslint .", "lint:fix": "npm run lint -- --fix", "prepare": "npm run rebuild", "test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.js\"", @@ -68,7 +68,6 @@ "appium": "^2.4.1" }, "devDependencies": { - "@appium/eslint-config-appium": "^8.0.5", "@appium/eslint-config-appium-ts": "^0.x", "@appium/tsconfig": "^0.x", "@appium/types": "^0.x", From ab5c879f3dbb4eae48447650e1b4cc239d207d1a Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 19 Jul 2024 09:06:58 +0200 Subject: [PATCH 05/12] add eslint --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index c906f36..b08d613 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "clean": "npm run build -- --clean", "rebuild": "npm run clean; npm run build", "dev": "npm run build -- --watch", - "lint": "npx eslint .", + "lint": "eslint .", "lint:fix": "npm run lint -- --fix", "prepare": "npm run rebuild", "test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.js\"", @@ -81,6 +81,7 @@ "chai": "^5.1.1", "chai-as-promised": "^8.0.0", "conventional-changelog-conventionalcommits": "^7.0.1", + "eslint": "^8.57.0", "mocha": "^10.0.0", "semantic-release": "^23.0.0", "sinon": "^17.0.0", From 4266be63f2f08ce523b5a6c7220c0d69271059f3 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 19 Jul 2024 09:10:50 +0200 Subject: [PATCH 06/12] try global lint --- .github/workflows/unit-test.yml | 1 + package.json | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 16c573c..07ba98f 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -37,6 +37,7 @@ jobs: node-version: ${{ matrix.node-version }} - run: npm install --no-package-lock name: Install dev dependencies + - run: npm i -g eslint@8.57.0 - run: npm run lint name: Run linter - run: npm run test diff --git a/package.json b/package.json index b08d613..bf1d867 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,6 @@ "chai": "^5.1.1", "chai-as-promised": "^8.0.0", "conventional-changelog-conventionalcommits": "^7.0.1", - "eslint": "^8.57.0", "mocha": "^10.0.0", "semantic-release": "^23.0.0", "sinon": "^17.0.0", From 6ff84f9d8c6c51970dd4d93e15ee2d9880dfa9b7 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 19 Jul 2024 09:17:35 +0200 Subject: [PATCH 07/12] mocha --- .github/workflows/unit-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 07ba98f..02c19f1 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -35,9 +35,11 @@ jobs: - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} + - run: | + npm i -g eslint@8.57.0 + npm i -g mocha - run: npm install --no-package-lock name: Install dev dependencies - - run: npm i -g eslint@8.57.0 - run: npm run lint name: Run linter - run: npm run test From e742103076b27b4098e5d606fde0ff99099805e6 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 19 Jul 2024 09:23:38 +0200 Subject: [PATCH 08/12] moar --- .github/workflows/unit-test.yml | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 02c19f1..9d157a2 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -35,9 +35,8 @@ jobs: - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - - run: | - npm i -g eslint@8.57.0 - npm i -g mocha + - run: npm i -g eslint@8.57.0 + - run: npm i -g mocha - run: npm install --no-package-lock name: Install dev dependencies - run: npm run lint @@ -48,11 +47,15 @@ jobs: analyze_wda: strategy: matrix: - os: [macos-11, macos-12] - xcode_version: [13, 14] + os: [macos-12, macos-13, macos-14] + xcode_version: [13, 14, 15] exclude: - - os: macos-11 - xcode_version: 14 + - os: macos-13 + xcode_version: 13 + - os: macos-14 + xcode_version: 13 + - os: macos-12 + xcode_version: 15 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 From a05fa4b38803dbf1e6b1d46567be4d9c21d3284f Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 19 Jul 2024 09:32:11 +0200 Subject: [PATCH 09/12] try --- .github/workflows/unit-test.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 9d157a2..a3c8e83 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -35,13 +35,15 @@ jobs: - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - - run: npm i -g eslint@8.57.0 - - run: npm i -g mocha + # - run: npm i -g eslint@8.57.0 + # - run: npm i -g mocha - run: npm install --no-package-lock name: Install dev dependencies - - run: npm run lint + - run: ls "$(pwd)/node_modules/.bin" + - run: ls "$(pwd)/node_modules" + - run: PATH=$(pwd)/node_modules/.bin:$PATH npm run lint name: Run linter - - run: npm run test + - run: PATH=$(pwd)/node_modules/.bin:$PATH npm run test name: Run unit tests analyze_wda: From 8719f849cfdca27c8533c46d9b4c60a4491887b5 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 19 Jul 2024 10:47:14 +0200 Subject: [PATCH 10/12] revert --- .github/workflows/unit-test.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index a3c8e83..f9dbf22 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -35,15 +35,11 @@ jobs: - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - # - run: npm i -g eslint@8.57.0 - # - run: npm i -g mocha - run: npm install --no-package-lock name: Install dev dependencies - - run: ls "$(pwd)/node_modules/.bin" - - run: ls "$(pwd)/node_modules" - - run: PATH=$(pwd)/node_modules/.bin:$PATH npm run lint + - run: npm run lint name: Run linter - - run: PATH=$(pwd)/node_modules/.bin:$PATH npm run test + - run: npm run test name: Run unit tests analyze_wda: From b240b62a9495b0333041133b3602e8ee69468feb Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 19 Jul 2024 21:51:45 +0200 Subject: [PATCH 11/12] run ci --- .github/workflows/unit-test.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index f9dbf22..210bca7 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -48,12 +48,12 @@ jobs: os: [macos-12, macos-13, macos-14] xcode_version: [13, 14, 15] exclude: - - os: macos-13 - xcode_version: 13 - - os: macos-14 - xcode_version: 13 - - os: macos-12 - xcode_version: 15 + - os: macos-13 + xcode_version: 13 + - os: macos-14 + xcode_version: 13 + - os: macos-12 + xcode_version: 15 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 From 146d78c9bad14104e70309af7ef17a54e7d81b2b Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 19 Jul 2024 22:04:32 +0200 Subject: [PATCH 12/12] check latest --- .github/workflows/unit-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 210bca7..7becc40 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -35,6 +35,7 @@ jobs: - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} + check-latest: true - run: npm install --no-package-lock name: Install dev dependencies - run: npm run lint