Here is an example of how you can write an Appium test using the Python unittest library:

import unittest
from appium import webdriver
from selenium.webdriver.common.by import By
import time

class TestLogin(unittest.TestCase):
    def setUp(self):
        # Set desired capabilities for the Appium driver
        desired_caps = {
            "platformName": "iOS",
            "deviceName": "iPhone 11",
            "app": "/path/to/your/app.app"
        }

        # Create the Appium driver
        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)

    def test_login(self):
        # Log into the app
        self.driver.find_element(By.ID, "username_input").send_keys("your_username")
        self.driver.find_element(By.ID, "password_input").send_keys("your_password")
        self.driver.find_element(By.ID, "login_button").click()

        # Click on a button
        self.driver.find_element(By.ID, "button_to_click").click()

        # Wait for the modal popup to appear
        modal_popup = self.driver.find_element(By.ID, "success_modal")
        while not modal_popup.is_displayed():
            time.sleep(1)

        # Verify that the modal popup says "Success!"
        self.assertEqual(modal_popup.text, "Success!")

        # Close the modal popup
        self.driver.find_element(By.ID, "close_button").click()

    def tearDown(self):
        # Close the Appium driver
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()

In this version of the test, the setUp method is used to create the Appium driver and set the desired capabilities, and the tearDown method is used to close the driver. The test itself is defined in the test_login method, which performs the steps of logging into the app, clicking on a button, waiting for the modal popup to appear, and verifying that the modal popup says “Success!”.

To run the test, you can use the unittest.main() method, which will discover and run all tests in the script. The unittest library provides many other features such as assertions, test discovery, and test runners, which you can use to further structure and organize your tests.

By Tech Thompson

Tech Thompson is a software blogger and developer with over 10 years of experience in the tech industry. He has worked on a wide range of software projects for Fortune 500 companies and startups alike, and has gained a reputation as a leading expert in software development and design.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

WordPress Appliance - Powered by TurnKey Linux