Skip to content

Commit

Permalink
adding browser console to the report
Browse files Browse the repository at this point in the history
  • Loading branch information
ronandrevon committed Oct 12, 2023
1 parent 7d8f40c commit d176ffb
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Version log
## 0.0.7dev
### Thu 12 Oct 18:30:11 CEST 2023
- tests:
- capturing browser console to the report folder *console.log*
### Thu 12 Oct 13:11:11 BST 2023
- issue#62 : delete frames
- simple new feature
Expand Down
9 changes: 8 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def pytest_addoption(parser):
parser.addoption('--ip' ,action="store" ,default="localhost")
parser.addoption('--address' ,action="store" ,default='')
parser.addoption('--sleep' ,action="store" ,default=0.3)
parser.addoption('--report' ,action='store' ,default="")#"console.log")
parser.addoption('--headless' ,action='store_true',default=False)

parser.addoption("--slow", action="store_true", default=False, help="run slow tests")
Expand Down Expand Up @@ -51,7 +52,7 @@ def pytest_collection_modifyitems(config, items):

lvl = int(config.getoption("--lvl"))
for item in items:
for i in range(1,3):
for i in range(1,5):
if "lvl%d" %i in item.keywords:
reason="test level marked as lvl{test_level}>{lvl}".format(test_level=i,lvl=lvl)
item.add_marker(pytest.mark.skipif(lvl<i, reason=reason))
Expand Down Expand Up @@ -82,6 +83,8 @@ def chrome_driver(pytestconfig):
options.add_argument('--headless')
address=get_address(pytestconfig)

options.set_capability("goog:loggingPrefs", {"performance": "ALL", "browser": "ALL"})

chrome_driver = webdriver.Chrome(options=options)
# chrome_driver.set_network_conditions(offline=True,latency=5,throughput=500*1024)
# print(address)
Expand All @@ -106,3 +109,7 @@ def sec(pytestconfig):
@pytest.fixture(scope="package")
def address(pytestconfig):
return get_address(pytestconfig)

@pytest.fixture(scope="package")
def report(pytestconfig):
return pytestconfig.getoption('--report')
2 changes: 1 addition & 1 deletion tests/email_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
msg.attach(MIMEText(body, "plain"))

#### attachments
for filename in ['server.log','pytest.log','report.html']:
for filename in ['server.log','pytest.log','report.html','console.log']:
with open(os.path.join(folder,filename), "rb") as attachment:
part = MIMEBase("application", "octet-stream")
part.set_payload(attachment.read())
Expand Down
7 changes: 5 additions & 2 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ while getopts ":l:a:A:p:s:m:rdHReCh" arg; do
;;
s)
sleep=$OPTARG
args+="--sleep=$sleep"
args+=" --sleep=$sleep "
;;
r)
report_dir='report_rel'
Expand Down Expand Up @@ -123,7 +123,9 @@ if [ $do_report -eq 1 ];then

report_log="$report_dir/run_tests.log"
server_log="$report_dir/server.log"

console_log="$report_dir/console.log"
args+=" --report=$console_log "

cd $dir/..
echo 'Launching server for reporting' >> "tests/$report_log"; tail -n1 "tests/$report_log"
$env_bin/python3 serve.py -p $port &> "tests/$server_log" &
Expand Down Expand Up @@ -209,6 +211,7 @@ fi
if [ $do_report -eq 1 ];then
echo "Shutting down server used for pytest" >> $report_log; tail -n1 $report_log
kill $server_pid
cat $pytest_log
if [ $send_email -eq 1 ];then
echo "Sending email to $email_address" >> $report_log; tail -n1 $report_log
cmd="$env_bin/python3 email_report.py -f=$report_dir"
Expand Down
12 changes: 11 additions & 1 deletion tests/test_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def test_delete_struct(chrome_driver,sec):
sleep(2)

@pytest.mark.new
def test_close(chrome_driver):
def test_close(chrome_driver,report):
print(colors.green+"\nclosing browser. Good bye"+colors.black)
log_entries = chrome_driver.get_log("performance")
entries = chrome_driver.get_log('browser')

msg='\n'.join([entry['message'] for entry in entries
if entry['source']=='console-api'])
# print(msg)
if report:
with open(report,'w') as f :
f.write(msg)

chrome_driver.close()

0 comments on commit d176ffb

Please sign in to comment.