码迷,mamicode.com
首页 > 移动开发 > 详细

第一个appium测试用例

时间:2019-08-18 13:59:17      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:阿里   lib   activity   assert   cli   click   icon   ext   class   

 

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测试用例

标签:阿里   lib   activity   assert   cli   click   icon   ext   class   

原文地址:https://www.cnblogs.com/youyouyunduo/p/11371873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!