Skip to content
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

Accept splunk cloud agreement #409

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pytest_splunk_addon_ui_smartx/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import re
# requests.urllib3.disable_warnings()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.setLevel(logging.INFO)
PNG_PATH = "assets"

class SeleniumHelper(object):
Expand All @@ -38,11 +38,12 @@ class SeleniumHelper(object):
sauce_tunnel_parent=None
jenkins_build=None

def __init__(self, browser, browser_version, splunk_web_url, splunk_mgmt_url, debug=False, cred=("admin", "Chang3d!"), headless=False, test_case=None):
def __init__(self, browser, browser_version, splunk_web_url, splunk_mgmt_url, debug=False, cred=("admin", "Chang3d!"), headless=False, test_case=None, splunk_cloud_agreement=False):
self.splunk_web_url = splunk_web_url
self.splunk_mgmt_url = splunk_mgmt_url
self.cred = cred
self.test_case = test_case
self.splunk_cloud_agreement = splunk_cloud_agreement
if not debug:
# Using Saucelabs
self.init_sauce_env_variables()
Expand Down Expand Up @@ -266,7 +267,7 @@ def get_sauce_safari_opts(self, browser_version):
def login_to_splunk(self, *cred):
try:
login_page = LoginPage(self)
login_page.login.login(*cred)
login_page.login.login(*cred, splunk_cloud_agreement=self.splunk_cloud_agreement)
except:
self.browser.save_screenshot(os.path.join(PNG_PATH, "login_error.png"))
raise
Expand Down
15 changes: 13 additions & 2 deletions pytest_splunk_addon_ui_smartx/components/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .base_component import BaseComponent, Selector
from selenium.webdriver.common.by import By

SPLUNK_CLOUD_TOS = True
class Login(BaseComponent):
"""
Component: Login
Expand All @@ -22,16 +23,26 @@ def __init__(self, browser, container=Selector(select="form.loginForm")):
self.elements = {
"username": Selector(by=By.ID, select="username"),
"password": Selector(by=By.ID, select="password"),
"homepage": Selector(select='a[data-action="home"]')
"homepage": Selector(select='a[data-action="home"]'),
"accept_checkbox": Selector(by=By.ID, select="accept"),
"accept_button": Selector(select=" .accept-tos-button.btn.btn-primary")
}

def login(self, username, password):
def login(self, username, password, splunk_cloud_agreement):
"""
Login into the Splunk instance
:param username: Str the username for the splunk instance we want to access
:param password: Str the password for the splunk instance we want to access
"""
global SPLUNK_CLOUD_TOS
self.username.send_keys(username)
self.password.send_keys(password)
self.password.send_keys(u'\ue007')

if splunk_cloud_agreement and SPLUNK_CLOUD_TOS:
self.wait_to_be_clickable("accept_checkbox")
self.accept_checkbox.click()
self.wait_for("accept_button")
self.accept_button.click()
SPLUNK_CLOUD_TOS = False
self.wait_for("homepage", "Could not log in to the Splunk instance.")
35 changes: 32 additions & 3 deletions pytest_splunk_addon_ui_smartx/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ def pytest_addoption(parser):
help="Run the test case on headless mode"
)

SmartConfigs = namedtuple("SmartConfigs", ['driver', 'driver_version', 'local_run', 'retry_count', 'headless_run'])
group.addoption(
"--accept-splunk-cloud-agreement",
action="store_true",
help="Accept splunk cloud Terms of Service, when login for first time"
)

SmartConfigs = namedtuple("SmartConfigs", ['driver', 'driver_version', 'local_run', 'retry_count', 'headless_run', "splunk_cloud_agreement"])

@pytest.fixture(scope="session")
def ucc_smartx_configs(request):
Expand Down Expand Up @@ -131,10 +137,23 @@ def ucc_smartx_configs(request):
else:
headless_run = False

if request.config.getoption("--accept-splunk-cloud-agreement"):
splunk_cloud_agreement = True
LOGGER.debug("--splunk_cloud_agreement")
else:
splunk_cloud_agreement = False

LOGGER.info("Calling SeleniumHelper with:: browser={driver}, debug={local_run}, headless={headless_run})".format(
driver=driver, local_run=local_run, headless_run=headless_run
))
smartx_configs = SmartConfigs(driver=driver, driver_version=driver_version, local_run=local_run, retry_count=retry_count, headless_run=headless_run)
smartx_configs = SmartConfigs(
driver=driver,
driver_version=driver_version,
local_run=local_run,
retry_count=retry_count,
headless_run=headless_run,
splunk_cloud_agreement=splunk_cloud_agreement
)
return smartx_configs

def get_browser_scope(fixture_name, config):
Expand All @@ -154,7 +173,17 @@ def ucc_smartx_selenium_helper(request, ucc_smartx_configs, splunk, splunk_web_u
for try_number in range(ucc_smartx_configs.retry_count):
last_exc = Exception()
try:
selenium_helper = SeleniumHelper(ucc_smartx_configs.driver, ucc_smartx_configs.driver_version, splunk_web_uri, splunk_rest_uri, debug=ucc_smartx_configs.local_run, cred=(splunk["username"], splunk["password"]), headless=ucc_smartx_configs.headless_run, test_case=test_case)
selenium_helper = SeleniumHelper(
ucc_smartx_configs.driver,
ucc_smartx_configs.driver_version,
splunk_web_uri,
splunk_rest_uri,
debug=ucc_smartx_configs.local_run,
cred=(splunk["username"], splunk["password"]),
headless=ucc_smartx_configs.headless_run,
test_case=test_case,
splunk_cloud_agreement=ucc_smartx_configs.splunk_cloud_agreement
)
break
except Exception as e:
last_exc = e
Expand Down