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

Fix selenium tests broken after bootstrap upgrade #998

Merged
merged 9 commits into from
Jul 22, 2024
Merged
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
9 changes: 5 additions & 4 deletions .github/tests/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ APP_NAME=Cypht
DB_CONNECTION_TYPE=host
DB_DRIVER=mysql
DB_PORT=
DB_HOST=localhost
DB_HOST=127.0.0.1
DB_NAME=cypht_test
DB_USER=cypht_test
DB_PASS=cypht_test
DB_SOCKET=/var/lib/mysqld/mysqld.sock
DB_SOCKET=/tmp/test.db

SESSION_TYPE=PHP
AUTH_TYPE=IMAP
AUTH_TYPE=DB
LDAP_AUTH_SERVER=localhost
LDAP_AUTH_PORT=389
LDAP_AUTH_TLS=
Expand All @@ -28,7 +28,7 @@ DEFAULT_SMTP_PORT=
DEFAULT_SMTP_TLS=
DEFAULT_SMTP_NO_AUTH=

USER_CONFIG_TYPE=file
USER_CONFIG_TYPE=DB
USER_SETTINGS_DIR=/tmp
ATTACHMENT_DIR=/tmp
APP_DATA_DIR=/tmp
Expand Down Expand Up @@ -183,3 +183,4 @@ WORDPRESS_CLIENT_URI=

RECAPTCHA_SECRET=
RECAPTCHA_SITE_KEY=
CYPHT_MODULES="core,contacts,local_contacts,feeds,imap,smtp,account,idle_timer,calendar,themes,nux,history,saved_searches,advanced_search,profiles,inline_message,imap_folders,keyboard_shortcuts"
13 changes: 12 additions & 1 deletion .github/tests/selenium/creds.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.BinaryLocation = "/usr/bin/google-chrome"
chrome_options.add_argument("--window-size=3200,3800")

chrome_options.headless = False
chrome_options.add_argument("start-maximized")
# options.add_experimental_option("detach", True)
chrome_options.add_argument("--no-sandbox")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
chrome_options.add_experimental_option('useAutomationExtension', False)
chrome_options.add_argument('--disable-blink-features=AutomationControlled')

RECIP='testuser@localhost.org'
IMAP_ID='0'
DRIVER_CMD =Service('/usr/bin/chromedriver')
SITE_URL = 'http://cypht-test.org'
SITE_URL = 'http://cypht-test.org/'
USER = 'testuser'
PASS = 'testuser'
DESIRED_CAP = None
Expand All @@ -22,3 +32,4 @@ def get_driver(cap):

def success(driver):
pass

8 changes: 4 additions & 4 deletions .github/tests/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ setup_cypht() {
cp .github/tests/.env .
if [ "$DB" = "postgres" ]; then
# .env
sed -i 's/db_driver=mysql/db_driver=pgsql/' .env
sed -i 's/DB_DRIVER=mysql/DB_DRIVER=pgsql/' .env
# mocks.php
sed -i 's/mysql/pgsql/' tests/phpunit/mocks.php
fi
if [ "$DB" = "sqlite" ]; then
# .env
sed -i 's/db_driver=mysql/db_driver=sqlite/' .env
sed -i 's/DB_DRIVER=mysql/DB_DRIVER=sqlite/' .env
# mocks.php
sed -i 's/mysql/sqlite/' tests/phpunit/mocks.php
sed -i "s/'host'/'socket'/" tests/phpunit/mocks.php
Expand Down Expand Up @@ -125,7 +125,7 @@ setup_site() {
sudo cp .github/tests/selenium/nginx/php_fastcgi.conf /etc/nginx/nginxconfig/php_fastcgi.conf
sudo sed -e "s?%VERSION%?${PHP_V}?g" --in-place /etc/nginx/sites-available/default
sudo ln -sf "$(pwd)" /var/www/cypht
sudo systemctl start nginx.service
sudo systemctl start nginx
if [ "$(curl -s -o /dev/null -w '%{http_code}' 'http://cypht-test.org')" -eq 200 ]; then
STATUS_DONE
else
Expand Down Expand Up @@ -161,7 +161,7 @@ case "$ARG" in
phpunit)
setup_unit_tests
;;
ui)
selenium)
setup_ui_tests
;;
*)
Expand Down
3 changes: 2 additions & 1 deletion .github/tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ phpunit_tests() {
}

