第一个appium测试用例

Posted youyouyunduo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第一个appium测试用例相关的知识,希望对你有一定的参考价值。

 

from time import sleep
from appium import webdriver
import pytest


class TestXueqiu:

    user_profile_id = "user_profile_icon"
    login_more_id = "iv_login_more"
    login_account_id = "login_account"
    login_password_id = "login_password"
    button_next_id = "button_next"
    md_content_id = "md_content"
    md_buttonDefaultPositive_id = "md_buttonDefaultPositive"
    action_back_id = "iv_action_back"
    buttonDefaultNegative_id = "md_buttonDefaultNegative"
    action_back1_id = "action_back"
    home_search_id = "home_search"
    search_input_text_id = "search_input_text"
    search_name_id = "name"
    stockName_id = "stockName"
    action_close_id = "action_close"

    def setup_class(self):

        caps = 
        caps["platformName"] = "android"
        caps["platformVersion"] = "8.1.0"
        caps["deviceName"] = "60c106df0302"
        caps["appPackage"] = "com.xueqiu.android"
        caps["appActivity"] = ".view.WelcomeActivityAlias"
        caps["noReset"] = True

        self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
        self.driver.implicitly_wait(20)

    def test_wrong_phone(self):

        self.driver.find_element_by_id(self.user_profile_id).click()
        self.driver.find_element_by_id(self.login_more_id).click()
        login_account = self.driver.find_element_by_id(self.login_account_id)
        login_account.clear()
        login_account.send_keys("1311111111111111111")
        login_password = self.driver.find_element_by_id(self.login_password_id)
        login_password.clear()
        login_password.send_keys("123456abc")
        self.driver.find_element_by_id(self.button_next_id).click()
        text = self.driver.find_element_by_id(self.md_content_id).get_attribute("text")
        assert text == "手机号码填写错误"
        self.driver.find_element_by_id(self.md_buttonDefaultPositive_id).click()

    def test_wrong_password(self):
        login_account = self.driver.find_element_by_id(self.login_account_id)
        login_account.clear()
        login_account.send_keys("15958020294")
        login_password = self.driver.find_element_by_id(self.login_password_id)
        login_password.clear()
        login_password.send_keys("123456abc111")
        self.driver.find_element_by_id(self.button_next_id).click()
        text = self.driver.find_element_by_id(self.md_content_id).get_attribute("text")
        assert text == "用户名或密码错误"
        self.driver.find_element_by_id(self.md_buttonDefaultPositive_id).click()
        self.driver.find_element_by_id(self.action_back_id).click()
        self.driver.find_element_by_id(self.buttonDefaultNegative_id).click()
        self.driver.find_element_by_id(self.action_back1_id).click()

    @pytest.mark.parametrize(("search", "result"), [
        ("alibaba", "阿里巴巴"), ("xiaomi", "小米"), ("google", "谷歌")
      ])
    def test_search(self, search, result):
        self.driver.find_element_by_id(self.home_search_id).click()
        self.driver.find_element_by_id(self.search_input_text_id).send_keys(search)
        self.driver.find_elements_by_id(self.search_name_id)[0].click()
        text = self.driver.find_elements_by_id(self.stockName_id)[0].get_attribute("text")
        assert result in text
        self.driver.find_element_by_id(self.action_close_id).click()

    def teardown_class(self):
        sleep(5)
        self.driver.quit()

  

以上是关于第一个appium测试用例的主要内容,如果未能解决你的问题,请参考以下文章

Appium:如何一个接一个地执行多个测试用例?

robotframework+appium 创建第一条测试用例

appium+robot framework 一个测试用例

TestNG中Appium测试用例的顺序执行导致测试用例失败

python+appium自动化测试-重复执行测试用例

Appium新手入门—— Appium测试用例