Skip to content

Make sample more OS language agnostic #1

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

Open
wants to merge 3 commits into
base: patch-1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 36 additions & 37 deletions Samples/Python/calculatortest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__':
Expand Down