Skip to content
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
19 changes: 19 additions & 0 deletions pyguit/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import re
from Xlib import display, X, Xatom
from ewmh import EWMH
import argparse

from sys import platform
if not (platform == "linux" or platform == "linux2"):
Expand Down Expand Up @@ -118,6 +119,24 @@ def get_window_title(self, window):
return window_name.value
return window_name.value.decode("utf-8")
return None

def get_window_position(self, window):
try:
# Get the window's position and size using pyautogui
window_info = self.gui.get_window_position(window)
if window_info:
# Extract position and size information
x = window_info[0].left
y = window_info[0].top
width = window_info[0].width
height = window_info[0].height
return x, y, width, height
else:
print(f"Window '{window}' not found.")
return None
except Exception as e:
print(f"Error occurred while getting window position: {e}")
return None

def frame(self, window):
frame = window
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
import setuptools

def _get_version():
Expand Down
59 changes: 59 additions & 0 deletions test/adi-diagnostic/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import pytest

def pytest_addoption(parser):
parser.addoption(
"--remote",
action="store_true",
help="Run test on network mode",
)

parser.addoption(
"--local",
action="store_true",
help="Run test on local mode",
)

parser.addoption(
"--ip",
action="store",
default="localhost",
help="IP of DUT",
)

parser.addoption(
"--delay",
action="store",
type=int,
default=10,
help="adding delay",
)

def pytest_configure(config):
# register marker
config.addinivalue_line("markers", "remote: mark remote tests")
config.addinivalue_line("markers", "local: mark local tests")


def pytest_runtest_setup(item):
remote = item.config.getoption("--remote")
marks = [mark.name for mark in item.iter_markers()]
if not remote and "remote" in marks:
pytest.skip(
"Testing requires network flag: --remote"
)

local = item.config.getoption("--local")
marks = [mark.name for mark in item.iter_markers()]
if not local and "local" in marks:
pytest.skip(
"Testing requires local flag: --local"
)

@pytest.fixture(scope="session")
def ip(pytestconfig):
return pytestconfig.getoption("ip")


@pytest.fixture(scope="session")
def delay(pytestconfig):
return pytestconfig.getoption("delay")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/adi-diagnostic/ref_test_open_app_rpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/adi-diagnostic/ref_test_open_diagnostic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions test/adi-diagnostic/test_adi_diagnostic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import pytest
import pyguit
import time
import os
import shutil

class TestDiagnostic:

@classmethod
def setup_class(self):
'''Setup the pyguit object. Will be called once before the start of test'''
self.gui = pyguit.gui()
self.gui.attach_openbox()
# self.gui.run_ssh_agent()
time.sleep(10)
try:
os.makedirs("results")
except FileExistsError:
# directory already exists
shutil.rmtree('results')
os.makedirs("results")

@classmethod
def teardown_class(self):
'''Garbage collector. Will be called once after running of tests'''
time.sleep(10)
self.gui.dettach_openbox()
del self.gui

@pytest.mark.remote
def test_open_app_terminal_on_remote(self, ip, delay):
'''Test if app opens, and checks main window'''
self.gui.open_app(
host=ip,
user="analog",
app_name="adi_diagnostic_report",
path="/usr/local/bin/adi_diagnostic_report --gui")
time.sleep(delay)
print("Test build: Check application title")
# Find main screen
found_window = None
for w in self.gui.get_open_windows():
if w:
print(self.gui.get_window_title(w))
print("Test build: Check application title")
#Find main screen
found_window = None
for w in self.gui.get_open_windows():
if w:
print(self.gui.get_window_title(w))
time.sleep(delay)
self.gui.find_window("Generate Diagnostic Report")
print("Test build: Done main window")
time.sleep(delay)
# assert self.gui.controller.locateOnScreen("ref_test_open_diagnostic.png", grayscale=True, confidence=0.9)
assert self.gui.controller.locateOnScreen("ref_test_open_app_rpi.png", grayscale=True, confidence=0.9)
self.gui.controller.screenshot("results/test_open_diagnostic.png")
time.sleep(5)

#click functons
noneBtn = self.gui.controller.locateCenterOnScreen("ref_test_click_none_button.png", grayscale=True, confidence=0.9)
assert noneBtn
self.gui.controller.click(noneBtn)
time.sleep(5)
self.gui.controller.screenshot("results/test_click_none_button.png")
print("Test build: Done None button")
time.sleep(delay)
analogItem = self.gui.controller.locateCenterOnScreen("ref_test_click_analog_item.png", grayscale=True, confidence=0.9)
assert analogItem
self.gui.controller.click(analogItem)
time.sleep(5)
self.gui.controller.screenshot("results/test_click_analog.png")
print("Test build: Done analog item")
generateBtn = self.gui.controller.locateCenterOnScreen("ref_test_click_generate_button.png", grayscale=True, confidence=0.9)
assert generateBtn
self.gui.controller.click(generateBtn)
time.sleep(5)
self.gui.controller.screenshot("results/test_generate_button.png")
print("Test build: Done Generate button")



