Automated Mobile App Testing with Python and Nose
Sauce AI for Test Authoring: Move from purport to performance in moment.|xBack to ResourcesBlogPosted<
Sauce AI for Test Authoring: Move from purport to performance in moment.
|
x
One of the coolest parts about expendAppiumfor automated functional testing is that you can compose your tests in whatever language has the examination tools that suit you best. One of the most democratic pick for testing is Python. Writing tests for iOS and Android apps with Appium and Python is easygoing. In this post we & # x27; ll walk through the measure involved in try aniOS sample appusing Appium & # x27; sPython example tests, but the steps for go examination on android are very similar. To start, fork and clone Appium fromhttps: //github.com/appium/appium, and follow the installation pedagogy to set up Appium on your machine. We & # x27; ll need to install Appium & # x27; s dependencies and build the sample apps. To do this, run the following bidding from the Appium work directory:$ ./reset.sh -- iosOnce the task is built, you can get Appium by bunk:$ grunt appiumNow that Appium is running, permutation to the sample-code/examples/python directory. Install the dependencies with pip (if you are not in a virtualenv, you will want to use sudo):$ pip install -r requirements.txtThen, run the example test:$ nosetests simple.pyNow that you & # x27; re set up to run tests, let & # x27; s conduct a closer looking at the exemplar test that we precisely ran to get an idea of how Appium act. This test establish our demo app, fills in some boxes, clicks a push, and tab for an expected result. First, we create the test class and a setUp method:
class TestSequenceFunctions (unittest.TestCase):
def apparatus (self):
app = os.path.join (os.path.dirname (__file__),
& # x27; .. / .. /apps/TestApp/build/Release-iphonesimulator & # x27;,
& # x27; TestApp.app & # x27;)
app = os.path.abspath (app)
self.driver = webdriver.Remote (
command_executor= & # x27; http: //127.0.0.1:4723/wd/hub & # x27;,
desired_capabilities= {
& # x27; browserName & # x27;: & # x27; iOS & # x27;,
& # x27; platform & # x27;: & # x27; Mac & # x27;,
& # x27; variation & # x27;: & # x27; 6.0 & # x27;,
& # x27; app & # x27;: app
})
self._values = []
The & quot; desired_capabilities & quot; argument is used to qualify the platform (iOS 6.0) and the app we need to test. Next we & # x27; ll add a tearDown method to send the quit command after each exam:
For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.
def tearDown (self):
self.driver.quit ()
Finally, we & # x27; ll add a helper method that fills in the shape, and the main test method:
def _populate (self):
# populate text fields with two random number
elems = self.driver.find_elements_by_tag_name (& # x27; textField & # x27;)
for elem in elems:
rndNum = randint (0, 10)
elem.send_keys (rndNum)
self._values.append (rndNum)
def test_ui_computation (self):
# populate text fields with values
self._populate ()
# trigger computation by expend the button
button = self.driver.find_elements_by_tag_name (& quot; button & quot;)
button [0] .click ()
# is sum equal?
texts = self.driver.find_elements_by_tag_name (& quot; staticText & quot;)
self.assertEqual (int (texts [0] .text), self._values [0] + self._values [1])
That & # x27; s it! There are more Python instance in Appium & # x27; s sample tests. Please let us know if you feature any questions or comments about running Appium & # x27; s tests with Nose and Python.
Automate This With SUSA
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.
Try SUSA FreeTest Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free