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

Feature/tests #46

Merged
merged 2 commits into from
Apr 28, 2020
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
84 changes: 84 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Tests (Python 3.x)

on:
push:
paths:
- '.github/workflows/**'
- 'src/**'
- 'tests/**'
- 'setup.py'
pull_request:
paths:
- '.github/workflows/**'
- 'src/**'
- 'tests/**'
- 'setup.py'
jobs:
test_using_builtin_python:

strategy:
fail-fast: false
matrix:
os: [ 'ubuntu-latest', 'windows-latest' ]
python-version: [ '3.6', '3.7', '3.8' ]
include:
- os: ubuntu-latest
set_display: export DISPLAY=:99; Xvfb :99 -screen 0 1024x768x24 -ac -noreset & sleep 3
#- os: macos-latest
#set_tmpdir: export TMPDIR=/tmp
- os: windows-latest
set_codepage: chcp 850

runs-on: ${{ matrix.os }}

name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2

- name: Setup python ${{ matrix.python-version }} for running the tests
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'

# pyautogui does not work by default (https://github.com/asweigart/pyautogui/issues/247)
# need to disable security feature (https://apple.stackexchange.com/questions/178313/change-accessibility-setting-on-mac-using-terminal)
# and database is readonly (https://github.com/jacobsalmela/tccutil/issues/18)
# you need to disable SIP, but for that go into recovery mode and disable it - not on CI system
#- name: Install test tools to Mac
#run: |
#sudo sqlite3 "/Library/Application Support/com.apple.TCC/TCC.db" 'UPDATE access SET allowed = "1";'
#if: runner.os == 'macOS'

- name: Install test tools to Linux
run: |
sudo apt-get update
sudo apt-get -y -q install xvfb scrot chromium-browser
touch ~/.Xauthority
if: contains(matrix.os, 'ubuntu')

- name: Install python test dependencies
run: |
python --version
python -m pip install mock robotframework opencv-python eel .

- name: Run tests
run: |
${{ matrix.set_codepage }}
${{ matrix.set_display }}
python tests/utest/run_tests.py
python tests/atest/run_tests.py

- name: Archive acceptances test results
uses: actions/[email protected]
with:
name: log-${{ matrix.python-version }}-${{ matrix.os }}
path: log.html
if: always() && job.status == 'failure'

- name: Archive acceptances test failure screenshot on Linux
uses: actions/[email protected]
with:
name: screenshot-${{ matrix.python-version }}-${{ matrix.os }}
path: /tmp/Atest.Calculator-screenshot-1.png
if: always() && job.status == 'failure' && contains(matrix.os, 'ubuntu')
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ log.html
*-screenshot-*.png
*\$py.class
*.swp
*__pycache__
*__pycache__
/bin
/include
/lib
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

20 changes: 20 additions & 0 deletions tests/atest/calculator.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
*** Settings ***
Library ImageHorizonLibrary ${CURDIR}${/}reference_images${/}calculator screenshot_folder=${TEMPDIR}

*** Test cases ***

Calculator
Set Confidence 0.9
Launch application python tests/atest/calculator/calculator.py
${location1}= Wait for inputs.png timeout=30
Click to the above of ${location1} 20
Type 1010
Click to the below of ${location1} 20
Type 1001
${location2}= Locate or_button.png
Click to the below of ${location2} 0
Click to the below of ${location2} 50
${result}= Copy
Should be equal as integers ${result} 1011
Click Image close_button.png
[Teardown] Terminate application
16 changes: 16 additions & 0 deletions tests/atest/calculator/calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import eel
import os
import sys


os.chdir(os.path.dirname(__file__))

eel.init('web')


@eel.expose
def close():
sys.exit(0)


eel.start('main.html', size=(300, 380))
Binary file added tests/atest/calculator/web/Roboto-Black.ttf
Binary file not shown.
191 changes: 191 additions & 0 deletions tests/atest/calculator/web/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<!DOCTYPE html>
<html>
<head>
<title>Bitwise Calculator</title>

