-
Notifications
You must be signed in to change notification settings - Fork 572
test: add bidi example in test #1154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
796de94
test: add bidi log example test
KazuCocoa 137b5e9
add ci
KazuCocoa c22051c
add ubsubscribe
KazuCocoa d572c59
run it first
KazuCocoa c775d82
remove redundant log
KazuCocoa 0492926
run at the end
KazuCocoa 8836561
add comment
KazuCocoa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,81 @@ | ||
#!/usr/bin/env python | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from selenium.webdriver.common.bidi.common import command_builder | ||
|
||
from appium import webdriver | ||
from appium.options.common import AppiumOptions | ||
from appium.webdriver.client_config import AppiumClientConfig | ||
from test.helpers.constants import SERVER_URL_BASE | ||
|
||
from .helper.desired_capabilities import get_desired_capabilities | ||
|
||
|
||
class AppiumLogEntry: | ||
event_class = 'log.entryAdded' | ||
|
||
def __init__(self, level, text, timestamp, source, type): | ||
self.level = level | ||
self.text = text | ||
self.timestamp = timestamp | ||
self.source = source | ||
self.type = type | ||
|
||
@property | ||
def json(self): | ||
return dict(type=self.type, level=self.level, text=self.text, timestamp=self.timestamp, source=self.source) | ||
|
||
@classmethod | ||
def from_json(cls, json: dict): | ||
return cls( | ||
level=json['level'], | ||
text=json['text'], | ||
timestamp=json['timestamp'], | ||
source=json['source'], | ||
type=json['type'], | ||
) | ||
|
||
|
||
class TestChromeWithBiDi: | ||
"""This test requires selenium python client which supports 'command_builder'""" | ||
|
||
def setup_method(self) -> None: | ||
client_config = AppiumClientConfig(remote_server_addr=SERVER_URL_BASE) | ||
client_config.timeout = 600 | ||
caps = get_desired_capabilities() | ||
caps['webSocketUrl'] = True | ||
self.driver = webdriver.Remote( | ||
SERVER_URL_BASE, options=AppiumOptions().load_capabilities(caps), client_config=client_config | ||
) | ||
|
||
def teardown_method(self) -> None: | ||
self.driver.quit() | ||
|
||
def test_bidi_log(self) -> None: | ||
log_entries = [] | ||
bidi_log_param = {'events': ['log.entryAdded'], 'contexts': ['NATIVE_APP']} | ||
|
||
self.driver.script.conn.execute(command_builder('session.subscribe', bidi_log_param)) | ||
|
||
def _log(entry: AppiumLogEntry): | ||
# e.g. {'type': 'syslog', 'level': 'info', 'source': {'realm': ''}, 'text': '08-05 13:30:32.617 29677 29709 I appium : channel read: GET /session/d7c38859-8930-4eb0-960a-8f917c9e6a38/source', 'timestamp': 1754368241565} | ||
log_entries.append(entry.json) | ||
|
||
try: | ||
callback_id = self.driver.script.conn.add_callback(AppiumLogEntry, _log) | ||
self.driver.page_source | ||
assert len(log_entries) != 0 | ||
self.driver.script.conn.remove_callback(AppiumLogEntry, callback_id) | ||
finally: | ||
self.driver.script.conn.execute(command_builder('session.unsubscribe', bidi_log_param)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is example implementation for testing purpose