def test_url_changes_with_gw_selection(): """URL query param should change when gateway selection changes.""" splinter_tests.visit("/#/xbee_network") assert browser.is_text_present("XBee Network View") # Since this user has more than one gateway, it shouldn't auto-select one. gw_select = browser.find_by_css('select#gateway') assert not gw_select.is_empty() # Check that the select box is present assert_that(gw_select.first.value, is_("?")) # Pick the first gateway browser.select("gateway", "0") do_sleep() user = get_e2e_user("e2e_user") assert user is not None # Selected gateway should be first in order of devConnectwareId devices = user.devices['items'] devices = sorted(devices, key=lambda d: d['devConnectwareId']) devid = devices[0]['devConnectwareId'] assert_that(browser.url, ends_with("/xbee_network?gateway=" + devid)) # Select the second gateway browser.select("gateway", "1") devid = devices[1]['devConnectwareId'] assert_that(browser.url, ends_with("/xbee_network?gateway=" + devid))
def test_delete_works_and_moves_user_to_setup(): """'Delete dashboard' button works and redirects user to setup page.""" splinter_tests.visit("#/advanced") do_sleep() button = find_delete_button() assert not button.first['disabled'] # Click the delete button button.click() # Wait a moment while the deletion happens do_sleep() # Are we at the setup page now? assert_that(browser.url, ends_with("#/setup")) # If we go back to Advanced Options, is the button disabled? splinter_tests.visit("#/advanced") do_sleep() button = find_delete_button() assert button.first['disabled']
def do_logout(): splinter_tests.visit("/logout") splinter_tests.visit("/#/login") browser = splinter_tests.browser # Wait up to 15 seconds for the page to load assert browser.is_element_present_by_css("h1.title", wait_time=15)
def log_in_clean(username, password, fqdn=""): browser = splinter_tests.browser # Sign out. splinter_tests.visit("/logout") # Navigate to login page, targeting FQDN if provided if fqdn: fqdn = "/{}".format(fqdn) splinter_tests.visit("/#/login" + fqdn) do_sleep() # Check that no error div is present with screenshot_on_exception("log_in_clean"): # Wait up to 15 seconds for the page to load up (detected by seeing the # 'Log in' text header_xpath = '//h1[contains(@class, "title") and contains(., "Log in")]' assert browser.is_element_present_by_xpath(header_xpath, wait_time=15) # Log in with the given credentials browser.fill("username", username) browser.fill("password", password) browser.find_by_css('.btn.login-button').click() # Wait for a moment do_sleep() # Check that the login was successful assert not browser.is_text_present("Username or password was incorrect.")
def test_initial_gw_selection_depends_on_query_param(): """If gateway param is given, that gateway is selected automatically.""" user = get_e2e_user("e2e_user") assert user is not None # Extract the first device's ID devices = user.devices['items'] devices = sorted(devices, key=lambda d: d['devConnectwareId']) devid = devices[0]['devConnectwareId'] splinter_tests.visit("/#/xbee_network?gateway=" + devid) do_sleep() assert browser.is_text_present("XBee Network View") gw_select = browser.find_by_css("select#gateway") assert not gw_select.is_empty() # Check that the first gateway is selected assert_that(gw_select.first.value, is_("0")) # 'Fetch from' select box should be visible now assert browser.is_text_present("Fetch from:") # 'Device Cloud' is automatically selected fetch_from = browser.find_by_css('select#fetch_from') assert not fetch_from.is_empty() assert_that(fetch_from.first.value, is_("dc"))
def do_check_device_list(test_user): # Do a fresh login log_in_clean(*test_user.auth) # Navigate to the Devices page splinter_tests.visit("/#/devices") do_sleep(multiplier=0.5) assert_that(browser.title, starts_with("XBee Gateways in your account")) # Make sure we didn't get redirected away or anything assert_that(browser.url, ends_with("#/devices")) # Check the contents of the page assert browser.is_text_present("XBee Gateways in your account") assert not browser.find_link_by_text("Manage Devices").is_empty() # Allow the device list fetch to complete. (Should be wicked fast on # integration test backend.) do_sleep(multiplier=0.5) def check_devices(): for device in test_user.devices['items']: assert browser.is_text_present(device['devConnectwareId']) if device.get('dpDescription'): assert browser.is_text_present(device['dpDescription']) # Check the connection status indicator is correct. conn_status = device.get('dpConnectionStatus', "0") conn_image = "device_disconnected.png" try: if int(conn_status): conn_image = "device_connected.png" except (ValueError, TypeError): pass # Find the image. This XPath ensures that the connection status # image is in the cell immediately before the device ID. xpath = '//td[.="{}"]/preceding-sibling::td[1]/img' xpath = xpath.format(device['devConnectwareId']) img = browser.find_by_xpath(xpath) assert not img.is_empty() assert_that(len(img), is_(1)) assert_that(img.first['src'], ends_with(conn_image)) # Check the device list right now check_devices() # Refresh the list, check it again. ref_button = browser.find_by_xpath('//button[contains(., "Refresh List")]') assert not ref_button.is_empty() ref_button.click() # Wait for list to load do_sleep() # Check the list again check_devices()
def test_delete_disabled_without_dashboards(): """Without a dashboard, Advanced Options does not enable the delete button.""" splinter_tests.visit("#/advanced") do_sleep() button = find_delete_button() assert button.first['disabled'] assert_that(button.first.text, is_("No dashboards in your account"))
def test_delete_enabled_with_dashboard(): """With a dashboard, Advanced Options enables the delete button.""" splinter_tests.visit("#/advanced") do_sleep() button = find_delete_button() assert not button.first['disabled'] assert_that(button.first.text, is_("Delete dashboard"))
def fn(): # Attempt to go to the given page splinter_tests.visit(visited_uri) # Sleep the test runner for a moment, to allow the browser to catch up. splinter_tests.utils.do_sleep() # Check that we ended up on the login page assert_that(splinter_tests.browser.url, ends_with("/#/login"))
def setup(): splinter_tests.start_browser() # First, logout to ensure that we are in fact logged out. splinter_tests.visit("/logout") # Wait a few seconds for redirect. splinter_tests.utils.do_sleep() assert_that(splinter_tests.browser.url, ends_with("/#/login"))
def re_login_tst_user(): # tst, not test, so nose ignores this. splinter_tests.visit("/logout") splinter_tests.visit("/#/login") assert not browser.find_by_id("login_error").visible browser.fill("username", "test_user") browser.fill("password", "e2e_password") browser.find_by_css('.btn.login-button').click() do_sleep() assert not browser.is_text_present("Username or password was incorrect.") assert_that(browser.url, ends_with("#/setup"))
def log_in(*auth): delete_all_dashboards(*auth) add_empty_dashboard(*auth) log_in_clean(*auth) splinter_tests.visit("/#/add_widget") # Wait a moment for everything to settle do_sleep() with screenshot_on_exception("log_in_not_add_widget"): assert_that(browser.url, ends_with('/#/add_widget'))
def make_dashboard(): # Create a blank dashboard. req = requests.post(splinter_tests.SERVER_URL + '/api/dashboards', data='{"widgets": []}', headers={'content-type': 'application/json'}, auth=('test_user#login.etherios.com', 'e2e_password')) req.raise_for_status() # Pause for a moment. do_sleep(multiplier=0.5) # Navigate to the dashboard page splinter_tests.visit("#/dashboard")
def login_account_one_device(): splinter_tests.visit("/logout") splinter_tests.visit("/#/login") assert not browser.find_by_id("login_error").visible browser.fill("username", "e2e_user_1device") browser.fill("password", "e2e_password") browser.find_by_css('.btn.login-button').click() # Wait for a moment do_sleep() assert not browser.is_text_present("Username or password was incorrect.")
def test_select_only_gateway(): """If account has only one gateway, it is selected automatically.""" splinter_tests.visit("/#/xbee_network") do_sleep() user = get_e2e_user("e2e_user_1device") assert user is not None # Extract the first device's ID devices = user.devices['items'] devices = sorted(devices, key=lambda d: d['devConnectwareId']) devid = devices[0]['devConnectwareId'] gw_select = browser.find_by_css('select#gateway') assert not gw_select.is_empty() assert_that(gw_select.first.value, is_("0")) assert_that(browser.url, ends_with("/xbee_network?gateway=" + devid))
def re_login_no_devices(): splinter_tests.visit("/logout") splinter_tests.visit("/#/login") do_sleep() with screenshot_on_exception("re_login_no_devices"): assert not browser.find_by_id("login_error").visible browser.fill("username", "e2e_user_nodevices") browser.fill("password", "e2e_password") browser.find_by_css('.btn.login-button').click() # Wait for a moment do_sleep() assert not browser.is_text_present(BAD_CREDS_TEXT) assert_that(browser.url, ends_with("#/setup"))
def test_linked_to_from_devices_page(): """Devices page should deep-link to XBee Network page.""" user = get_e2e_user("test_user") assert user is not None # Extract the first device's ID devices = user.devices['items'] devices = sorted(devices, key=lambda d: d['devConnectwareId']) devid = devices[0]['devConnectwareId'] splinter_tests.visit("/#/devices") do_sleep() xpath = '//td[.="{}"]/..//a[.="View"]'.format(devid) view_btn = browser.find_by_xpath(xpath) assert not view_btn.is_empty() assert_that(view_btn.first['href'], ends_with("/xbee_network?gateway=" + devid))
def test_xbees_show_up(): """XBees (but not coordinators) should be listed in the table correctly.""" user = get_e2e_user("test_user") assert user is not None # Extract the first device's ID devices = user.devices['items'] devices = sorted(devices, key=lambda d: d['devConnectwareId']) devid = devices[0]['devConnectwareId'] splinter_tests.visit("/#/xbee_network?gateway=" + devid) do_sleep() xbees = user.xbees['items'] for xbee in xbees: if str(xbee.get('xpNetAddr')) != "0": assert browser.is_text_present(xbee['xpExtAddr']) assert browser.is_text_present(xbee['xpNodeId'])
def test_login_good_credentials(): """ When the user enters correct credentials, they go to Dashboard Creation. """ # First, delete all the user's dashboards. utils.delete_all_dashboards('e2e_user', 'e2e_password', 'e2e_fqdn') browser = splinter_tests.browser # Need to first set the login page to use 'e2e_fqdn' as server URL splinter_tests.visit("#/login/e2e_fqdn") # Check that no error is on screen yet. assert browser.find_by_id("login_error").has_class("hide") browser.fill('username', 'e2e_user') browser.fill('password', 'e2e_password') browser.find_by_css('.btn.login-button').click() assert not browser.is_text_present("Username or password was incorrect.") assert_that(browser.url, ends_with("#/setup")) # Log out. To do this, we must click on the username in the top right, then # "Log out". Splinter seems to have trouble finding the link by text, so we # will have to find it by CSS... dropdown_css = ".nav.navbar-right > li.dropdown > a.dropdown-toggle" dropdown = browser.find_by_css(dropdown_css) assert not dropdown.is_empty() # Make sure we found it dropdown.click() browser.find_link_by_text("Log out").click() assert_that(browser.url, ends_with("#/login"))
def test_page_no_xbees(): """Node table should remain empty if no XBees are found.""" splinter_tests.visit("/#/xbee_network") assert browser.is_text_present("XBee Network View") # Since this user has more than one gateway, it shouldn't auto-select one. gw_select = browser.find_by_css('select#gateway') assert not gw_select.is_empty() # Check that the select box is present assert_that(gw_select.first.value, is_("?")) # Pick the first gateway browser.select("gateway", "0") do_sleep() # 'Fetch from' select box should be visible now assert browser.is_text_present("Fetch from:") # 'Device Cloud' is automatically selected fetch_from = browser.find_by_css('select#fetch_from') assert not fetch_from.is_empty() assert_that(fetch_from.first.value, is_("dc")) # Nodes table should be empty assert browser.find_by_css('table.network-table tbody tr').is_empty()