diff --git a/Samples/Python/calculatortest.py b/Samples/Python/calculatortest.py index da0f800c..2b318193 100644 --- a/Samples/Python/calculatortest.py +++ b/Samples/Python/calculatortest.py @@ -18,8 +18,7 @@ import unittest from appium import webdriver from appium.options.windows import WindowsOptions -from appium.webdriver.common.appiumby import AppiumBy - +from appium.webdriver.common.appiumby import AppiumBy as By class SimpleCalculatorTests(unittest.TestCase): @classmethod @@ -35,59 +34,59 @@ def tearDownClass(self): self.driver.quit() def getresults(self): - displaytext = self.driver.find_element(AppiumBy.ACCESSIBILITY_ID, "CalculatorResults").text - displaytext = displaytext.strip("Display is ") - displaytext = displaytext.rstrip(' ') - displaytext = displaytext.lstrip(' ') + displaytext = self.driver.find_element(By.ACCESSIBILITY_ID, "CalculatorResults").text + displaytext = displaytext.strip() + # Takes the last space character and deletes whole "Display is " text, more localization-compatible + displaytext = displaytext[displaytext.rindex(' ')+1::] return displaytext def test_initialize(self): - self.driver.find_element(AppiumBy.NAME, "Clear").click() - self.driver.find_element(AppiumBy.NAME, "Seven").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "clearButton").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num7Button").click() self.assertEqual(self.getresults(), "7") - self.driver.find_element(AppiumBy.NAME, "Clear").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "clearButton").click() def test_addition(self): - self.driver.find_element(AppiumBy.NAME, "One").click() - self.driver.find_element(AppiumBy.NAME, "Plus").click() - self.driver.find_element(AppiumBy.NAME, "Seven").click() - self.driver.find_element(AppiumBy.NAME, "Equals").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num1Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "plusButton").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num7Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "equalButton").click() self.assertEqual(self.getresults(), "8") def test_combination(self): - self.driver.find_element(AppiumBy.NAME, "Seven").click() - self.driver.find_element(AppiumBy.NAME, "Multiply by").click() - self.driver.find_element(AppiumBy.NAME, "Nine").click() - self.driver.find_element(AppiumBy.NAME, "Plus").click() - self.driver.find_element(AppiumBy.NAME, "One").click() - self.driver.find_element(AppiumBy.NAME, "Equals").click() - self.driver.find_element(AppiumBy.NAME, "Divide by").click() - self.driver.find_element(AppiumBy.NAME, "Eight").click() - self.driver.find_element(AppiumBy.NAME, "Equals").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num7Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "multiplyButton").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num9Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "plusButton").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num1Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "equalButton").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "divideButton").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num8Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "equalButton").click() self.assertEqual(self.getresults(), "8") def test_division(self): - self.driver.find_element(AppiumBy.NAME, "Eight").click() - self.driver.find_element(AppiumBy.NAME, "Eight").click() - self.driver.find_element(AppiumBy.NAME, "Divide by").click() - self.driver.find_element(AppiumBy.NAME, "One").click() - self.driver.find_element(AppiumBy.NAME, "One").click() - self.driver.find_element(AppiumBy.NAME, "Equals").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num8Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num8Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "divideButton").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num1Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num1Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "equalButton").click() self.assertEqual(self.getresults(), "8") def test_multiplication(self): - self.driver.find_element(AppiumBy.NAME, "Nine").click() - self.driver.find_element(AppiumBy.NAME, "Multiply by").click() - self.driver.find_element(AppiumBy.NAME, "Nine").click() - self.driver.find_element(AppiumBy.NAME, "Equals").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num9Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "multiplyButton").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num9Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "equalButton").click() self.assertEqual(self.getresults(), "81") def test_subtraction(self): - self.driver.find_element(AppiumBy.NAME, "Nine").click() - self.driver.find_element(AppiumBy.NAME, "Minus").click() - self.driver.find_element(AppiumBy.NAME, "One").click() - self.driver.find_element(AppiumBy.NAME, "Equals").click() - self.assertEqual(self.getresults(), "8") + self.driver.find_element(by=By.ACCESSIBILITY_ID, value="num9Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "minusButton").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "num1Button").click() + self.driver.find_element(By.ACCESSIBILITY_ID, "equalButton").click() + self.assertEqual(self.getresults(),"8") if __name__ == '__main__':