I had the opportunity to write a simple automated test for a legacy Windows application (Win32) using Windows Application Driver, so I summarized the environment construction and touch. I will. [^ 1]
First, before executing the script, start the Windows Application Driver from the command prompt. When it starts, it goes into a standby state.
c:\Program Files (x86)\Windows Application Driver>WinAppDriver.exe
Windows Application Driver listening for requests at: http://127.0.0.1:4723/
Press ENTER to exit.
For the time being, I tried to move it and searched for a sample, but it only works with an English UI: frowning2: For this reason, I wrote the flow of starting and closing Notepad and saving it.
wda_test.py
import unittest
import os
import time
from appium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common import exceptions
save_file = "c:\\temp\\test.txt"
def remove_save_file():
if os.path.exists(save_file):
os.remove(save_file)
class WindowsApplicationDriverTests(unittest.TestCase):
@classmethod
def setUpClass(self):
remove_save_file()
desired_caps = {}
desired_caps["app"] = r"C:\Windows\System32\notepad.exe"
self.driver = webdriver.Remote(
command_executor='http://127.0.0.1:4723',
desired_capabilities= desired_caps)
@classmethod
def tearDownClass(self):
remove_save_file()
self.driver.quit()
def test_edit_and_close_with_save(self):
#Character input
self.driver.find_element_by_class_name("Notepad").send_keys("abcdefg")
#Notepad exit instructions
self.driver.find_element_by_class_name("Notepad").send_keys(Keys.ALT, Keys.F4)
#Wait for the save confirmation message to be displayed and press the save button
time.sleep(1)
self.driver.find_element_by_name("save(S)").send_keys(Keys.ENTER)
#Waiting for the Save As dialog to appear
time.sleep(3)
#Enter the file name
self.driver.find_element_by_name("save as").send_keys(save_file)
#Press the save button
self.driver.find_element_by_name("Save(S)").send_keys(Keys.ENTER)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(WindowsApplicationDriverTests)
unittest.TextTestRunner(verbosity=2).run(suite)
Please note that if you do not wait for the message or dialog to be displayed, the operation may not be performed as expected. You can see that Notepad runs automatically when you run the script as shown below.
python wad_test.py
[^ 1]: As a result of writing, it seems that it ended at the reference site: severe:
Recommended Posts