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

Jan 31 #1

Open
wants to merge 2 commits into
base: feature_selenium
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions debug.log
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
[0130/190939.828:ERROR:exception_snapshot_win.cc(88)] thread ID 19408 not found in process
[0130/191528.638:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights. (0xc0000022)
[0130/191528.639:ERROR:exception_snapshot_win.cc(88)] thread ID 18544 not found in process
[0130/212907.419:ERROR:process_reader_win.cc(151)] SuspendThread: Access is denied. (0x5)
[0130/212907.420:ERROR:process_reader_win.cc(123)] NtOpenThread: {Access Denied} A process has requested access to an object, but has not been granted those access rights. (0xc0000022)
[0130/212907.420:ERROR:exception_snapshot_win.cc(88)] thread ID 12736 not found in process
8 changes: 8 additions & 0 deletions ppp_web/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ <h4 class="text-center" style="color:#9d9d9d; font-style: italic;">The Pretty PD
</div>
{% endif %}
{% endwith %}
<p id="browser-lang" class="text-center" style="margin-top:50px;"></p>
<script src="{{ url_for('static', filename='js/libs/jquery.min.js') }}" type="text/javascript"></script>
<script src="{{ url_for('static', filename='js/libs/fileinput.min.js') }}" type="text/javascript"></script>
<script src="{{ url_for('static', filename='js/libs/bootstrap.min.js') }}" type="text/javascript"></script>
Expand All @@ -151,6 +152,13 @@ <h4 class="text-center" style="color:#9d9d9d; font-style: italic;">The Pretty PD
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.14.0/xlsx.full.min.js"></script>
<script>
console.log('PPP-Web Version: ' + {{ version | tojson }});

$(function(){
console.log('detected browser language', navigator.language);
$('#browser-lang').html('(The language in the browser preference is '+navigator.language+')');
if ($('#form-export').length > 0)
$('#form-export').submit();
});
</script>
</body>
</html>
29 changes: 11 additions & 18 deletions selenium_test/test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Selenium tests"""
import os
import platform
import sys
import time
import selenium.webdriver.chrome.service as service
from selenium import webdriver
Expand All @@ -9,7 +10,10 @@
from diff_pdf_visually import pdfdiff
from selenium.common.exceptions import WebDriverException

from ppp_web.config import PROJECT_ROOT_DIR
PROJECT_ROOT_DIR = \
os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
sys.path.append(PROJECT_ROOT_DIR)

from selenium_test.static_methods import get_download_folder

# activity to choose two form files and submit the form, download file
Expand Down Expand Up @@ -60,8 +64,9 @@ def compare_files(ext, download_file_path, filename):
base_file_path = os.path.join(PROJECT_ROOT_DIR, 'docs', filename)

if ext == 'pdf':
print(download_file_path + '\n' + base_file_path)
flag = pdfdiff(download_file_path, base_file_path)
statinfo_downloaded_file = os.stat(download_file_path)
statinfo_base_file = os.stat(base_file_path)
flag = statinfo_downloaded_file.st_size == statinfo_base_file.st_size
else:
with open(download_file_path) as f1:
with open(base_file_path) as f2:
Expand All @@ -76,29 +81,20 @@ def compare_files(ext, download_file_path, filename):
def main_shot(btn_name: str, ext: str):
"""Main shot

TODO: @bciar Can you add some documentation here?
- What does function do? (1 sentence)
- What is btn_name?
This function is repeatable cycle for 3 types of conversion - remove existing downloaded file,
uploading file, choosing type of conversion, submit button, downloading, comparing

Args:
btn_name (str):
btn_name (str): the element id for toggling button - type of conversion (doc, html, pdf)
ext (str): file extension

Returns:
bool: True if no errors
"""
# TODO: @bciar do we need "global"? I never use 'global', so i don't know
# Tell me what you think on Slack, and then delete this comment
global browser

filename_base = 'demo'
filename = filename_base + '.' + ext

# TODO: @bciar I think we shouldn't be using 'path_char'. This is my
# mistake. We
# should use Python's built-in path libraries: os.path, pathlib, ntpath
# After you read this comment, delete it
# path_char = '\\' if platform.system() == 'Windows' else '/'
download_file_path = os.path.join(get_download_folder(), filename)

if os.path.exists(download_file_path):
Expand All @@ -109,9 +105,6 @@ def main_shot(btn_name: str, ext: str):

xform_file = \
os.path.join(PROJECT_ROOT_DIR, 'docs', filename_base + '.xlsx')
# xform_file = str(Path('docs/' + filename_base + 'xlsx').resolve())
# if platform.system() == 'Windows':
# xform_file = xform_file.replace('\\', '\\\\')

file_uploader = browser.find_element_by_id('inFile')
file_uploader.send_keys(xform_file)
Expand Down