microsoft / WinAppDriver

Windows Application Driver
MIT License
3.7k stars 1.41k forks source link

what's problem? how to use winappdriver in python. calculator automation #1931

Open YeonwooJeong opened 1 year ago

YeonwooJeong commented 1 year ago

0

I don't know what the hell's wrong. Why doesn't it work?

this is error message

and when I used to "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App" same problem too

====================================================================== ERROR: setUpClass (main.SimpleCalculatorTests) Traceback (most recent call last): File "F:\자동화\WinAppDriver-master\Samples\Python\calculatortest.py", line 29, in setUpClass self.driver = webdriver.Remote( ^^^^^^^^^^^^^^^^^ File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\appium\webdriver\webdriver.py", line 257, in init super().init( File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 206, in init self.start_session(capabilities) File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\appium\webdriver\webdriver.py", line 346, in start_session response = self.execute(RemoteCommand.NEW_SESSION, w3c_caps) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\remote\webdriver.py", line 345, in execute self.error_handler.check_response(response) File "C:\Users\USER\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: Bad capabilities. Specify either app or appTopLevelWindow to create a session

` import unittest from appium import webdriver

class SimpleCalculatorTests(unittest.TestCase):

@classmethod

def setUpClass(self):
    #set up appium
    desired_caps = {}
    desired_caps["app"] = "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App"
    self.driver = webdriver.Remote(
        command_executor='http://127.0.0.1:4723',
        desired_capabilities= desired_caps)

@classmethod
def tearDownClass(self):
    self.driver.quit()

def getresults(self):
    displaytext = self.driver.find_element_by_accessibility_id("CalculatorResults").text
    displaytext = displaytext.strip("Display is " )
    displaytext = displaytext.rstrip(' ')
    displaytext = displaytext.lstrip(' ')
    return displaytext

def test_initialize(self):
    self.driver.find_element_by_name("지우기").click()
    self.driver.find_element_by_name("7").click()
    self.assertEqual(self.getresults(),"7")
    self.driver.find_element_by_name("지우기").click()

def test_addition(self):
    self.driver.find_element_by_name("1").click()
    self.driver.find_element_by_name("양의 값").click()
    self.driver.find_element_by_name("7").click()
    self.driver.find_element_by_name("일치").click()
    self.assertEqual(self.getresults(),"8")

def test_combination(self):
    self.driver.find_element_by_name("7").click()
    self.driver.find_element_by_name("곱").click()
    self.driver.find_element_by_name("9").click()
    self.driver.find_element_by_name("양의 값").click()
    self.driver.find_element_by_name("1").click()
    self.driver.find_element_by_name("일치").click()
    self.driver.find_element_by_name("나누기").click()
    self.driver.find_element_by_name("8").click()
    self.driver.find_element_by_name("일치").click()
    self.assertEqual(self.getresults(),"8")

def test_division(self):
    self.driver.find_element_by_name("8").click()
    self.driver.find_element_by_name("8").click()
    self.driver.find_element_by_name("나누기").click()
    self.driver.find_element_by_name("1").click()
    self.driver.find_element_by_name("1").click()
    self.driver.find_element_by_name("일치").click()
    self.assertEqual(self.getresults(),"8")

def test_multiplication(self):
    self.driver.find_element_by_name("9").click()
    self.driver.find_element_by_name("곱").click()
    self.driver.find_element_by_name("9").click()
    self.driver.find_element_by_name("일치").click()
    self.assertEqual(self.getresults(),"81") 

def test_subtraction(self):
    self.driver.find_element_by_name("9").click()
    self.driver.find_element_by_name("음의 값").click()
    self.driver.find_element_by_name("1").click()
    self.driver.find_element_by_name("일치").click()
    self.assertEqual(self.getresults(),"8")

if name == 'main': suite = unittest.TestLoader().loadTestsFromTestCase(SimpleCalculatorTests) unittest.TextTestRunner(verbosity=2).run(suite) `

image image

anunay1 commented 1 year ago

you need to downgrade appium client and selenium to version3.

YeonwooJeong commented 1 year ago

you need to downgrade appium client and selenium to version3.

which is version number appium client?

status now

Another problem occurs in version 3. Version 4 also has a previous problem. What am I supposed to do?

Are you sure that winapp driver is available on python? I don't want to waste time like this..

image

anunay1 commented 1 year ago

Check ticket #1784

YeonwooJeong commented 1 year ago

Check ticket #1784

you means I shouldn't use winappdriver in python not yet?

anunay1 commented 1 year ago

Your call

YeonwooJeong commented 1 year ago

Your call

I checked your link. https://github.com/microsoft/WinAppDriver/issues/1784

Should it be updated so that python can work on the latest versions of selenium and appium?

anunay1 commented 1 year ago

Yes, but Microsoft is in deep slumber for this project as it's evident with 1k open issues

YeonwooJeong commented 1 year ago

that's too bad..I should give up on python.

daluu commented 1 year ago

Or use a different tool with python if you really like python. For example, with respect to calculator automation

https://github.com/daluu/AutoItDriverServer/blob/master/sample-code/calculator.py

https://github.com/daluu/AutoPyDriverServer/blob/master/sample-code/calculator_demo.py

calculator automation aside, there are other UI tools that should have python interface, or that you can use with python via IronPython for .NET based tools.

but not that the samples I provided were for older Windows back in Windows 7 or earlier. The locators might have changed for Windows 10+.