selenium_tests() {
cp .github/tests/selenium/creds.py tests/selenium/
cd tests/selenium/ && sh ./runall.sh && cd ../../
}

Expand All @@ -18,7 +19,7 @@ case "$ARG" in
phpunit)
phpunit_tests
;;
ui)
selenium)
selenium_tests
;;
*)
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/Test-Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ jobs:
- name: "Composer Install Dependencies"
run: |
composer install
php scripts/config_gen.php

- name: "Script: setup.sh"
run: bash .github/tests/setup.sh
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ services:
- DB_DRIVER=mysql
- DB_HOST=db
- DB_NAME=cypht
- DB_USER=cypht
- DB_PASS=cypht_password
- DB_USER=testuser
- DB_PASS=testuser
- SESSION_TYPE=DB
- USER_CONFIG_TYPE=DB
extra_hosts:
Expand Down
2 changes: 1 addition & 1 deletion modules/calendar/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ protected function output() {
$events = $cal_events->in_date_range($bounds[0], $bounds[1]);
$out = new Hm_Cal_Output($this, $events);
$out = $out->output($data, $date, $view);
return '<div class="calendar p-0"><div class="content_title d-flex justify-content-between px-3">'.$this->trans('Calendar').
return '<div class="calendar p-0"><div class="content_title d-flex justify-content-between px-3"><span class="calendar_content_title">'.$this->trans('Calendar').'</span>'.
'<a href="?page=calendar&amp;action=add" title="'.$this->trans('Add Event').'" class="btn btn-light btn-sm">'.
'<i class="bi bi-plus-circle me-2"></i> '.$this->trans('Add Event').'</a></div>'.
$out.'</div>';
Expand Down
7 changes: 3 additions & 4 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ class Hm_Output_server_content_start extends Hm_Output_Module {
*/
protected function output() {
return '<div class="content_title">'.$this->trans('Servers').
'<div class="list_controls"></div>'.
'</div><div class="server_content">';
}
}
Expand Down Expand Up @@ -2172,7 +2171,7 @@ protected function output() {
</div>
<div class="step_config-actions mt-4 d-flex justify-content-between">
<button class="btn btn-primary px-5" onclick="display_config_step(0);resetQuickSetupForm();">'.$this->trans('Cancel').'</button>
<button class="btn btn-primary px-5" onclick="display_config_step(2)">'.$this->trans('Next').'</button>
<button class="btn btn-primary px-5" id="step_config_action_next" onclick="display_config_step(2)">'.$this->trans('Next').'</button>
</div>
</div>
<div id="step_config_2" class="step step_config">
Expand Down Expand Up @@ -2241,11 +2240,11 @@ protected function output() {
<div class="step_config-actions mt-4 d-flex justify-content-between">
<button class="btn btn-danger px-3" onclick="display_config_step(0);resetQuickSetupForm();">'.$this->trans('Cancel').'</button>
<button class="btn btn-primary px-4" onclick="display_config_step(1)">'.$this->trans('Previous').'</button>
<button class="btn btn-primary px-3" onclick="display_config_step(3)" id="stepper-action-finish">'.$this->trans('Finish').'</button>
<button class="btn btn-primary px-3" id="step_config_action_finish" onclick="display_config_step(3)" id="stepper-action-finish">'.$this->trans('Finish').'</button>
</div>
</div>
<div id="step_config_0" class="step_config current_config_step">
<button class="imap-jmap-smtp-btn btn btn-primary px-4" onclick="display_config_step(1)"><i class="bi bi-plus-square-fill me-2"></i> '.$this->trans('Add a new server').'</button>
<button class="imap-jmap-smtp-btn btn btn-primary px-4" id="add_new_server_button" onclick="display_config_step(1)"><i class="bi bi-plus-square-fill me-2"></i> '.$this->trans('Add a new server').'</button>
</div>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion modules/core/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ var Hm_Utils = {
},

confirm_logout: function() {
if ($('#unsaved_changes').val() == 0) {
if (! $('#unsaved_changes').length || $('#unsaved_changes').val() == 0) {
document.getElementById('logout_without_saving').click();
}
else {
Expand Down Expand Up @@ -1980,6 +1980,9 @@ $(function() {

/* fire up the job scheduler */
Hm_Timer.fire();

/* show any pending notices */
Hm_Utils.show_sys_messages();

/* load folder list */
if (hm_is_logged() && (!reloaded && !Hm_Folders.load_from_local_storage())) {
Expand Down
2 changes: 1 addition & 1 deletion modules/profiles/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function process() {
class Hm_Output_profile_edit_form extends Hm_Output_Module {
protected function output() {
$new_id = $this->get('new_profile_id', -1);
$res = '<div class="profile_content p-0"><div class="content_title px-3 d-flex justify-content-between"><span>'.$this->trans('Profiles').'</span>';
$res = '<div class="profile_content p-0"><div class="content_title px-3 d-flex justify-content-between"><span class="profile_content_title">'.$this->trans('Profiles').'</span>';
$smtp_servers = $this->get('smtp_servers', array());
$imap_servers = $this->get('imap_servers', array());
if ($this->get('edit_profile')) {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public function test_fancy_login() {
public function test_server_content_start() {
$test = new Output_Test('server_content_start', 'core');
$res = $test->run();
$this->assertEquals(array('<div class="content_title">Servers<div class="list_controls"></div></div><div class="server_content">'), $res->output_response);
$this->assertEquals(array('<div class="content_title">Servers</div><div class="server_content">'), $res->output_response);
}
/**
* @preserveGlobalState disabled
Expand Down
29 changes: 20 additions & 9 deletions tests/selenium/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, cap=None):

def read_ini(self):
self.modules = []
self.servers = 1
kroky marked this conversation as resolved.
Show resolved Hide resolved
self.auth_type = ''
config_files = glob.glob('../../config/*.php')
for file_path in config_files:
Expand Down Expand Up @@ -60,6 +61,12 @@ def mod_active(self, name):
return True
print(" - module not enabled: %s" % name)
return False

def single_server(self):
if self.servers <= 1:
return True
print(" - servers account: %s" % self.servers)
return False

def go(self, url):
self.driver.get(url)
Expand All @@ -81,40 +88,44 @@ def confirm_alert(self):
WebDriverWait(self.driver, 3).until(exp_cond.alert_is_present(), 'timed out')
alert = self.driver.switch_to.alert
alert.accept()

def logout_no_save(self):
print(" - logging out")
self.driver.find_element_by_class_name('logout_link').click()
self.driver.find_element(By.CLASS_NAME, 'logout_link').click()
logout = self.by_id('logout_without_saving').click()

def logout(self):
print(" - logging out")
self.driver.find_element_by_class_name('logout_link').click()
self.driver.find_element(By.CLASS_NAME, 'logout_link').click()

def end(self):
self.driver.quit()

def by_id(self, el_id):
print(" - finding element by id {0}".format(el_id))
return self.driver.find_element_by_id(el_id)
return self.driver.find_element(By.ID, el_id)

def by_tag(self, name):
print(" - finding element by tag name {0}".format(name))
return self.driver.find_element_by_tag_name(name)
return self.driver.find_element(By.TAG_NAME, name)

def by_name(self, name):
print(" - finding element by name {0}".format(name))
return self.driver.find_element_by_name(name)
return self.driver.find_element(By.NAME, name)

def by_css(self, selector):
print(" - finding element by selector {0}".format(selector))
return self.driver.find_element_by_css_selector(selector)
return self.driver.find_element(By.CSS_SELECTOR, selector)

def by_class(self, class_name):
print(" - finding element by class {0}".format(class_name))
return self.driver.find_element_by_class_name(class_name)
return self.driver.find_element(By.CLASS_NAME, class_name)

def by_xpath(self, element_xpath):
print(" - finding element by xpath {0}".format(element_xpath))
return self.driver.find_element(By.XPATH, element_xpath)

def wait(self, el_type=By.TAG_NAME, el_value="body", timeout=30):
def wait(self, el_type=By.TAG_NAME, el_value="body", timeout=60):
print(" - waiting for page by {0}: {1} ...".format(el_type, el_value))
element = WebDriverWait(self.driver, timeout).until(
exp_cond.presence_of_element_located((el_type, el_value)))
Expand Down
13 changes: 7 additions & 6 deletions tests/selenium/folder_list.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python

from base import WebTest, USER, PASS
from selenium.webdriver.common.by import By
from runner import test_runner

class FolderListTests(WebTest):
Expand All @@ -19,26 +20,26 @@ def reload_folder_list(self):
def expand_section(self):
self.by_css('[data-source=".settings"]').click()
list_item = self.by_class('menu_home')
list_item.find_element_by_tag_name('a').click()
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
assert self.by_class('content_title').text == 'Home'

def collapse_section(self):
self.by_css('[data-source=".main"]').click()
list_item = self.by_class('menu_unread')
link = list_item.find_element_by_tag_name('a')
link = list_item.find_element(By.TAG_NAME, 'a')
assert link.is_displayed() == False

def hide_folders(self):
self.by_class('hide_folders').click()
self.by_css('[data-source=".settings"]').click()
list_item = self.by_class('menu_home')
link = list_item.find_element_by_tag_name('a');
link = list_item.find_element(By.TAG_NAME, 'a');
assert link.is_displayed() == False

def show_folders(self):
self.by_class('folder_toggle').click()
self.by_css('[data-source=".settings"]').click()
list_item = self.by_class('menu_home')
list_item.find_element_by_tag_name('a').click()
list_item.find_element(By.TAG_NAME, 'a').click()
self.wait_with_folder_list()
assert self.by_class('content_title').text == 'Home'
self.by_css('[data-source=".main"]').click()
Expand Down
10 changes: 5 additions & 5 deletions tests/selenium/inline_msg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python

from base import WebTest, USER, PASS
from selenium.webdriver.common.by import By
from runner import test_runner
from settings import SettingsHelpers

Expand All @@ -16,16 +17,15 @@ def set_inline_message_test(self):
self.dropdown_test('email_setting', 'all_email_since', '-1 week', '-5 years')

def navigate_msg_test(self):
self.by_css('[data-source=".email_folders"]').click()
allmsgs = self.by_class('menu_email')
allmsgs.find_element_by_tag_name('a').click()
allmsgs.find_element(By.TAG_NAME, 'a').click()
self.wait_on_class('checkbox_cell')
body = self.by_class('message_table_body')
subject = body.find_element_by_class_name('subject')
subject.find_element_by_tag_name('a').click()
subject = body.find_element(By.CLASS_NAME, 'subject')
subject.find_element(By.TAG_NAME, 'a').click()
self.wait_on_class('header_subject')
detail_subject = self.by_class('header_subject')
header = detail_subject.find_element_by_tag_name('th')
header = detail_subject.find_element(By.TAG_NAME, 'th')
assert header.text.startswith('recent')


Expand Down
4 changes: 2 additions & 2 deletions tests/selenium/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from base import WebTest, USER, PASS
from runner import test_runner

from selenium.webdriver.common.by import By
class LoginTests(WebTest):

def bad_login_values(self):
self.login('asdf', 'asdf')
self.wait()
self.safari_workaround()
assert self.by_class('err') != None
assert self.by_class('sys_messages') != None

def missing_password(self):
self.load()
Expand Down
Loading