Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouyunpeng2 committed Jul 5, 2024
2 parents 55b1d66 + 2a1a4e7 commit 162733a
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 50 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
prepare_matrix:
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.generate-matrix.outputs.versions }}
versions: ${{ steps.generate-matrix.outputs.active }}
steps:
- name: Select 3 most recent LTS versions of Node.js
- name: Select all active LTS versions of Node.js
id: generate-matrix
run: echo "versions=$(curl -s https://endoflife.date/api/nodejs.json | jq -c '[[.[] | select(.lts != false)][:3] | .[].cycle | tonumber]')" >> "$GITHUB_OUTPUT"
uses: msimerson/node-lts-versions@v1

test:
needs:
Expand Down
43 changes: 43 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
## [8.7.6](https://github.com/appium/WebDriverAgent/compare/v8.7.5...v8.7.6) (2024-07-02)

### Miscellaneous Chores

* Simplify xcodebuild lines monitoring ([#916](https://github.com/appium/WebDriverAgent/issues/916)) ([87678f2](https://github.com/appium/WebDriverAgent/commit/87678f260c98b3a3bc3d37017e9ef39098ccb3c4))

## [8.7.5](https://github.com/appium/WebDriverAgent/compare/v8.7.4...v8.7.5) (2024-06-26)

### Bug Fixes

* Respect wdaRemotePort capability for real devices ([#915](https://github.com/appium/WebDriverAgent/issues/915)) ([03ea143](https://github.com/appium/WebDriverAgent/commit/03ea1439a9cc5b6495be60707bc474e3ae9bdb06))

## [8.7.4](https://github.com/appium/WebDriverAgent/compare/v8.7.3...v8.7.4) (2024-06-20)

### Miscellaneous Chores

* Bump chai and chai-as-promised ([#913](https://github.com/appium/WebDriverAgent/issues/913)) ([9086783](https://github.com/appium/WebDriverAgent/commit/90867832ec3077f0036938aa68a168a5702fc90a))

## [8.7.3](https://github.com/appium/WebDriverAgent/compare/v8.7.2...v8.7.3) (2024-06-12)

### Miscellaneous Chores

* **deps:** bump @appium/support from 4.5.0 to 5.0.3 ([#910](https://github.com/appium/WebDriverAgent/issues/910)) ([936005b](https://github.com/appium/WebDriverAgent/commit/936005b458e7b5b64b60d9bda37d45bb5a90e615))

## [8.7.2](https://github.com/appium/WebDriverAgent/compare/v8.7.1...v8.7.2) (2024-06-04)

### Miscellaneous Chores

* **deps-dev:** bump sinon from 17.0.2 to 18.0.0 ([#903](https://github.com/appium/WebDriverAgent/issues/903)) ([87e4ba5](https://github.com/appium/WebDriverAgent/commit/87e4ba5ce3868d99ac889795039936be119ef87a))

## [8.7.1](https://github.com/appium/WebDriverAgent/compare/v8.7.0...v8.7.1) (2024-06-04)

### Miscellaneous Chores

* **deps-dev:** bump semantic-release from 23.1.1 to 24.0.0 and conventional-changelog-conventionalcommits to 8.0.0 ([#908](https://github.com/appium/WebDriverAgent/issues/908)) ([26019ec](https://github.com/appium/WebDriverAgent/commit/26019eca9b7331353e26a1014bc4afcecc0450f3))

## [8.7.0](https://github.com/appium/WebDriverAgent/compare/v8.6.0...v8.7.0) (2024-06-01)


### Features

* Add a setting to respect system alerts while detecting active apps ([#907](https://github.com/appium/WebDriverAgent/issues/907)) ([5c82d66](https://github.com/appium/WebDriverAgent/commit/5c82d66890b1a74f9b6f698c87590b2154a6c1bd))

## [8.6.0](https://github.com/appium/WebDriverAgent/compare/v8.5.7...v8.6.0) (2024-05-17)


Expand Down
4 changes: 4 additions & 0 deletions WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ + (NSArray *)routes
FB_SETTING_DISMISS_ALERT_BUTTON_SELECTOR: FBConfiguration.dismissAlertButtonSelector,
FB_SETTING_DEFAULT_ALERT_ACTION: request.session.defaultAlertAction ?: @"",
FB_SETTING_MAX_TYPING_FREQUENCY: @([FBConfiguration maxTypingFrequency]),
FB_SETTING_RESPECT_SYSTEM_ALERTS: @([FBConfiguration shouldRespectSystemAlerts]),
#if !TARGET_OS_TV
FB_SETTING_SCREENSHOT_ORIENTATION: [FBConfiguration humanReadableScreenshotOrientation],
#endif
Expand Down Expand Up @@ -385,6 +386,9 @@ + (NSArray *)routes
if (nil != [settings objectForKey:FB_SETTING_KEYBOARD_PREDICTION]) {
[FBConfiguration setKeyboardPrediction:[[settings objectForKey:FB_SETTING_KEYBOARD_PREDICTION] boolValue]];
}
if (nil != [settings objectForKey:FB_SETTING_RESPECT_SYSTEM_ALERTS]) {
[FBConfiguration setShouldRespectSystemAlerts:[[settings objectForKey:FB_SETTING_RESPECT_SYSTEM_ALERTS] boolValue]];
}
// SNAPSHOT_TIMEOUT setting is deprecated. Please use CUSTOM_SNAPSHOT_TIMEOUT instead
if (nil != [settings objectForKey:FB_SETTING_SNAPSHOT_TIMEOUT]) {
[FBConfiguration setCustomSnapshotTimeout:[[settings objectForKey:FB_SETTING_SNAPSHOT_TIMEOUT] doubleValue]];
Expand Down
4 changes: 2 additions & 2 deletions WebDriverAgentLib/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>8.6.0</string>
<string>8.7.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>8.6.0</string>
<string>8.7.6</string>
<key>NSPrincipalClass</key>
<string/>
</dict>
Expand Down
4 changes: 4 additions & 0 deletions WebDriverAgentLib/Routing/FBSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ - (XCUIApplication *)activeApplication
if (nil != self.testedApplication) {
XCUIApplicationState testedAppState = self.testedApplication.state;
if (testedAppState >= XCUIApplicationStateRunningForeground) {
if ([FBConfiguration shouldRespectSystemAlerts]
&& [XCUIApplication.fb_systemApplication descendantsMatchingType:XCUIElementTypeAlert].count > 0) {
return XCUIApplication.fb_systemApplication;
}
return (XCUIApplication *)self.testedApplication;
}
if (self.isTestedApplicationExpectedToRun && testedAppState <= XCUIApplicationStateNotRunning) {
Expand Down
4 changes: 4 additions & 0 deletions WebDriverAgentLib/Utilities/FBConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ extern NSString *const FBSnapshotMaxDepthKey;
+ (void)setShouldUseSingletonTestManager:(BOOL)value;
+ (BOOL)shouldUseSingletonTestManager;

/* Enforces WDA to verify the presense of system alerts while checking for an active app */
+ (void)setShouldRespectSystemAlerts:(BOOL)value;
+ (BOOL)shouldRespectSystemAlerts;

/**
* Extract switch value from arguments
*
Expand Down
11 changes: 11 additions & 0 deletions WebDriverAgentLib/Utilities/FBConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

static BOOL FBShouldUseTestManagerForVisibilityDetection = NO;
static BOOL FBShouldUseSingletonTestManager = YES;
static BOOL FBShouldRespectSystemAlerts = NO;

static NSUInteger FBMjpegScalingFactor = 100;
static BOOL FBMjpegShouldFixOrientation = NO;
Expand Down Expand Up @@ -373,6 +374,16 @@ + (int)snapshotMaxDepth
return [FBGetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey) intValue];
}

+ (void)setShouldRespectSystemAlerts:(BOOL)value
{
FBShouldRespectSystemAlerts = value;
}

+ (BOOL)shouldRespectSystemAlerts
{
return FBShouldRespectSystemAlerts;
}

+ (void)setUseFirstMatch:(BOOL)enabled
{
FBShouldUseFirstMatch = enabled;
Expand Down
1 change: 1 addition & 0 deletions WebDriverAgentLib/Utilities/FBSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern NSString* const FB_SETTING_SCREENSHOT_ORIENTATION;
extern NSString* const FB_SETTING_WAIT_FOR_IDLE_TIMEOUT;
extern NSString* const FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT;
extern NSString* const FB_SETTING_MAX_TYPING_FREQUENCY;
extern NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS;


NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions WebDriverAgentLib/Utilities/FBSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
NSString* const FB_SETTING_WAIT_FOR_IDLE_TIMEOUT = @"waitForIdleTimeout";
NSString* const FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT = @"animationCoolOffTimeout";
NSString* const FB_SETTING_MAX_TYPING_FREQUENCY = @"maxTypingFrequency";
NSString* const FB_SETTING_RESPECT_SYSTEM_ALERTS = @"respectSystemAlerts";
3 changes: 2 additions & 1 deletion lib/webdriveragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class WebDriverAgent {
this.setWDAPaths(args.bootstrapPath, args.agentPath);

this.wdaLocalPort = args.wdaLocalPort;
this.wdaRemotePort = args.wdaLocalPort || WDA_AGENT_PORT;
this.wdaRemotePort = ((this.isRealDevice ? args.wdaRemotePort : null) ?? args.wdaLocalPort)
|| WDA_AGENT_PORT;
this.wdaBaseUrl = args.wdaBaseUrl || WDA_BASE_URL;

this.prebuildWDA = args.prebuildWDA;
Expand Down
31 changes: 18 additions & 13 deletions lib/xcodebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from './utils';
import _ from 'lodash';
import path from 'path';
import { EOL } from 'os';
import { WDA_RUNNER_BUNDLE_ID } from './constants';


Expand All @@ -26,6 +25,13 @@ const IGNORED_ERRORS = [
ERROR_COPYING_ATTACHMENT,
'Failed to remove screenshot at path',
];
const IGNORED_ERRORS_PATTERN = new RegExp(
'(' +
IGNORED_ERRORS
.map((errStr) => _.escapeRegExp(errStr))
.join('|') +
')'
);

const RUNNER_SCHEME_TV = 'WebDriverAgentRunner_tvOS';
const LIB_SCHEME_TV = 'WebDriverAgentLib_tvOS';
Expand Down Expand Up @@ -324,27 +330,26 @@ export class XcodeBuild {
? `Output from xcodebuild ${this.showXcodeLog ? 'will' : 'will not'} be logged`
: 'Output from xcodebuild will only be logged if any errors are present there';
this.log.debug(`${logMsg}. To change this, use 'showXcodeLog' desired capability`);
xcodebuild.on('output', (stdout, stderr) => {
let out = stdout || stderr;

const onStreamLine = (/** @type {string} */ line) => {
if (this.showXcodeLog === false || IGNORED_ERRORS_PATTERN.test(line)) {
return;
}
// if we have an error we want to output the logs
// otherwise the failure is inscrutible
// but do not log permission errors from trying to write to attachments folder
const ignoreError = IGNORED_ERRORS.some((x) => out.includes(x));
if (this.showXcodeLog !== false && out.includes('Error Domain=') && !ignoreError) {
if (line.includes('Error Domain=')) {
logXcodeOutput = true;

// handle case where xcode returns 0 but is failing
this._didBuildFail = true;
}

// do not log permission errors from trying to write to attachments folder
if (logXcodeOutput && !ignoreError) {
for (const line of out.split(EOL)) {
xcodeLog.error(line);
}
if (logXcodeOutput) {
xcodeLog.info(line);
}
});
};
for (const streamName of ['stderr', 'stdout']) {
xcodebuild.on(`line-${streamName}`, onStreamLine);
}

return xcodebuild;
}
Expand Down
21 changes: 8 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "appium-webdriveragent",
"version": "8.6.0",
"version": "8.7.6",
"description": "Package bundling WebDriverAgent",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand Down Expand Up @@ -48,40 +48,35 @@
},
"homepage": "https://github.com/appium/WebDriverAgent#readme",
"devDependencies": {
"@appium/eslint-config-appium": "^8.0.4",
"@appium/eslint-config-appium-ts": "^0.x",
"@appium/test-support": "^3.0.0",
"@appium/tsconfig": "^0.x",
"@appium/types": "^0.x",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@types/bluebird": "^3.5.38",
"@types/chai": "^4.3.5",
"@types/chai-as-promised": "^7.1.5",
"@types/lodash": "^4.14.196",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.7",
"@types/sinon": "^17.0.0",
"@types/sinon-chai": "^3.2.9",
"@types/teen_process": "^2.0.1",
"appium-xcode": "^5.0.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"conventional-changelog-conventionalcommits": "^7.0.1",
"chai": "^5.1.1",
"chai-as-promised": "^8.0.0",
"conventional-changelog-conventionalcommits": "^8.0.0",
"fancy-log": "^2.0.0",
"node-simctl": "^7.0.1",
"mocha": "^10.0.0",
"prettier": "^3.0.0",
"semantic-release": "^23.0.0",
"semantic-release": "^24.0.0",
"semver": "^7.3.7",
"sinon": "^17.0.0",
"sinon": "^18.0.0",
"ts-node": "^10.9.1",
"typescript": "^5.4.2"
},
"dependencies": {
"@appium/base-driver": "^9.0.0",
"@appium/strongbox": "^0.x",
"@appium/support": "^4.0.0",
"@appium/support": "^5.0.3",
"appium-ios-device": "^2.5.0",
"appium-ios-simulator": "^6.0.0",
"async-lock": "^1.0.0",
Expand All @@ -90,7 +85,7 @@
"bluebird": "^3.5.5",
"lodash": "^4.17.11",
"source-map-support": "^0.x",
"teen_process": "^2.0.0"
"teen_process": "^2.2.0"
},
"files": [
"index.ts",
Expand Down
15 changes: 8 additions & 7 deletions test/functional/webdriveragent-e2e-specs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import Simctl from 'node-simctl';
import { getVersion } from 'appium-xcode';
import { getSimulator } from 'appium-ios-simulator';
Expand All @@ -15,10 +13,6 @@ const MOCHA_TIMEOUT_MS = 60 * 1000 * 4;
const SIM_DEVICE_NAME = 'webDriverAgentTest';
const SIM_STARTUP_TIMEOUT_MS = MOCHA_TIMEOUT_MS;


chai.should();
chai.use(chaiAsPromised);

let testUrl = 'http://localhost:8100/tree';

function getStartOpts (device) {
Expand All @@ -36,9 +30,16 @@ function getStartOpts (device) {

describe('WebDriverAgent', function () {
this.timeout(MOCHA_TIMEOUT_MS);

let chai;
let xcodeVersion;

before(async function () {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');

chai.should();
chai.use(chaiAsPromised.default);

// Don't do these tests on Sauce Labs
if (process.env.CLOUD) {
this.skip();
Expand Down
15 changes: 10 additions & 5 deletions test/unit/utils-specs.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
import { getXctestrunFilePath, getAdditionalRunContent, getXctestrunFileName } from '../../lib/utils';
import { PLATFORM_NAME_IOS, PLATFORM_NAME_TVOS } from '../../lib/constants';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { withMocks } from '@appium/test-support';
import { fs } from '@appium/support';
import path from 'path';
import { fail } from 'assert';
import { arch } from 'os';

chai.should();
chai.use(chaiAsPromised);

function get_arch() {
return arch() === 'arm64' ? 'arm64' : 'x86_64';
}

describe('utils', function () {
let chai;

before(async function() {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');

chai.should();
chai.use(chaiAsPromised.default);
});

describe('#getXctestrunFilePath', withMocks({fs}, function (mocks) {
const platformVersion = '12.0';
const sdkVersion = '12.2';
Expand Down
16 changes: 10 additions & 6 deletions test/unit/webdriveragent-specs.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { BOOTSTRAP_PATH } from '../../lib/utils';
import { WebDriverAgent } from '../../lib/webdriveragent';
import * as utils from '../../lib/utils';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import path from 'path';
import _ from 'lodash';
import sinon from 'sinon';


chai.should();
chai.use(chaiAsPromised);

const fakeConstructorArgs = {
device: 'some sim',
platformVersion: '9',
Expand All @@ -25,6 +19,16 @@ const customAgentPath = '/path/to/some/agent/WebDriverAgent.xcodeproj';
const customDerivedDataPath = '/path/to/some/agent/DerivedData/';

describe('Constructor', function () {
let chai;

before(async function() {
chai = await import('chai');
const chaiAsPromised = await import('chai-as-promised');

chai.should();
chai.use(chaiAsPromised.default);
});

it('should have a default wda agent if not specified', function () {
let agent = new WebDriverAgent({}, fakeConstructorArgs);
agent.bootstrapPath.should.eql(BOOTSTRAP_PATH);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"extends": "@appium/tsconfig/tsconfig.json",
"compilerOptions": {
"strict": false, // TODO: make this flag true
"esModuleInterop": true,
"outDir": "build",
"types": ["node"],
"checkJs": true
Expand Down

0 comments on commit 162733a

Please sign in to comment.