本文整理汇总了Python中pywinauto.application.Application类的典型用法代码示例。如果您正苦于以下问题:Python Application类的具体用法?Python Application怎么用?Python Application使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Application类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: NotepadRegressionTests
class NotepadRegressionTests(unittest.TestCase):
"Regression unit tests for Notepad"
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
# start the application
self.app = Application()
self.app.start_(_notepad_exe())
self.dlg = self.app.Window_(title='Untitled - Notepad', class_name='Notepad')
self.ctrl = HwndWrapper(self.dlg.Edit.handle)
self.dlg.edit.SetEditText("Here is some text\r\n and some more")
self.app2 = Application.start(_notepad_exe())
def tearDown(self):
"Close the application after tests"
# close the application
try:
self.dlg.Close(0.5)
if self.app.Notepad["Do&n't Save"].Exists():
self.app.Notepad["Do&n't Save"].Click()
self.app.Notepad["Do&n't Save"].WaitNot('visible')
except Exception: # timings.TimeoutError:
pass
finally:
self.app.kill_()
self.app2.kill_()
def testMenuSelectNotepad_bug(self):
"In notepad - MenuSelect Edit->Paste did not work"
text = b'Here are some unicode characters \xef\xfc\r\n'
self.app2.UntitledNotepad.Edit.Wait('enabled')
time.sleep(0.3)
self.app2.UntitledNotepad.Edit.SetEditText(text)
time.sleep(0.3)
self.assertEquals(self.app2.UntitledNotepad.Edit.TextBlock().encode(locale.getpreferredencoding()), text)
Timings.after_menu_wait = .7
self.app2.UntitledNotepad.MenuSelect("Edit->Select All")
time.sleep(0.3)
self.app2.UntitledNotepad.MenuSelect("Edit->Copy")
time.sleep(0.3)
self.assertEquals(clipboard.GetData().encode(locale.getpreferredencoding()), text)
self.dlg.SetFocus()
self.dlg.MenuSelect("Edit->Select All")
self.dlg.MenuSelect("Edit->Paste")
self.dlg.MenuSelect("Edit->Paste")
self.dlg.MenuSelect("Edit->Paste")
self.app2.UntitledNotepad.MenuSelect("File->Exit")
self.app2.Window_(title='Notepad', class_name='#32770')["Don't save"].Click()
self.assertEquals(self.dlg.Edit.TextBlock().encode(locale.getpreferredencoding()), text*3)
开发者ID:papa3ggplant,项目名称:pywinauto,代码行数:60,代码来源:test_HwndWrapper.py
示例2: RemoteMemoryBlockTests
class RemoteMemoryBlockTests(unittest.TestCase):
"Unit tests for RemoteMemoryBlock"
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
# start the application
self.app = Application()
self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe"))
self.dlg = self.app.Common_Controls_Sample
self.ctrl = self.dlg.TreeView.WrapperObject()
def tearDown(self):
"Close the application after tests"
self.app.kill_()
def testGuardSignatureCorruption(self):
mem = RemoteMemoryBlock(self.ctrl, 16)
buf = ctypes.create_string_buffer(24)
self.assertRaises(Exception, mem.Write, buf)
mem.size = 24 # test hack
self.assertRaises(Exception, mem.Write, buf)
开发者ID:gitter-badger,项目名称:pywinauto,代码行数:26,代码来源:test_HwndWrapper.py
示例3: testGetitem
def testGetitem(self):
"Test that __getitem__() works correctly"
app = Application()
app.start(_notepad_exe())
try:
app['blahblah']
except Exception:
pass
#prev_timeout = application.window_find_timeout
#application.window_find_timeout = .1
self.assertRaises(
findbestmatch.MatchError,
app['blahblah']['not here'].__getitem__, 'handle')
self.assertEqual(
app[u'Unt\xeftledNotepad'].handle,
app.window_(title = "Untitled - Notepad").handle)
app.UntitledNotepad.MenuSelect("Help->About Notepad")
self.assertEqual(
app['AboutNotepad'].handle,
app.window_(title = "About Notepad").handle)
app.AboutNotepad.Ok.Click()
app.UntitledNotepad.MenuSelect("File->Exit")
开发者ID:nnamon,项目名称:pywinauto,代码行数:29,代码来源:test_application.py
示例4: setUp
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
# start the application
from pywinauto.application import Application
app = Application()
app.start_(os.path.join(mfc_samples_folder, "RowList.exe"), timeout=20)
self.texts = [u"Color", u"Red", u"Green", u"Blue", u"Hue", u"Sat", u"Lum", u"Type"]
self.item_rects = [
RECT(0, 0, 150, 19),
RECT(150, 0, 200, 19),
RECT(200, 0, 250, 19),
RECT(250, 0, 300, 19),
RECT(300, 0, 400, 19),
RECT(400, 0, 450, 19),
RECT(450, 0, 500, 19),
RECT(500, 0, 650, 19),
]
self.app = app
self.dlg = app.RowListSampleApplication # top_window_()
self.ctrl = app.RowListSampleApplication.Header.WrapperObject()
开发者ID:softandbyte,项目名称:pywinauto,代码行数:25,代码来源:test_common_controls.py
示例5: ControlStateTests
class ControlStateTests(unittest.TestCase):
"""Unit tests for control states"""
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
self.app = Application()
self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl1.exe"))
self.dlg = self.app.Common_Controls_Sample
self.dlg.TabControl.Select(4)
self.ctrl = self.dlg.EditBox.WrapperObject()
def tearDown(self):
"""Close the application after tests"""
self.app.kill_()
def test_VerifyEnabled(self):
"""test for verify_enabled"""
self.assertRaises(ElementNotEnabled, self.ctrl.verify_enabled)
def test_VerifyVisible(self):
"""test for verify_visible"""
self.dlg.TabControl.Select(3)
self.assertRaises(ElementNotVisible, self.ctrl.verify_visible)
开发者ID:MagazinnikIvan,项目名称:pywinauto,代码行数:27,代码来源:test_hwndwrapper.py
示例6: GetDialogPropsFromHandleTest
class GetDialogPropsFromHandleTest(unittest.TestCase):
"""Unit tests for mouse actions of the HwndWrapper class"""
def setUp(self):
"""Set some data and ensure the application is in the state we want"""
Timings.Fast()
self.app = Application()
self.app.start(_notepad_exe())
self.dlg = self.app.UntitledNotepad
self.ctrl = HwndWrapper(self.dlg.Edit.handle)
def tearDown(self):
"""Close the application after tests"""
# close the application
#self.dlg.type_keys("%{F4}")
self.dlg.Close(0.5)
self.app.kill_()
def test_GetDialogPropsFromHandle(self):
"""Test some small stuff regarding GetDialogPropsFromHandle"""
props_from_handle = GetDialogPropsFromHandle(self.dlg.handle)
props_from_dialog = GetDialogPropsFromHandle(self.dlg)
#unused var: props_from_ctrl = GetDialogPropsFromHandle(self.ctrl)
self.assertEquals(props_from_handle, props_from_dialog)
开发者ID:MagazinnikIvan,项目名称:pywinauto,代码行数:29,代码来源:test_hwndwrapper.py
示例7: setUp
def setUp(self):
"""Set some data and ensure the application is in the state we want"""
Timings.Fast()
self.app = Application()
self.app.start(os.path.join(mfc_samples_folder, u"CmnCtrl3.exe"))
self.app2 = Application().start(_notepad_exe())
开发者ID:MagazinnikIvan,项目名称:pywinauto,代码行数:7,代码来源:test_hwndwrapper.py
示例8: setUp
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
# start the application
from pywinauto.application import Application
app = Application()
app.start_(controlspy_folder + "Tab.exe")
self.texts = [
"Pluto", "Neptune", "Uranus",
"Saturn", "Jupiter", "Mars",
"Earth", "Venus", "Mercury", "Sun"]
self.rects = [
RECT(2,2,80,21),
RECT(80,2,174,21),
RECT(174,2,261,21),
RECT(2,21,91,40),
RECT(91,21,180,40),
RECT(180,21,261,40),
RECT(2,40,64,59),
RECT(64,40,131,59),
RECT(131,40,206,59),
RECT(206,40,261,59),
]
self.app = app
self.dlg = app.MicrosoftControlSpy
self.ctrl = app.MicrosoftControlSpy.TabControl.WrapperObject()
开发者ID:CompMike,项目名称:BrowserRefresh-Sublime,代码行数:30,代码来源:test_common_controls.py
示例9: SendKeysToAllWindows
def SendKeysToAllWindows(self, title_regex):
"Sends the keystroke to all windows whose title matches the regex"
# We need to call find_windows on our own because Application.connect_ will
# call find_window and throw if it finds more than one match.
all_matches = pywinauto.findwindows.find_windows(title_re=title_regex)
# We need to store all window handles that have been sent keys in order
# to avoid reactivating windows and doing unnecesary refreshes. This is a
# side effect of having to call Application.connect_ on each regex match.
# We need to loop through each open window collection to support edge
# cases like Google Canary where the Window title is identical to Chrome.
processed_handles = []
for win in all_matches:
app = Application()
app.connect_(handle=win)
open_windows = app.windows_(title_re=title_regex)
for openwin in open_windows:
if openwin.handle in processed_handles:
continue
openwin.TypeKeys("{F5}")
processed_handles.append(openwin.handle)
time.sleep(1)
开发者ID:Web5design,项目名称:BrowserRefresh-Sublime,代码行数:26,代码来源:__init__.py
示例10: GetDialogPropsFromHandleTest
class GetDialogPropsFromHandleTest(unittest.TestCase):
"Unit tests for mouse actions of the HwndWrapper class"
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
# start the application
self.app = Application()
self.app.start_("notepad.exe")
self.dlg = self.app.UntitledNotepad
self.ctrl = HwndWrapper(self.dlg.Edit.handle)
def tearDown(self):
"Close the application after tests"
# close the application
self.dlg.TypeKeys("%{F4}")
def test_GetDialogPropsFromHandle(self):
"Test some small stuff regarding GetDialogPropsFromHandle"
props_from_handle = GetDialogPropsFromHandle(self.dlg.handle)
props_from_dialog = GetDialogPropsFromHandle(self.dlg)
props_from_ctrl = GetDialogPropsFromHandle(self.ctrl)
self.assertEquals(props_from_handle, props_from_dialog)
开发者ID:CompMike,项目名称:BrowserRefresh-Sublime,代码行数:30,代码来源:test_HwndWrapper.py
示例11: setUp
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
# start the application
from pywinauto.application import Application
app = Application()
import os.path
path = os.path.split(__file__)[0]
test_file = os.path.join(path, "test.txt")
with codecs.open(test_file, mode="rb", encoding='utf-8') as f:
self.test_data = f.read()
# remove the BOM if it exists
self.test_data = self.test_data.replace(repr("\xef\xbb\xbf"), "")
#self.test_data = self.test_data.encode('utf-8', 'ignore') # XXX: decode raises UnicodeEncodeError even if 'ignore' is used!
print('self.test_data:')
print(self.test_data.encode('utf-8', 'ignore'))
app.start_("Notepad.exe " + test_file, timeout=20)
self.app = app
self.dlg = app.UntitledNotepad
self.ctrl = self.dlg.Edit.WrapperObject()
self.old_pos = self.dlg.Rectangle
self.dlg.MoveWindow(10, 10, 400, 400)
开发者ID:claudioRcarvalho,项目名称:pywinauto,代码行数:30,代码来源:test_win32controls.py
示例12: ButtonOwnerdrawTestCases
class ButtonOwnerdrawTestCases(unittest.TestCase):
"""Unit tests for the ButtonWrapper(ownerdraw button)"""
def setUp(self):
"""Start the sample application. Open a tab with ownerdraw button."""
# start the application
self.app = Application().Start(os.path.join(mfc_samples_folder, u"CmnCtrl3.exe"))
# open the needed tab
self.app.active_().TabControl.Select(1)
def tearDown(self):
"""Close the application after tests"""
self.app.kill_()
def test_NeedsImageProp(self):
"""test whether an image needs to be saved with the properties"""
active_window = self.app.active_()
self.assertEquals(active_window.Button2._NeedsImageProp, True)
self.assertIn('Image', active_window.Button2.GetProperties())
开发者ID:claudioRcarvalho,项目名称:pywinauto,代码行数:26,代码来源:test_win32controls.py
示例13: _toggle_notification_area_icons
def _toggle_notification_area_icons(show_all=True, debug_img=None):
"""
A helper function to change 'Show All Icons' settings.
On a succesful execution the function returns an original
state of 'Show All Icons' checkbox.
The helper works only for an "English" version of Windows,
on non-english versions of Windows the 'Notification Area Icons'
window should be accessed with a localized title"
"""
app = Application()
starter = app.start(r'explorer.exe')
class_name = 'CabinetWClass'
def _cabinetwclass_exist():
"Verify if at least one active 'CabinetWClass' window is created"
l = findwindows.find_windows(active_only=True, class_name=class_name)
return (len(l) > 0)
WaitUntil(30, 0.5, _cabinetwclass_exist)
handle = findwindows.find_windows(active_only=True,
class_name=class_name)[-1]
window = WindowSpecification({'handle': handle, })
explorer = Application().Connect(process=window.ProcessID())
cur_state = None
try:
# Go to "Control Panel -> Notification Area Icons"
window.AddressBandRoot.ClickInput()
window.TypeKeys(
r'control /name Microsoft.NotificationAreaIcons{ENTER}',
with_spaces=True,
set_foreground=False)
explorer.WaitCPUUsageLower(threshold=5, timeout=40)
# Get the new opened applet
notif_area = explorer.Window_(title="Notification Area Icons",
class_name=class_name)
cur_state = notif_area.CheckBox.GetCheckState()
# toggle the checkbox if it differs and close the applet
if bool(cur_state) != show_all:
notif_area.CheckBox.ClickInput()
notif_area.Ok.ClickInput()
explorer.WaitCPUUsageLower(threshold=5, timeout=40)
except Exception as e:
if debug_img:
from PIL import ImageGrab
ImageGrab.grab().save("%s.jpg" % (debug_img), "JPEG")
l = pywinauto.actionlogger.ActionLogger()
l.log("RuntimeError in _toggle_notification_area_icons")
raise e
finally:
# close the explorer window
window.Close()
return cur_state
开发者ID:programmdesign,项目名称:pywinauto,代码行数:60,代码来源:test_taskbar.py
示例14: setUp
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
# start the application
from pywinauto.application import Application
app = Application()
app.start_(os.path.join(controlspy_folder, "Tree View.exe"))
self.root_text = "The Planets"
self.texts = [
("Mercury", '57,910,000', '4,880', '3.30e23'),
("Venus", '108,200,000', '12,103.6', '4.869e24'),
("Earth", '149,600,000', '12,756.3', '5.9736e24'),
("Mars", '227,940,000', '6,794', '6.4219e23'),
("Jupiter", '778,330,000', '142,984', '1.900e27'),
("Saturn", '1,429,400,000', '120,536', '5.68e26'),
("Uranus", '2,870,990,000', '51,118', '8.683e25'),
("Neptune", '4,504,000,000', '49,532', '1.0247e26'),
("Pluto", '5,913,520,000', '2,274', '1.27e22'),
]
self.app = app
self.dlg = app.MicrosoftControlSpy #top_window_()
self.ctrl = app.MicrosoftControlSpy.TreeView.WrapperObject()
开发者ID:vasily-v-ryabov,项目名称:pywinauto-64,代码行数:25,代码来源:test_common_controls.py
示例15: setUp
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
# start the application
from pywinauto.application import Application
app = Application()
import os.path
path = os.path.split(__file__)[0]
test_file = os.path.join(path, "test.txt")
self.test_data = open(test_file, "rb").read()
# remove the BOM if it exists
self.test_data = self.test_data.replace("\xef\xbb\xbf", "")
self.test_data = self.test_data.decode('utf-8')
app.start_("Notepad.exe " + test_file)
self.app = app
self.dlg = app.UntitledNotepad
self.ctrl = self.dlg.Edit.WrapperObject()
self.old_pos = self.dlg.Rectangle
self.dlg.MoveWindow(10, 10, 400, 400)
开发者ID:CompMike,项目名称:BrowserRefresh-Sublime,代码行数:27,代码来源:test_win32controls.py
示例16: setUp
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
self.texts = [u'', u'New', u'Open', u'Save', u'Cut', u'Copy', u'Paste', u'Print', u'About', u'Help']
# start the application
from pywinauto.application import Application
app = Application()
app.start_(os.path.join(mfc_samples_folder, "CmnCtrl1.exe"))
#app.start_(os.path.join(controlspy_folder, "Tooltip.exe"))
self.app = app
self.dlg = app.Common_Controls_Sample
self.dlg.TabControl.Select(u'CToolBarCtrl')
'''
tips = app.windows_(
visible_only = False,
enabled_only = False,
top_level_only = False,
class_name = "tooltips_class32")
'''
self.ctrl = self.dlg.Toolbar.GetToolTipsControl() #WrapHandle(tips[1])
开发者ID:overr1de,项目名称:pywinauto,代码行数:26,代码来源:test_common_controls.py
示例17: test_is64bitprocess
def test_is64bitprocess(self):
"Make sure a 64-bit process detection returns correct results"
if is_x64_OS():
# Test a 32-bit app running on x64
expected_is64bit = False
if is_x64_Python():
exe32bit = os.path.join(os.path.dirname(__file__),
r"..\..\apps\MFC_samples\RowList.exe")
app = Application().start_(exe32bit, timeout=20)
pid = app.RowListSampleApplication.ProcessID()
res_is64bit = is64bitprocess(pid)
try:
self.assertEquals(expected_is64bit, res_is64bit)
finally:
# make sure to close an additional app we have opened
app.kill_()
# setup expected for a 64-bit app on x64
expected_is64bit = True
else:
# setup expected for a 32-bit app on x86
expected_is64bit = False
# test native Notepad app
res_is64bit = is64bitprocess(self.app.UntitledNotepad.ProcessID())
self.assertEquals(expected_is64bit, res_is64bit)
开发者ID:softandbyte,项目名称:pywinauto,代码行数:27,代码来源:test_handleprops.py
示例18: ClipboardTestCases
class ClipboardTestCases(unittest.TestCase):
"Unit tests for the clipboard"
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
EmptyClipboard()
self.app1 = Application().start("notepad.exe")
self.app2 = Application().start("notepad.exe")
self.app1.UntitledNotepad.MoveWindow(RECT(0, 0, 200, 200))
self.app2.UntitledNotepad.MoveWindow(RECT(0, 200, 200, 400))
def tearDown(self):
"Close the application after tests"
# close the application
self.app1.UntitledNotepad.MenuSelect('File -> Exit')
if self.app1.Notepad["Do&n't Save"].Exists():
self.app1.Notepad["Do&n't Save"].Click()
self.app1.kill_()
self.app2.UntitledNotepad.MenuSelect('File -> Exit')
if self.app2.Notepad["Do&n't Save"].Exists():
self.app2.Notepad["Do&n't Save"].Click()
self.app2.kill_()
def testGetClipBoardFormats(self):
typetext(self.app1, "here we are")
copytext(self.app1)
self.assertEquals(GetClipboardFormats(), [13, 16, 1, 7])
def testGetFormatName(self):
typetext(self.app1, "here we are")
copytext(self.app1)
self.assertEquals(
[GetFormatName(f) for f in GetClipboardFormats()],
['CF_UNICODETEXT', 'CF_LOCALE', 'CF_TEXT', 'CF_OEMTEXT']
)
def testBug1452832(self):
"""Failing test for sourceforge bug 1452832
Where GetData was not closing the clipboard. FIXED.
"""
self.app1.UntitledNotepad.MenuSelect("Edit->Select All Ctrl+A")
typetext(self.app1, "some text")
copytext(self.app1)
# was not closing the clipboard!
data = GetData()
self.assertEquals(data, "some text")
self.assertEquals(gettext(self.app2), "")
pastetext(self.app2)
self.assertEquals(gettext(self.app2), "some text")
开发者ID:Anton-Lazarev,项目名称:pywinauto,代码行数:60,代码来源:test_clipboard.py
示例19: testClickCustomizeButton
def testClickCustomizeButton(self):
"Test click on the 'show hidden icons' button"
# Minimize to tray
self.dlg.Minimize()
self.dlg.WaitNot("active")
# Make sure that the hidden icons area is enabled
orig_hid_state = _toggle_notification_area_icons(show_all=False, debug_img="%s_01.jpg" % (self.id()))
# Run one more instance of the sample app
# hopefully one of the icons moves into the hidden area
app2 = Application()
app2.start_(os.path.join(mfc_samples_folder, u"TrayMenu.exe"))
dlg2 = app2.TrayMenu
dlg2.Wait("visible")
dlg2.Minimize()
dlg2.WaitNot("active")
# Test click on "Show Hidden Icons" button
taskbar.ShowHiddenIconsButton.ClickInput()
niow_dlg = taskbar.explorer_app.Window_(class_name="NotifyIconOverflowWindow")
niow_dlg.OverflowNotificationAreaToolbar.Wait("ready", timeout=30)
niow_dlg.SysLink.ClickInput()
nai = taskbar.explorer_app.Window_(title="Notification Area Icons", class_name="CabinetWClass")
origAlwaysShow = nai.CheckBox.GetCheckState()
if not origAlwaysShow:
nai.CheckBox.ClickInput()
nai.OK.Click()
# Restore Notification Area settings
_toggle_notification_area_icons(show_all=orig_hid_state, debug_img="%s_02.jpg" % (self.id()))
# close the second sample app
dlg2.SendMessage(win32defines.WM_CLOSE)
开发者ID:funoffan,项目名称:pywinauto,代码行数:35,代码来源:test_taskbar.py
示例20: SendKeysModifiersTests
class SendKeysModifiersTests(unittest.TestCase):
"Unit tests for the Sendkeys module (modifiers)"
def setUp(self):
"""Start the application set some data and ensure the application
is in the state we want it."""
self.app = Application().start(os.path.join(mfc_samples_folder, u"CtrlTest.exe"))
self.dlg = self.app.Control_Test_App
def tearDown(self):
"Close the application after tests"
try:
self.dlg.Close(0.5)
except Exception:
pass
finally:
self.app.kill_()
def testModifiersForFewChars(self):
"Make sure that repeated action works"
SendKeys("%(SC)", pause = .3)
dlg = self.app.Window_(title='Using C++ Derived Class')
dlg.Wait('ready')
dlg.Done.CloseClick()
dlg.WaitNot('visible')
SendKeys("%(H{LEFT}{UP}{ENTER})", pause = .3)
dlg = self.app.Window_(title='Sample Dialog with spin controls')
dlg.Wait('ready')
dlg.Done.CloseClick()
dlg.WaitNot('visible')
开发者ID:2nty7vn,项目名称:pywinauto,代码行数:32,代码来源:test_SendKeys.py
注:本文中的pywinauto.application.Application类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论