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

fix is_checked in uia_controls #1323

Open
wants to merge 2 commits into
base: atspi
Choose a base branch
from

Conversation

junkmd
Copy link
Contributor

@junkmd junkmd commented Aug 14, 2023

I noticed that the IUIAutomationTogglePattern assigned to iface_toggle does not have an attribute named ToggleState_On.

https://learn.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtogglepattern#methods

uia_controls.FooWrapper.is_checked have only been tested for cases where NoPatternInterfaceError raises, and there is no test that actually verifies if it is "toggled".

However, I believe it's not ideal to leave a situation where AttributeError is consistently occurring unaddressed, so I made the necessary corrections.

@codecov
Copy link

codecov bot commented Aug 15, 2023

Codecov Report

Merging #1323 (c4b49f1) into atspi (bf7f789) will decrease coverage by 6.32%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##            atspi    #1323      +/-   ##
==========================================
- Coverage   94.15%   87.83%   -6.32%     
==========================================
  Files          60       60              
  Lines       23036    23034       -2     
==========================================
- Hits        21689    20232    -1457     
- Misses       1347     2802    +1455     

Copy link
Contributor

@vasily-v-ryabov vasily-v-ryabov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! May I ask for adding such positive test case?

@junkmd
Copy link
Contributor Author

junkmd commented Aug 18, 2023

Hello! You are welcome!

Given my current knowledge, creating test cases to ensure the behavior of is_checked is difficult.
Apps like the existing WpfApplication1.exe used in the tests seem to have toggleable list items at first glance, but they actually raise a NoPatternInterfaceError.

wpf_app_1 = os.path.join(wpf_samples_folder, u"WpfApplication1.exe")

I believe there is a need to create a new test GUI App that includes ListItemWrapper and TreeItemWrapper which do not raise NoPatternInterfaceError.

@junkmd
Copy link
Contributor Author

junkmd commented Aug 18, 2023

To be honest, I didn't encounter this bug while working with the GUI.

I found this bug while investigating how pywinauto invokes COM methods, using the type-hinted comtypes.gen.UIAutomationClient from enthought/comtypes#490.

@junkmd
Copy link
Contributor Author

junkmd commented Aug 18, 2023

On the other hand, in ButtonWrapper, there is a get_toggle_state that returns iface_toggle.CurrentToggleState, and since the tests are passing, I am confident that CurrentToggleState is definitely a functioning property present in IUIAutomationTogglePattern.

def get_toggle_state(self):
"""
Get a toggle state of a check box control.
The toggle state is represented by an integer
0 - unchecked
1 - checked
2 - indeterminate
The following constants are defined in the uia_defines module
toggle_state_off = 0
toggle_state_on = 1
toggle_state_inderteminate = 2
"""
return self.iface_toggle.CurrentToggleState

def test_toggle_button(self):
"""Test 'toggle' and 'toggle_state' for the toggle button control"""
# Get a current state of the check box control
button = self.dlg.ToggleMe.find()
cur_state = button.get_toggle_state()
self.assertEqual(cur_state, uia_defs.toggle_state_on)
# Toggle the next state
cur_state = button.toggle().get_toggle_state()
# Get a new state of the check box control
self.assertEqual(cur_state, uia_defs.toggle_state_off)
# Toggle the next state
cur_state = button.toggle().get_toggle_state()
self.assertEqual(cur_state, uia_defs.toggle_state_on)

@junkmd
Copy link
Contributor Author

junkmd commented Aug 20, 2023

I thought preparing an actual GUI would incur significant testing costs.
Therefore, I added tests for is_checked using the patch approach, similar to what's done in other test cases in test_uiawrapper.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants