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

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

Open
YeonwooJeong opened this issue Aug 24, 2023 · 9 comments

Comments

@YeonwooJeong
Copy link

YeonwooJeong commented Aug 24, 2023

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
Copy link

anunay1 commented Aug 24, 2023

you need to downgrade appium client and selenium to version3.

@YeonwooJeong
Copy link
Author

YeonwooJeong commented Aug 25, 2023

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
Copy link

anunay1 commented Aug 25, 2023

Check ticket #1784

@YeonwooJeong
Copy link
Author

YeonwooJeong commented Aug 26, 2023

Check ticket #1784

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

@anunay1
Copy link

anunay1 commented Aug 26, 2023

Your call

@YeonwooJeong
Copy link
Author

YeonwooJeong commented Aug 26, 2023

Your call

I checked your link. #1784

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

@anunay1
Copy link

anunay1 commented Aug 26, 2023

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

@YeonwooJeong
Copy link
Author

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

@daluu
Copy link

daluu commented Sep 1, 2023

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+.

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

No branches or pull requests

3 participants