2 changes: 1 addition & 1 deletion test/gnuradio/test_adi_gnuradio.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_open_app_on_remote(self, ip, delay):
self.gui.open_app(
host= ip,
user="analog",
app_name="gnuradio",
app_name="gnuradio-companion",
path="/usr/bin/gnuradio-companion",
)
time.sleep(delay)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/iio-oscilloscope/ref_test_run_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/iio-oscilloscope/results/test_run_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 36 additions & 3 deletions test/iio-oscilloscope/test_adi_oscilloscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,43 @@ def test_open_app_on_remote(self, ip, delay):
path="/usr/local/bin/osc",
)
time.sleep(delay)
#find_active_screen
print("Test build: Check application title")
# Find main screen
found_window = None
for w in self.gui.get_open_windows():
if w:
if w:
print(self.gui.get_window_title(w))
time.sleep(delay)
self.gui.controller.screenshot("results/test_open_a_app.png")
#find_small_window
time.sleep(delay)
small_window = self.gui.find_window("ADI IIO Oscilloscope")
self.gui.set_window_center(small_window)
print("Test build: Done small window")
time.sleep(delay)
assert self.gui.controller.locateCenterOnScreen("ref_test_open_adi_iio_oscilloscope_app.png", grayscale=True, confidence=0.5)
self.gui.controller.screenshot("results/test_open_adi_iio_oscilloscope_app.png")
# find_main screen
main_window = self.gui.find_window("ADI IIO Oscilloscope - Capture1")
self.gui.set_window_center(main_window)
time.sleep(delay)
assert self.gui.controller.locateCenterOnScreen("ref_test_open_adi_iio_oscilloscope-capture1_app.png", grayscale=True, confidence=0.5)
self.gui.controller.screenshot("results/test_open_adi_iio_oscilloscope-capture1_app.png")
print("Test build: Done main window")

def test_play_button(self,delay):
'''Test if capture works by clicking the checkbox button'''
checkboxBtn = self.gui.controller.locateCenterOnScreen("ref_test_enable_all_checkbox.png", grayscale=True, confidence=0.9)
assert checkboxBtn
self.gui.controller.click(checkboxBtn)
time.sleep(5)
self.gui.controller.screenshot("results/test_checkbox_button.png")
print("Test build: Done checkbox")
time.sleep(delay)
runBtn = self.gui.controller.locateCenterOnScreen("ref_test_run_button.png", grayscale=True, confidence=0.5)
assert runBtn
self.gui.controller.click(runBtn)
time.sleep(5)
self.gui.controller.screenshot("results/test_run_button.png")
print("Test build: Done run button")


60 changes: 60 additions & 0 deletions test/scopy/linux/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import pytest

def pytest_addoption(parser):
parser.addoption(
"--remote",
action="store_true",
help="Run test on network mode",
)

parser.addoption(
"--local",
action="store_true",
help="Run test on local mode",
)

parser.addoption(
"--ip",
action="store",
default="localhost",
help="IP of DUT",
)

parser.addoption(
"--delay",
action="store",
type=int,
default=10,
help="adding delay",
)


def pytest_configure(config):
# register marker
config.addinivalue_line("markers", "remote: mark remote tests")
config.addinivalue_line("markers", "local: mark local tests")


def pytest_runtest_setup(item):
remote = item.config.getoption("--remote")
marks = [mark.name for mark in item.iter_markers()]
if not remote and "remote" in marks:
pytest.skip(
"Testing requires network flag: --remote"
)

local = item.config.getoption("--local")
marks = [mark.name for mark in item.iter_markers()]
if not local and "local" in marks:
pytest.skip(
"Testing requires local flag: --local"
)

@pytest.fixture(scope="session")
def ip(pytestconfig):
return pytestconfig.getoption("ip")


@pytest.fixture(scope="session")
def delay(pytestconfig):
return pytestconfig.getoption("delay")
Binary file added test/scopy/linux/ref_test_open_appScopy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/scopy/linux/ref_test_open_scopy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions test/scopy/linux/test_adi_scopy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pytest
import pyguit
import time
import os
import shutil

class TestScopy:

@classmethod
def setup_class(self):
'''Setup the pyguit object. Will be called once before the start of test'''
self.gui = pyguit.gui()
self.gui.attach_openbox()
# self.gui.run_ssh_agent()
time.sleep(10)
try:
os.makedirs("results")
except FileExistsError:
# directory already exists
shutil.rmtree('results')
os.makedirs("results")

@classmethod
def teardown_class(self):
'''Garbage collector. Will be called once after running of tests'''
time.sleep(10)
self.gui.dettach_openbox()
del self.gui

@pytest.mark.remote
def test_open_app_on_remote(self, ip, delay):
'''Test if app opens, and checks main window'''
self.gui.open_app(
host=ip,
user="analog",
app_name="flatpak",
path="/usr/bin/flatpak",
)
time.sleep(delay)
# print("Test build: Check application title") **commented this first**
# Find main screen
# found_window = None
# for w in self.gui.get_open_windows():
# if w:
# print(self.gui.get_window_title(w))
# print(self.gui.get_window_title(w))
# time.sleep(delay)


Loading