From f0910457ffd2eaf135e0deb301ace4f87fd1e816 Mon Sep 17 00:00:00 2001 From: Pedro de Oliveira Guedes Date: Wed, 26 Jan 2022 17:14:31 -0300 Subject: [PATCH] Adding tests to window methods. --- api/wingui/features/steps/steps.py | 65 +++++++++++++++++++++++++++++- api/wingui/features/wingui.feature | 26 +++++++++++- 2 files changed, 89 insertions(+), 2 deletions(-) diff --git a/api/wingui/features/steps/steps.py b/api/wingui/features/steps/steps.py index 488dfe9..2094839 100644 --- a/api/wingui/features/steps/steps.py +++ b/api/wingui/features/steps/steps.py @@ -1,3 +1,4 @@ +from time import sleep from behave import * from cli import Wingui @@ -90,4 +91,66 @@ def step_impl(context): def step_impl(context): assert context.proc_pid in context.all_pids, "Something went wrong catching all of the pids." - context.client.proc_kill(context.proc_pid) \ No newline at end of file + context.client.proc_kill(context.proc_pid) + + + +# =========================== Window_list and Window_hwnd =========================== +@when(u'the window_hwnd method is called with the parameter "mspaint.exe"') +def step_impl(context): + sleep(0.5) + context.paint_hwnd = context.client.window_hwnd("mspaint.exe") + +@when(u'the window_list method is called') +def step_impl(context): + context.windows = context.client.window_list() + +@then(u'the return of window_hwnd must be the value of one of the "Hwnd" keys returned in window_list') +def step_impl(context): + for window in context.windows: + if context.paint_hwnd[0] == window["Hwnd"]: + assert True + sleep(0.5) + context.client.proc_kill(context.proc_pid) + + return + + assert False, "Something went wrong catching the Paint window." + + + +# # =================== Window_activate, Window_activetitle and Window_activehwnd =================== +# @given(u'the window hwnd obtained from the "Name" info') +# def step_impl(context): +# context.paint_hwnd = context.client.window_hwnd(context.proc_name) + +# @when(u'the window_activate method is called with the Paint Hwnd obtained') +# def step_impl(context): +# sleep(0.5) +# context.client.window_activate (context.paint_hwnd[0]) +# sleep(0.5) + +# @when(u'the methods window_activetitle and window_activehwnd are called') +# def step_impl(context): +# context.paint_title = context.client.window_activetitle() +# context.paint_win_hwnd = context.client.window_activehwnd() + +# context.client.window_close(context.paint_hwnd[0]) + +# @then(u'the returned value from window_activetitle must contain the substring "Paint"') +# def step_impl(context): +# assert "Paint" in context.paint_title, f"The active title obtained is not from Paint.\nActive Title: {context.paint_title}" + +# for window in context.client.window_list(): +# if context.paint_hwnd == window["Hwnd"]: +# print(f""" + +# --------------------------- +# Hwnd associated title: {window["Title"]} +# --------------------------- + +# """) + +# @then(u'the returned value from window_activehwnd must be equal to the hwnd previously obtained') +# def step_impl(context): +# assert context.paint_win_hwnd == context.paint_hwnd, "The Hwnd obtained is not from Paint" \ No newline at end of file diff --git a/api/wingui/features/wingui.feature b/api/wingui/features/wingui.feature index 29f94ca..e9c627a 100644 --- a/api/wingui/features/wingui.feature +++ b/api/wingui/features/wingui.feature @@ -36,4 +36,28 @@ Feature: The winGUI API client And the initialization of Microsoft Paint And the "Name" and "Pid" infos about this process When the proc_pids is called - Then the "Pid" info collected must be inside the array returned \ No newline at end of file + Then the "Pid" info collected must be inside the array returned + + + Scenario: Testing the window_list and window_hwnd methods + Given a winGUI client + And the initialization of Microsoft Paint + And the "Name" and "Pid" infos about this process + + When the window_hwnd method is called with the parameter "mspaint.exe" + And the window_list method is called + + Then the return of window_hwnd must be the value of one of the "Hwnd" keys returned in window_list + + + # Scenario: Testing window_activate, window_activetitle and window_activehwnd + # Given a winGUI client + # And the initialization of Microsoft Paint + # And the "Name" and "Pid" infos about this process + # And the window hwnd obtained from the "Name" info + + # When the window_activate method is called with the Paint Hwnd obtained + # And the methods window_activetitle and window_activehwnd are called + + # Then the returned value from window_activetitle must contain the substring "Paint" + # And the returned value from window_activehwnd must be equal to the hwnd previously obtained \ No newline at end of file