Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8774c23
Add some routines for the tests and simplify tests
martinRenou Jun 7, 2017
07404c1
Add some ids to simplify code and create select_application routine
martinRenou Jun 7, 2017
e8eb562
Add routines for start/stop application and add one test
martinRenou Jun 7, 2017
56340a3
Add routines for waiting app running/stopped
martinRenou Jun 7, 2017
f07210d
Add tests for user creation
martinRenou Jun 7, 2017
406813c
Renamed functions and add a test
martinRenou Jun 7, 2017
e46976b
Remove failing test in travis because there is only one app
martinRenou Jun 7, 2017
792fc64
Create user driver and admin driver
martinRenou Jun 7, 2017
b4c69b0
Add remove/policy user methods
martinRenou Jun 7, 2017
5822529
Reduce routines verbosity
martinRenou Jun 7, 2017
9d8f849
Rename routine
martinRenou Jun 7, 2017
85e70b3
Rename routine
martinRenou Jun 7, 2017
5989f89
Remove ids for modal dialogs
martinRenou Jun 8, 2017
f0a11f6
Rename click routine
martinRenou Jun 8, 2017
36bc291
Add a routine for clicking a button by innertext
martinRenou Jun 8, 2017
47a26f1
Clear routine names
martinRenou Jun 8, 2017
a4baa9d
Remove ids for datatable actions
martinRenou Jun 8, 2017
8d36f49
Merge branch 'master' into clear-selenium-tests
martinRenou Jun 8, 2017
88e8af8
Undo change and remove trailing ids
martinRenou Jun 8, 2017
2ba3950
Undo error of change
martinRenou Jun 8, 2017
83b1365
Clear code by removing unused expected condition
martinRenou Jun 8, 2017
9883049
Reviews about logged_in context manager
martinRenou Jun 8, 2017
714a704
Merge branch 'master' into clear-selenium-tests
martinRenou Jun 9, 2017
836f094
Rename click routines
martinRenou Jun 9, 2017
79f15e1
Move basic modal routines in RemoteAppDriver
martinRenou Jun 9, 2017
41130ae
Refactor modal click button functions
martinRenou Jun 9, 2017
dc2efef
Rename row action routine
martinRenou Jun 9, 2017
d4a5ccc
Add docstring
martinRenou Jun 9, 2017
189e40b
Add docstring
martinRenou Jun 9, 2017
27da0b0
Add docstring
martinRenou Jun 9, 2017
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
2 changes: 1 addition & 1 deletion frontend/user/vue-components/ApplicationLabel.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<ul v-if="currentApp !== null" class="nav navbar-nav">
<li class="dropdown notifications-menu">
<li id="application-settings" class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle cust-padding" data-toggle="dropdown" aria-expanded="false">
<img class="app-icon"
:src="currentApp.appData.image.icon_128 | iconSrc">
Expand Down
3 changes: 2 additions & 1 deletion frontend/user/vue-components/ApplicationListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<section class="sidebar">
<!-- Search form -->
<form action="#" class="sidebar-form">
<input type="text" name="q" class="form-control" placeholder="Search..." v-model="searchInput">
<input id="search-input" type="text" name="q" class="form-control" placeholder="Search..." v-model="searchInput">
</form>

<!-- Sidebar Menu -->
Expand All @@ -28,6 +28,7 @@
<transition-group name="list" tag="ul" id="applistentries" class="sidebar-menu">
<li v-for="app in visibleList" v-bind:key="app"
:class="{ active: indexOf(app) === model.selectedIndex }"
:id="'application-entry-' + indexOf(app)"
@click="model.selectedIndex = indexOf(app); $emit('entryClicked');">

<span :class="app.status.toLowerCase() + '-badge'"></span>
Expand Down
2 changes: 1 addition & 1 deletion frontend/user/vue-components/ApplicationView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<!-- Start Button -->
<div class="box-footer">
<button class="btn btn-primary pull-right start-button"
<button id="start-button" class="btn btn-primary pull-right start-button"
@click="startApplication()"
:disabled="!currentApp.isStopped()">
{{ {STOPPED: 'Start', STARTING: 'Starting', STOPPING: 'Stopping'}[currentApp.status] }}
Expand Down
2 changes: 1 addition & 1 deletion remoteappmanager/templates/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<!-- User Account Menu -->
<li class="dropdown user user-menu">
<li id="user-menu" class="dropdown user user-menu">
<!-- Menu Toggle Button -->
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<!-- The user image in the navbar-->
Expand Down
39 changes: 39 additions & 0 deletions selenium_tests/AdminDriverTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
from selenium_tests.RemoteAppDriverTest import RemoteAppDriverTest
from selenium.webdriver.common.by import By


