diff --git a/pyguit/gui.py b/pyguit/gui.py index 98bbffc..45454b0 100644 --- a/pyguit/gui.py +++ b/pyguit/gui.py @@ -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"): @@ -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 diff --git a/setup.py b/setup.py index a5b058b..bc7dae7 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,4 @@ +import re import setuptools def _get_version(): diff --git a/test/adi-diagnostic/conftest.py b/test/adi-diagnostic/conftest.py new file mode 100644 index 0000000..6c10c9c --- /dev/null +++ b/test/adi-diagnostic/conftest.py @@ -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") \ No newline at end of file diff --git a/test/adi-diagnostic/ref_test_click_analog_item.png b/test/adi-diagnostic/ref_test_click_analog_item.png new file mode 100644 index 0000000..e40f48c Binary files /dev/null and b/test/adi-diagnostic/ref_test_click_analog_item.png differ diff --git a/test/adi-diagnostic/ref_test_click_generate_button.png b/test/adi-diagnostic/ref_test_click_generate_button.png new file mode 100644 index 0000000..f81a87f Binary files /dev/null and b/test/adi-diagnostic/ref_test_click_generate_button.png differ diff --git a/test/adi-diagnostic/ref_test_click_none_button.png b/test/adi-diagnostic/ref_test_click_none_button.png new file mode 100644 index 0000000..d2ef768 Binary files /dev/null and b/test/adi-diagnostic/ref_test_click_none_button.png differ diff --git a/test/adi-diagnostic/ref_test_open_app_rpi.png b/test/adi-diagnostic/ref_test_open_app_rpi.png new file mode 100644 index 0000000..b5083d4 Binary files /dev/null and b/test/adi-diagnostic/ref_test_open_app_rpi.png differ diff --git a/test/adi-diagnostic/ref_test_open_diagnostic.png b/test/adi-diagnostic/ref_test_open_diagnostic.png new file mode 100644 index 0000000..4b5ff42 Binary files /dev/null and b/test/adi-diagnostic/ref_test_open_diagnostic.png differ diff --git a/test/adi-diagnostic/test_adi_diagnostic.py b/test/adi-diagnostic/test_adi_diagnostic.py new file mode 100644 index 0000000..1f1abcb --- /dev/null +++ b/test/adi-diagnostic/test_adi_diagnostic.py @@ -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") + + + \ No newline at end of file diff --git a/test/gnuradio/test_adi_gnuradio.py b/test/gnuradio/test_adi_gnuradio.py index c878c76..de67e14 100644 --- a/test/gnuradio/test_adi_gnuradio.py +++ b/test/gnuradio/test_adi_gnuradio.py @@ -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) diff --git a/test/iio-oscilloscope/ref_test_enable_all_checkbox.png b/test/iio-oscilloscope/ref_test_enable_all_checkbox.png new file mode 100644 index 0000000..14d5517 Binary files /dev/null and b/test/iio-oscilloscope/ref_test_enable_all_checkbox.png differ diff --git a/test/iio-oscilloscope/ref_test_open_a_app.png b/test/iio-oscilloscope/ref_test_open_adi iio oscilloscope - capture1_app.png similarity index 100% rename from test/iio-oscilloscope/ref_test_open_a_app.png rename to test/iio-oscilloscope/ref_test_open_adi iio oscilloscope - capture1_app.png diff --git a/test/iio-oscilloscope/ref_test_open_b_app.png b/test/iio-oscilloscope/ref_test_open_adi iio oscilloscope_app.png similarity index 100% rename from test/iio-oscilloscope/ref_test_open_b_app.png rename to test/iio-oscilloscope/ref_test_open_adi iio oscilloscope_app.png diff --git a/test/iio-oscilloscope/ref_test_open_adi_iio_oscilloscope-capture1_app.png b/test/iio-oscilloscope/ref_test_open_adi_iio_oscilloscope-capture1_app.png new file mode 100644 index 0000000..a5bb3dc Binary files /dev/null and b/test/iio-oscilloscope/ref_test_open_adi_iio_oscilloscope-capture1_app.png differ diff --git a/test/iio-oscilloscope/ref_test_open_adi_iio_oscilloscope_app.png b/test/iio-oscilloscope/ref_test_open_adi_iio_oscilloscope_app.png new file mode 100644 index 0000000..99e82b5 Binary files /dev/null and b/test/iio-oscilloscope/ref_test_open_adi_iio_oscilloscope_app.png differ diff --git a/test/iio-oscilloscope/ref_test_run_button.png b/test/iio-oscilloscope/ref_test_run_button.png new file mode 100644 index 0000000..a78af02 Binary files /dev/null and b/test/iio-oscilloscope/ref_test_run_button.png differ diff --git a/test/iio-oscilloscope/results/test_checkbox_button.png b/test/iio-oscilloscope/results/test_checkbox_button.png new file mode 100644 index 0000000..5219f98 Binary files /dev/null and b/test/iio-oscilloscope/results/test_checkbox_button.png differ diff --git a/test/iio-oscilloscope/results/test_open_adi_iio_oscilloscope-capture1_app.png b/test/iio-oscilloscope/results/test_open_adi_iio_oscilloscope-capture1_app.png new file mode 100644 index 0000000..144438d Binary files /dev/null and b/test/iio-oscilloscope/results/test_open_adi_iio_oscilloscope-capture1_app.png differ diff --git a/test/iio-oscilloscope/results/test_open_adi_iio_oscilloscope_app.png b/test/iio-oscilloscope/results/test_open_adi_iio_oscilloscope_app.png new file mode 100644 index 0000000..c7ee19e Binary files /dev/null and b/test/iio-oscilloscope/results/test_open_adi_iio_oscilloscope_app.png differ diff --git a/test/iio-oscilloscope/results/test_run_button.png b/test/iio-oscilloscope/results/test_run_button.png new file mode 100644 index 0000000..88cb6fd Binary files /dev/null and b/test/iio-oscilloscope/results/test_run_button.png differ diff --git a/test/iio-oscilloscope/test_adi_oscilloscope.py b/test/iio-oscilloscope/test_adi_oscilloscope.py index 9d1dd17..2c10350 100644 --- a/test/iio-oscilloscope/test_adi_oscilloscope.py +++ b/test/iio-oscilloscope/test_adi_oscilloscope.py @@ -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") + \ No newline at end of file diff --git a/test/scopy/linux/conftest.py b/test/scopy/linux/conftest.py new file mode 100644 index 0000000..8f2cccf --- /dev/null +++ b/test/scopy/linux/conftest.py @@ -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") \ No newline at end of file diff --git a/test/scopy/linux/ref_test_open_appScopy.png b/test/scopy/linux/ref_test_open_appScopy.png new file mode 100644 index 0000000..8183025 Binary files /dev/null and b/test/scopy/linux/ref_test_open_appScopy.png differ diff --git a/test/scopy/linux/ref_test_open_scopy.png b/test/scopy/linux/ref_test_open_scopy.png new file mode 100644 index 0000000..1ee8c3e Binary files /dev/null and b/test/scopy/linux/ref_test_open_scopy.png differ diff --git a/test/scopy/linux/test_adi_scopy.py b/test/scopy/linux/test_adi_scopy.py new file mode 100644 index 0000000..d8879b1 --- /dev/null +++ b/test/scopy/linux/test_adi_scopy.py @@ -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) + + \ No newline at end of file