Skip to content

Commit

Permalink
feat: Added support for applications with multiple processes (#785)
Browse files Browse the repository at this point in the history
* feat: Added support for applications with multiple processes

* fix lint check
  • Loading branch information
tomaskatz96 authored Jan 8, 2025
1 parent 2869b26 commit ff18d96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/tools/adb-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ export async function getPIDsByName (name) {
if (this._isPgrepAvailable || this._isPidofAvailable) {
const shellCommand = this._isPgrepAvailable
? (this._canPgrepUseFullCmdLineSearch
? ['pgrep', '-f', _.escapeRegExp(`([[:blank:]]|^)${name}([[:blank:]]|$)`)]
? ['pgrep', '-f', _.escapeRegExp(`([[:blank:]]|^)${name}(:[a-zA-Z0-9_-]+)?([[:blank:]]|$)`)]
// https://github.com/appium/appium/issues/13872
: [`pgrep ^${_.escapeRegExp(name.slice(-MAX_PGREP_PATTERN_LEN))}$ ` +
`|| pgrep ^${_.escapeRegExp(name.slice(0, MAX_PGREP_PATTERN_LEN))}$`])
Expand Down
8 changes: 8 additions & 0 deletions test/unit/adb-commands-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,14 @@ describe('adb commands', withMocks({adb, logcat, teen_process, net}, function (m
.returns('5078\n5079\n');
(await adb.getPIDsByName(contactManagerPackage)).should.eql([5078, 5079]);
});
it('should call shell and parse pids with pgrep correctly with package with proccess', async function () {
adb._isPidofAvailable = false;
adb._isPgrepAvailable = true;
adb._canPgrepUseFullCmdLineSearch = true;
const escapedProcessName = _.escapeRegExp(`([[:blank:]]|^)${contactManagerPackage}(:[a-zA-Z0-9_-]+)?([[:blank:]]|$)`);
mocks.adb.expects('shell').once().withExactArgs(['pgrep', '-f', escapedProcessName]).returns('5080\n5081\n');
(await adb.getPIDsByName(contactManagerPackage)).should.eql([5080, 5081]);
});
it('should call shell and return an empty list if no processes are running', async function () {
adb._isPidofAvailable = true;
adb._isPgrepAvailable = false;
Expand Down

0 comments on commit ff18d96

Please sign in to comment.