class AdminDriverTest(RemoteAppDriverTest):
def setUp(self):
RemoteAppDriverTest.setUp(self)
self.login("admin")

def click_row_action_button(self, row, action_name):
""" Click on an action button in the datatable for a specific row
Parameters
----------
row: String
A string which permit to locate the row, it can be:
- the index of the row ("2")
- a user name ("JohnDoe")
- an application name ("File Manager")
- a container id ("3514azd65a4z4dazd131")
action_name: string
The name of the action

Example
-------
click_row_action_button("JohnDoe", "Remove")
click_row_action_button("JohnDoe", "Policies")
click_row_action_button("Mayavi", "Stop")
"""
self.click_first_element_located(
By.XPATH,
"//tr[td[text()='{}']]/td/button[text()='{}']".format(
row, action_name
)
)

def tearDown(self):
self.logout()
RemoteAppDriverTest.tearDown(self)
288 changes: 288 additions & 0 deletions selenium_tests/RemoteAppDriverTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
# -*- coding: utf-8 -*-
import time
import os
import contextlib
import sqlite3
import selenium.webdriver.support.expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.common.action_chains import ActionChains
import unittest


class RemoteAppDriverTest(unittest.TestCase):
def setUp(self):
ff_binary = webdriver.firefox.firefox_binary.FirefoxBinary()
ff_profile = webdriver.firefox.firefox_profile.FirefoxProfile()
ff_profile.assume_untrusted_cert_issuer = True
ff_profile.accept_untrusted_certs = True
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities['acceptSslCerts'] = True
self.driver = webdriver.Firefox(firefox_binary=ff_binary,
firefox_profile=ff_profile,
capabilities=capabilities,
timeout=60)
self.driver.implicitly_wait(30)
self.wait = WebDriverWait(self.driver, 30)
self.base_url = "https://127.0.0.1:8000/"
self.verificationErrors = []
self.accept_next_alert = True

permissions_db_path = os.path.join(ff_profile.profile_dir,
"permissions.sqlite")

with contextlib.closing(sqlite3.connect(permissions_db_path)) as db:
cur = db.cursor()
cur.execute(
("INSERT INTO moz_perms VALUES (1, '{base_url}', "
"'popup', 1, 0, 0, 1474977124357)").format(
base_url=self.base_url))
db.commit()

def wait_until_presence_of_element_located(self, how, what):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these need docs.

""" Wait until a located element is present
Parameters
----------
how: String
How you want to locate the element. See selenium.webdriver.common.by
what: String
What you want to locate.

Returns:
--------
element:
The element founded

Example:
--------
start_button = wait_until_presence_of_element_located(
By.ID, "start-button")
iframe = wait_until_presence_of_element_located(By.TAG_NAME, "iframe")
"""
return self.wait.until(EC.presence_of_element_located((how, what)))

def wait_until_text_inside_element_located(self, how, what, text):
""" Wait until a located element contains some text
Parameters
----------
how: String
How you want to locate the element. See selenium.webdriver.common.by
what: String
What you want to locate.
text: String
The text which must be contained by the located element

Returns:
--------
element:
The element founded

Example:
--------
conclusion_title = wait_until_text_inside_element_located(
By.TAG_NAME, "h3", "Conclusion")
"""
return self.wait.until(EC.text_to_be_present_in_element((how, what), text))

def wait_until_visibility_of_element_located(self, how, what):
""" Wait until a located element is visible, which means that it's rendered and
the CSS display style is not "none".
Parameters
----------
how: String
How you want to locate the element. See selenium.webdriver.common.by
what: String
What you want to locate.

Returns:
--------
element:
The element founded

Example:
--------
button = wait_until_visibility_of_element_located(By.TAG_NAME, "button")
"""
return self.wait.until(EC.visibility_of_element_located((how, what)))

def wait_until_visibility_of(self, element):
""" Wait until an element is visible, which means that it's rendered and
the CSS display style is not "none".
Parameters
----------
element: WebElement
The web element which is supposed to be visible

Returns:
--------
element:
The element

Example:
--------
wait_until_visibility_of(my_button)
"""
return self.wait.until(EC.visibility_of(element))

def wait_until_invisibility_of_element_located(self, how, what):
""" Wait until an element is invisible, which means that it's not rendered or
the CSS display style is "none".
Parameters
----------
how: String
How you want to locate the element. See selenium.webdriver.common.by
what: String
What you want to locate.

Returns:
--------
element:
The element founded

Example:
--------
button = wait_until_invisibility_of_element_located(By.TAG_NAME, "button")
"""
return self.wait.until(EC.invisibility_of_element_located((how, what)))

def wait_until_clickability_of_element_located(self, how, what):
""" Wait until an element is clickable, which means that it's visible,
enabled and nothing is above this element.
Parameters
----------
how: String
How you want to locate the element. See selenium.webdriver.common.by
what: String
What you want to locate.

Returns:
--------
element:
The element founded

Example:
--------
button = wait_until_clickability_of_element_located(By.TAG_NAME, "button")
button.click()
"""
return self.wait.until(EC.element_to_be_clickable((how, what)))

def click_first_element_located(self, how, what):
""" Wait until an element is clickable and click it
Parameters
----------
how: String
How you want to locate the element. See selenium.webdriver.common.by
what: String
What you want to locate.

Example:
--------
click_first_element_located(By.TAG_NAME, "button")
"""
element = self.wait_until_clickability_of_element_located(how, what)
element.click()

def click_first_button(self, name):
""" Click the first founded button containing a given name. If the button
is not clickable, it will wait until it is and then click it.
Parameters
----------
name: String
The name of the button you want to click

Example:
--------
click_first_button("Ok")
click_first_button("Remove")
"""
self.click_first_element_located(
By.XPATH, "//button[text()='{}']".format(name)
)

def type_text_in_element_located(self, how, what, text):
""" Type text into an located element.
Parameters
----------
how: String
How you want to locate the element. See selenium.webdriver.common.by
what: String
What you want to locate.
text: String
The text that you want to type in the element

Example:
--------
type_text_in_element_located(By.TAG_NAME, "input", "Hello World!")
"""
element = self.wait_until_clickability_of_element_located(how, what)
element.clear()
element.send_keys(text)

def wait_until_modal_closed(self):
""" Wait until the modal dialog is closed. We assume here that only
one modal dialog/alert dialog can be opened at the same time.
Returns
-------
element: WebElement
The modal dialog
"""
return self.wait.until_not(EC.alert_is_present())

def click_modal_footer_button(self, name):
""" Click the first founded button containing a given name in the modal
footer and then wait until the modal dialog is closed. We assume here
that only one modal dialog can be opened at the same time and that it
contains a footer with buttons. We also assume that whatever the button
does, it will close the modal dialog.
Parameters
----------
name: String
The name of the button you want to click

Example:
--------
click_modal_footer_button("Ok")
click_modal_footer_button("Submit")
click_modal_footer_button("Cancel")
"""
self.click_first_element_located(
By.XPATH, "//div[contains(@class,'modal-footer')]/button[text()='{}']".format(name)
)
self.wait_until_modal_closed()

def login(self, username="test"):
""" Login as a given user name. We assume that if you use this routine,
you are currently on the login page.
Parameters
----------
username: String
The name of the user, it can be "admin" if you want to login as admin.

Example:
--------
login("JohnDoe")
login("admin")
"""
self.driver.get(self.base_url + "/hub/login")

self.type_text_in_element_located(By.ID, "username_input", username)
self.type_text_in_element_located(By.ID, "password_input", username)

self.click_first_element_located(By.ID, "login_submit")

def logout(self):
""" Logout. We assume that if you use this routine you are currently on
the main page, and that the user-menu is clickable (which means that
there is no modal dialog in front of it).
"""
self.click_first_element_located(By.ID, "user-menu")
self.click_first_element_located(By.ID, "logout")
self.wait_until_text_inside_element_located(By.CSS_SELECTOR, "div.auth-form-header", "Sign in")

def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
Loading