|
5 | 5 | import unittest as ut
|
6 | 6 |
|
7 | 7 | import comtypes.client
|
8 |
| -from comtypes import COSERVERINFO |
| 8 | +from comtypes import COSERVERINFO, CLSCTX_INPROC_SERVER |
9 | 9 |
|
10 | 10 | # create the typelib wrapper and import it
|
11 | 11 | comtypes.client.GetModule("scrrun.dll")
|
@@ -143,46 +143,55 @@ def test_clsid_string(self):
|
143 | 143 | comtypes.client.CreateObject(text_type(Scripting.Dictionary._reg_clsid_))
|
144 | 144 | comtypes.client.CreateObject(str(Scripting.Dictionary._reg_clsid_))
|
145 | 145 |
|
146 |
| - @ut.skip( |
147 |
| - "This test uses IE which is not available on all machines anymore. " |
148 |
| - "Find another API to use." |
149 |
| - ) |
150 | 146 | def test_remote(self):
|
151 |
| - ie = comtypes.client.CreateObject( |
152 |
| - "InternetExplorer.Application", machine="localhost" |
| 147 | + comtypes.client.GetModule("UIAutomationCore.dll") |
| 148 | + from comtypes.gen.UIAutomationClient import ( |
| 149 | + CUIAutomation, |
| 150 | + IUIAutomation, |
| 151 | + IUIAutomationElement, |
153 | 152 | )
|
154 |
| - self.assertEqual(ie.Visible, False) |
155 |
| - ie.Visible = 1 |
156 |
| - # on a remote machine, this may not work. Probably depends on |
157 |
| - # how the server is run. |
158 |
| - self.assertEqual(ie.Visible, True) |
159 |
| - self.assertEqual(0, ie.Quit()) # 0 == S_OK |
160 |
| - |
161 |
| - @ut.skip( |
162 |
| - "This test uses IE which is not available on all machines anymore. " |
163 |
| - "Find another API to use." |
164 |
| - ) |
| 153 | + |
| 154 | + iuia = comtypes.client.CreateObject( |
| 155 | + CUIAutomation().IPersist_GetClassID(), |
| 156 | + interface=IUIAutomation, |
| 157 | + clsctx=CLSCTX_INPROC_SERVER, |
| 158 | + machine="localhost", |
| 159 | + ) |
| 160 | + self.assertIsInstance(iuia, POINTER(IUIAutomation)) |
| 161 | + self.assertIsInstance(iuia, IUIAutomation) |
| 162 | + self.assertIsInstance(iuia.GetRootElement(), POINTER(IUIAutomationElement)) |
| 163 | + self.assertIsInstance(iuia.GetRootElement(), IUIAutomationElement) |
| 164 | + |
165 | 165 | def test_server_info(self):
|
| 166 | + comtypes.client.GetModule("UIAutomationCore.dll") |
| 167 | + from comtypes.gen.UIAutomationClient import ( |
| 168 | + CUIAutomation, |
| 169 | + IUIAutomation, |
| 170 | + IUIAutomationElement, |
| 171 | + ) |
| 172 | + |
166 | 173 | serverinfo = COSERVERINFO()
|
167 | 174 | serverinfo.pwszName = "localhost"
|
168 | 175 | pServerInfo = byref(serverinfo)
|
169 |
| - |
170 |
| - self.assertRaises( |
171 |
| - ValueError, |
172 |
| - comtypes.client.CreateObject, |
173 |
| - "InternetExplorer.Application", |
174 |
| - machine="localhost", |
| 176 | + with self.assertRaises(ValueError): |
| 177 | + # cannot set both the machine name and server info |
| 178 | + comtypes.client.CreateObject( |
| 179 | + CUIAutomation().IPersist_GetClassID(), |
| 180 | + interface=IUIAutomation, |
| 181 | + clsctx=CLSCTX_INPROC_SERVER, |
| 182 | + machine="localhost", |
| 183 | + pServerInfo=pServerInfo, |
| 184 | + ) |
| 185 | + iuia = comtypes.client.CreateObject( |
| 186 | + CUIAutomation().IPersist_GetClassID(), |
| 187 | + interface=IUIAutomation, |
| 188 | + clsctx=CLSCTX_INPROC_SERVER, |
175 | 189 | pServerInfo=pServerInfo,
|
176 | 190 | )
|
177 |
| - ie = comtypes.client.CreateObject( |
178 |
| - "InternetExplorer.Application", pServerInfo=pServerInfo |
179 |
| - ) |
180 |
| - self.assertEqual(ie.Visible, False) |
181 |
| - ie.Visible = 1 |
182 |
| - # on a remote machine, this may not work. Probably depends on |
183 |
| - # how the server is run. |
184 |
| - self.assertEqual(ie.Visible, True) |
185 |
| - self.assertEqual(0, ie.Quit()) # 0 == S_OK |
| 191 | + self.assertIsInstance(iuia, POINTER(IUIAutomation)) |
| 192 | + self.assertIsInstance(iuia, IUIAutomation) |
| 193 | + self.assertIsInstance(iuia.GetRootElement(), POINTER(IUIAutomationElement)) |
| 194 | + self.assertIsInstance(iuia.GetRootElement(), IUIAutomationElement) |
186 | 195 |
|
187 | 196 |
|
188 | 197 | class Test_Constants(ut.TestCase):
|
|
0 commit comments