Skip to content

Commit 38028e1

Browse files
committed
[py] Add tests for chrome and edge
1 parent 83609f3 commit 38028e1

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

py/test/selenium/webdriver/chrome/chrome_service_tests.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
1718
import os
1819
import subprocess
1920
import time
2021
from unittest.mock import patch
2122

2223
import pytest
2324

25+
from selenium.common.exceptions import SessionNotCreatedException
26+
from selenium.webdriver.chrome.options import Options
2427
from selenium.webdriver.chrome.service import Service
2528

2629

@@ -105,6 +108,21 @@ def test_log_output_null_default(driver, capfd) -> None:
105108
driver.quit()
106109

107110

111+
@pytest.mark.no_driver_after_test
112+
def test_driver_is_stopped_if_browser_cant_start(clean_driver, driver_executable) -> None:
113+
options = Options()
114+
options.add_argument("--user-data-dir=/no/such/location")
115+
service = Service()
116+
with pytest.raises(SessionNotCreatedException):
117+
driver = clean_driver(options=options, service=service)
118+
assert not service.is_connectable()
119+
assert service.process.poll() < 0
120+
try:
121+
driver.quit()
122+
except Exception:
123+
pass
124+
125+
108126
@pytest.fixture
109127
def service():
110128
return Service()

py/test/selenium/webdriver/edge/edge_service_tests.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
1718
import os
1819
import subprocess
1920
import time
2021
from unittest.mock import patch
2122

2223
import pytest
2324

25+
from selenium.common.exceptions import SessionNotCreatedException
26+
from selenium.webdriver.edge.options import Options
2427
from selenium.webdriver.edge.service import Service
2528

2629

@@ -105,6 +108,21 @@ def test_log_output_null_default(driver, capfd) -> None:
105108
driver.quit()
106109

107110

111+
@pytest.mark.no_driver_after_test
112+
def test_driver_is_stopped_if_browser_cant_start(clean_driver, driver_executable) -> None:
113+
options = Options()
114+
options.add_argument("--user-data-dir=/no/such/location")
115+
service = Service()
116+
with pytest.raises(SessionNotCreatedException):
117+
driver = clean_driver(options=options, service=service)
118+
assert not service.is_connectable()
119+
assert service.process.poll() < 0
120+
try:
121+
driver.quit()
122+
except Exception:
123+
pass
124+
125+
108126
@pytest.fixture
109127
def service():
110128
return Service()

0 commit comments

Comments
 (0)