-
-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add a BiDi event upon context change (#967)
- Loading branch information
1 parent
4e9ab89
commit 26fc1bc
Showing
8 changed files
with
91 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const BIDI_EVENT_NAME = 'bidiEvent'; | ||
export const CONTEXT_UPDATED_EVENT = 'appium.contextUpdated'; | ||
export const LOG_ENTRY_ADDED_EVENT = 'log.entryAdded'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { LogEntryAddedEvent, ContextUpdatedEvent } from './types'; | ||
import { NATIVE_WIN } from '../context/helpers'; | ||
import { CONTEXT_UPDATED_EVENT, LOG_ENTRY_ADDED_EVENT } from './constants'; | ||
import type { LogcatRecord as LogEntry } from 'appium-adb'; | ||
|
||
export function makeContextUpdatedEvent(contextName: string): ContextUpdatedEvent { | ||
return { | ||
method: CONTEXT_UPDATED_EVENT, | ||
params: { | ||
name: contextName, | ||
type: contextName === NATIVE_WIN ? 'NATIVE' : 'WEB', | ||
}, | ||
}; | ||
} | ||
|
||
export function makeLogEntryAddedEvent(entry: LogEntry, context: string, type: string): LogEntryAddedEvent { | ||
return { | ||
context, | ||
method: LOG_ENTRY_ADDED_EVENT, | ||
params: { | ||
type, | ||
level: entry.level, | ||
source: { | ||
realm: '', | ||
}, | ||
text: entry.message, | ||
timestamp: entry.timestamp, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
interface BiDiEvent<TParams> { | ||
method: string; | ||
params: TParams; | ||
}; | ||
|
||
interface LogEntrySource { | ||
realm: string; | ||
} | ||
|
||
interface LogEntryAddedEventParams { | ||
type: string; | ||
level: string; | ||
source: LogEntrySource; | ||
text: string; | ||
timestamp: number; | ||
} | ||
|
||
// https://w3c.github.io/webdriver-bidi/#event-log-entryAdded | ||
export interface LogEntryAddedEvent extends BiDiEvent<LogEntryAddedEventParams> { | ||
context: string; | ||
} | ||
|
||
interface ContentUpdatedParams { | ||
name: string; | ||
type: 'NATIVE' | 'WEB'; | ||
} | ||
|
||
// https://github.com/appium/appium/issues/20741 | ||
export interface ContextUpdatedEvent extends BiDiEvent<ContentUpdatedParams> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters