Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/py/test/selenium/webdriver/remote/remote_session_event_tests.py
3992 views
1
# Licensed to the Software Freedom Conservancy (SFC) under one
2
# or more contributor license agreements. See the NOTICE file
3
# distributed with this work for additional information
4
# regarding copyright ownership. The SFC licenses this file
5
# to you under the Apache License, Version 2.0 (the
6
# "License"); you may not use this file except in compliance
7
# with the License. You may obtain a copy of the License at
8
#
9
# http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing,
12
# software distributed under the License is distributed on an
13
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
# KIND, either express or implied. See the License for the
15
# specific language governing permissions and limitations
16
# under the License.
17
18
"""
19
Integration tests for session events fired through Selenium Grid.
20
21
These tests require a running Selenium Grid instance. They verify that
22
custom session events can be fired from client code and received by
23
services listening on the remote server event bus.
24
"""
25
26
27
def test_fire_session_event_with_payload(driver, pages):
28
"""Test firing a session event with payload data through Grid."""
29
pages.load("simpleTest.html")
30
31
payload = {"testName": "LoginTest", "error": "Element not found", "screenshot": True}
32
result = driver.fire_session_event("test:failed", payload)
33
34
assert result["success"] is True
35
assert result["eventType"] == "test:failed"
36
assert "timestamp" in result
37
38
39
def test_fire_session_event_without_payload(driver, pages):
40
"""Test firing a session event without payload through Grid."""
41
pages.load("simpleTest.html")
42
43
result = driver.fire_session_event("log:collect")
44
45
assert result["success"] is True
46
assert result["eventType"] == "log:collect"
47
assert "timestamp" in result
48
49
50
def test_fire_session_event_with_empty_payload(driver, pages):
51
"""Test firing a session event with empty payload through Grid."""
52
pages.load("simpleTest.html")
53
54
result = driver.fire_session_event("marker:add", {})
55
56
assert result["success"] is True
57
assert result["eventType"] == "marker:add"
58
59
60
def test_fire_multiple_session_events(driver, pages):
61
"""Test firing multiple session events in sequence."""
62
pages.load("simpleTest.html")
63
64
# Simulate test lifecycle events
65
result1 = driver.fire_session_event("test:started", {"testName": "NavigationTest"})
66
assert result1["success"] is True
67
assert result1["eventType"] == "test:started"
68
69
result2 = driver.fire_session_event("test:step", {"stepName": "Navigate to page", "status": "passed"})
70
assert result2["success"] is True
71
assert result2["eventType"] == "test:step"
72
73
result3 = driver.fire_session_event("test:passed", {"testName": "NavigationTest", "duration": 1500})
74
assert result3["success"] is True
75
assert result3["eventType"] == "test:passed"
76
77
78
def test_fire_session_event_with_complex_payload(driver, pages):
79
"""Test firing a session event with nested payload data."""
80
pages.load("simpleTest.html")
81
82
payload = {
83
"testName": "ComplexTest",
84
"metadata": {"suite": "regression", "priority": "high", "tags": ["smoke", "critical"]},
85
"timing": {"started": "2024-01-15T10:00:00Z", "ended": "2024-01-15T10:05:00Z"},
86
"retryCount": 0,
87
}
88
result = driver.fire_session_event("test:completed", payload)
89
90
assert result["success"] is True
91
assert result["eventType"] == "test:completed"
92
93