-
Notifications
You must be signed in to change notification settings - Fork 3
/
conftest.py
104 lines (82 loc) · 3.21 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from selenium import webdriver
from utilities import ReadConfig
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pytest
import time
import os
@pytest.fixture(scope="function")
def setup_and_teardown(request):
# Read file inside of 'config.ini' from ReadConfig utlity
baseURL = ReadConfig.read_configuration("config file", "base_url")
browserType = ReadConfig.read_configuration("config file", "browser_type")
# Access Browserstack token key from environment variable
browserstack_token = os.getenv('browserstack_token')
# Initialize Webdriver
driver = None
if browserType == "chrome":
driver = uc.Chrome()
elif browserType == "firefox":
driver = webdriver.Firefox()
elif browserType == "edge":
driver = webdriver.Edge()
elif browserType == "safari":
safari_options = webdriver.SafariOptions()
capabilities = {
'browserName': 'Safari',
'browser_version': 'latest',
'os': 'macOS',
'os_version': 'Sonoma',
'name': 'Selenium Test'
}
# Create a remote WebDriver instance using BrowserStack
driver = webdriver.Remote(
command_executor=f'https://wickedman_tW4Iy0:{
browserstack_token}@hub-cloud.browserstack.com/wd/hub',
options=safari_options
)
else:
pytest.fail(f"Unsupported browser type: '{
browserType}'. Supported browsers are: 'chrome', 'firefox', 'edge'.")
# Maximize window and open the base URL
driver.maximize_window()
driver.get(baseURL)
# Wait for a specific element to be visible after the page loads
homepage_element = WebDriverWait(driver, 30).until(EC.visibility_of_element_located(
(By.XPATH, "//img[@src='/images/logo.jpg']")))
assert "nepsealpha" in driver.current_url
# Sharing WebDriver instance across all test methods in a class
request.cls.driver = driver
yield driver
driver.quit()
'''
# Enable this for cross browser testing
@pytest.fixture(params=['chrome', 'edge', 'firefox'])
def setup_and_teardown(request):
# Read file inside of 'config.ini' from ReadConfig utlity
baseURL = ReadConfig.read_configuration("config file", "base_url")
browserType = ReadConfig.read_configuration("config file", "browser_type")
# Initialize Webdriver
driver = None
if request.param == "chrome":
driver = uc.Chrome()
elif request.param == "edge":
driver = webdriver.Edge()
elif request.param == "firefox":
driver = webdriver.Firefox()
else:
pass
# Maximize window and open the base URL
driver.maximize_window()
driver.get(baseURL)
# Wait for a specific element to be visible after the page loads
homepage_element = WebDriverWait(driver, 30).until(EC.visibility_of_element_located(
(By.XPATH, "//img[@src='/images/logo.jpg']")))
assert "nepsealpha" in driver.current_url
# Sharing WebDriver instance across all test methods in a class
request.cls.driver = driver
yield driver
driver.quit()
'''