<style>
@font-face {
font-family: Roboto;
src: url('Roboto-Black.ttf') format('truetype');
}

body {
font-family: Roboto;
font-size: 18px;
}

.clickable {
user-select: none;
cursor: pointer;
}

.button {
background-color: black;
color: white;
padding: 10px 30px;
margin: 10px;
text-align: center;
text-decoration: none;
display: block;
border: none;
border-radius: 10px;
}

.button:active {
background-color: gray;
}

.binary-input {
border: 2px solid black;
outline: none;
}

#first,#second {
padding: 10px;
}

.check {
color: gray;
}

.check[checked] {
color: black;
}

#result {
text-align: center;
display: block;
font-size: 24px;
padding: 20px 0px;
}
</style>

<script type="text/javascript" src="/eel.js"></script>
<script type="text/javascript">
function setInputFilter(textbox, inputFilter) {
["input", "keydown", "keyup", "mousedown", "mouseup", "select", "contextmenu", "drop"].forEach(function(event) {
textbox.addEventListener(event, function() {
if (inputFilter(this.value)) {
this.oldValue = this.value;
this.oldSelectionStart = this.selectionStart;
this.oldSelectionEnd = this.selectionEnd;
} else if (this.hasOwnProperty("oldValue")) {
this.value = this.oldValue;
this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
} else {
this.value = "";
}
});
});
}

function selectElementText(el, win) {
win = win || window;
var doc = win.document, sel, range;
if (win.getSelection && doc.createRange) {
sel = win.getSelection();
range = doc.createRange();
range.selectNodeContents(el);
sel.removeAllRanges();
sel.addRange(range);
} else if (doc.body.createTextRange) {
range = doc.body.createTextRange();
range.moveToElementText(el);
range.select();
}
}

function main() {
let checks = document.querySelectorAll('.check');
checks.forEach(e => {
e.addEventListener('click', event => {
if (event.target.hasAttribute('checked')) {
event.target.removeAttribute('checked');
} else {
event.target.setAttribute('checked', 1);
}
});
});

let inputs = document.querySelectorAll('.binary-input');
inputs.forEach(e => {
setInputFilter(e, function(value) {
return /^[01]+$/.test(value);
});
});

let close = document.querySelector('#close');
close.addEventListener('click', event => {
eel.close();
window.close('','_parent','');
});

let result = document.querySelector('#result');
let resultArea = document.querySelector('#result-area');
resultArea.addEventListener('click', event => {
selectElementText(result);
});

let fnot = document.querySelector('#fnot');
let fnumber = document.querySelector('#fnumber');
let snot = document.querySelector('#snot');
let snumber = document.querySelector('#snumber');

let buttons = document.querySelectorAll('.button[operation]');
buttons.forEach(e => {
e.addEventListener('click', event => {

let fvalue = parseInt(fnumber.value, 2);
if (fnot.hasAttribute('checked')) {
fvalue = ~fvalue;
}
let svalue = parseInt(snumber.value, 2);
if (snot.hasAttribute('checked')) {
svalue = ~svalue;
}

let operation = event.target.getAttribute('operation');

switch (operation) {
case 'and':
res = fvalue & svalue;
break;
case 'or':
res = fvalue | svalue;
break;
default:
throw new Error('Unknown Operation');
}

result.innerHTML = res.toString(2);
});
});
};

setTimeout('main()');
</script>
</head>


<body>
<div id="form">
<div id="first">
<label id="fnot" class="clickable check">NOT</label>
<input type="text" id="fnumber" class="binary-input" />
</div>
<div id="second">
<label id="snot" class="clickable check">NOT</label>
<input type="text" id="snumber" class="binary-input" />
</div>

<div>
<label id="and" class="clickable button" operation="and">AND</label>
<label id="or" class="clickable button" operation="or">OR</label>
</div>
</div>
<div id="result-area">
<span id="result">N/A</span>
</div>
<label id="close" class="clickable button">Close</label>
</body>
</html>
18 changes: 0 additions & 18 deletions tests/atest/linux_tests.robot

This file was deleted.

Loading