• 作业一

    作业二

    import requests
    import logging
    import pytest
    import json


    class TestRequests(object):
    logging.basicConfig(level=logging.INFO)
    url = "https://182.92.251.113/v5/stock/portfolio/list.json"

    def test_xueqiu_quote(self):
    params = {"_t": "1UNKNOWNe82a4378ca77eecd854eca9c08318120.1555728505.1564488409077.1564488489893",
    "_s": "c72a26",
    "category": "1",
    "system": "true"
    }
    cookies = {"xq_a_token": "bff23b63f231f145697fc8750af56158cc702c10",
    "u": "1555728505"}
    r = requests.get(self.url,
    headers={'Host':'stock.xueqiu.com',
    'User-Agent':'Xueqiu Android 11.19'},
    params=params,
    cookies=cookies,
    verify=False
    )
    logging.info(r.url)
    logging.info(json.dumps(r.json(), indent=2))
  • 作业一

    作业二

  • 作业二

  • import time

    import pytest
    from selenium import webdriver


    class TestTesterHome(object):
    def setup(self):
    self.driver = webdriver.Chrome()
    self.driver.implicitly_wait(10)
    self.driver.get("https://xueqiu.com/")

    def test_search(self):
    self.driver.find_element_by_tag_name("input").send_keys('alibaba')
    self.driver.find_element_by_css_selector('.nav__search__addon').click()
    self.driver.find_element_by_xpath('//*[text()="01688"]/../../../..//*[@class="follow__control"]').click()
    self.driver.find_element_by_name('username').send_keys('13646837962')
    self.driver.find_element_by_name('password').send_keys('123456')
    self.driver.find_element_by_class_name('modal__login__btn').click()
    time.sleep(5)

    def teardown(self):
    self.driver.quit()

  • '''
    基金开户 蛋卷已有账户登录 密码登陆 输入错误的用户名和密码,点击安全登陆
    '''

    import time
    from appium import webdriver
    from appium.webdriver.common.mobileby import MobileBy
    from appium.webdriver.webdriver import WebDriver
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.wait import WebDriverWait


    class Testopenaccount(object):
    driver = WebDriver
    # @classmethod
    # def setup_class(cls):
    # print("setup class 在当前类下的所有用例执行之前只执行一次")
    # cls.driver = cls.install_app()
    # print(cls.driver.contexts)


    def setup_method(self):
    print("setup method 在每个测试用例执行之前执行一次")
    #获取启动的appiumdriver实例,用于后续每个casedriver
    self.driver = self.restart_app()
    # self.driver = Testopenaccount.driver
    WebDriverWait(self.driver, 20).until(EC.presence_of_element_located((MobileBy.XPATH, "//*[@text='交易']")))
    self.driver.find_element_by_xpath("//*[@text='交易']").click()
    WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((MobileBy.ACCESSIBILITY_ID, "A股开户")))

    def test_fund_account(self):
    self.driver.find_element_by_accessibility_id("基金开户").click()
    WebDriverWait(self.driver, 10).\
    until(EC.presence_of_element_located((MobileBy.ACCESSIBILITY_ID, "已有蛋卷基金账户登录")))
    self.driver.find_element_by_accessibility_id("已有蛋卷基金账户登录").click()
    WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((MobileBy.ACCESSIBILITY_ID, "安全登录")))
    self.driver.find_element_by_accessibility_id("使用密码登录").click()
    WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((MobileBy.ACCESSIBILITY_ID, "登录密码")))
    self.driver.find_element_by_id("telno").send_keys("13646837962")
    self.driver.find_element_by_id("pass").send_keys("123456")
    self.driver.find_element_by_accessibility_id("安全登录").click()
    time.sleep(2)

    # def teardown_method(self):
    # self.driver.back()

    @classmethod
    def install_app(cls) -> WebDriver:
    caps = {}
    #如果有必要,进行第一次安装
    # caps["app"]=''
    caps["platformName"] = "android"
    caps["deviceName"] = "hogwarts"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    #解决第一次启动的问题
    caps["autoGrantPermissions"] = "true"
    # caps['noReset']=True

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

    @classmethod
    def restart_app(cls) -> WebDriver:
    caps = {}

    caps["platformName"] = "android"
    caps["deviceName"] = "hogwarts"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    #为了更快的启动,并保留之前的数据,从而可以保存上一个case执行后的状态
    caps['noReset']=True
    caps['chromedriverExecutableDir']="/Users/seveniruby/projects/chromedriver/2.20"
    #caps["udid"]="emulator-5554"

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

  • 作业二


    '''
    进入雪球首页,进入基金的新闻页(不是第一个基金按钮),对他以及它右侧的每个新闻栏目,执行上滑5次,进入下个栏目用从右边到左边滑动
    滑动使用相对坐标,而不是绝对坐标
    '''


    import time
    from appium import webdriver
    from appium.webdriver.webdriver import WebDriver
    from appium.webdriver.common.touch_action import TouchAction


    class Testchangepage(object):
    driver = WebDriver

    # @classmethod
    # def setup_class(cls):
    # cls.restart_app()

    def setup_method(self):
    self.driver=self.restart_app() #这句写错,搞了好久

    def teardown_method(self):
    self.driver.quit()

    def move_up_n_times(self):
    rect = self.driver.get_window_size()
    action = TouchAction(self.driver)
    for i in range(5):
    action\
    .press(x=rect['width']*0.5, y=rect['height']*0.8).move_to(x=rect['width']*0.5, y=rect['height']*0.2)\
    .release()\
    .perform()
    time.sleep(2)

    #没有完成
    # def move_to_left(self):

    def test_move_from_jj(self):
    self.driver.find_element_by_xpath("//*[contains(@resource-id,'indicator')]//*[@text='基金']").click()
    self.move_up_n_times()


    @classmethod
    def install_app(cls) -> WebDriver:
    caps = {}
    # 如果有必要,进行第一次安装
    caps["platformName"] = "android"
    caps["deviceName"] = "hogwarts"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    # 解决第一次启动的问题
    caps["autoGrantPermissions"] = "true"

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

    @classmethod
    def restart_app(cls) -> WebDriver:
    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "hogwarts"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    # 为了更快的启动,并保留之前的数据,从而可以保存上一个case执行后的状态
    caps['noReset'] = True

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

    作业三


    '''
    完成雪球登录场景的测试
    要去带有setup_class setup_method体系
    微信 验证码 密码 错误的用户名 错误的密码 至少编写5条用例
    '''


    import time
    from appium import webdriver
    from appium.webdriver.webdriver import WebDriver
    import pytest
    import allure


    class Testlogin(object):
    driver = WebDriver

    @classmethod
    def setup_class(cls):
    cls.driver = cls.install_app()

    def setup_method(self):
    self.driver = self.restart_app()
    self.driver.find_element_by_id("user_profile_icon").click()
    self.driver.find_element_by_id("tv_login").click()

    def teardown_method(self):
    self.driver.quit()

    @allure.feature("测试用微信登陆")
    @allure.story('在第一个界面用微信登陆')
    @allure.severity('critical')
    def test_login_by_wechat1(self):
    self.driver.find_element_by_id("rl_login_by_wx").click()
    time.sleep(2)
    print("提示没有安装微信")
    assert 1==2, "没有安装微信"

    @allure.feature("测试用微信登陆")
    @allure.story('在第一个界面用微信登陆')
    @allure.severity('critical')
    def test_login_by_wechat2(self):
    self.driver.find_element_by_id("tv_login_by_phone_or_others").click()
    self.driver.find_element_by_id("weixin_login").click()
    print('微信登陆成功')
    time.sleep(2)

    @allure.feature("测试用手机号登陆")
    @allure.story('测试成功登陆')
    @allure.severity('critical')
    @pytest.mark.parametrize("user,password", [('mayun', '123456'), ('lv', '000000')])
    def test_login_by_phone(self, user, password):
    with allure.step("进入手机号登陆界面"):
    self.driver.find_element_by_id("tv_login_by_phone_or_others").click()
    with allure.step("输入手机号"):
    self.driver.find_element_by_id("register_phone_number").click()
    with allure.step("输入验证码登陆"):
    self.driver.find_element_by_id("register_code_text").click()
    with allure.step("登陆成功"):
    print("%s成功登陆" % user)
    time.sleep(2)

    @classmethod
    def install_app(cls) -> WebDriver:
    caps = {}
    # 如果有必要,进行第一次安装
    caps["platformName"] = "android"
    caps["deviceName"] = "hogwarts"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    # 解决第一次启动的问题
    caps["autoGrantPermissions"] = "true"

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

    @classmethod
    def restart_app(cls) -> WebDriver:
    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "hogwarts"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    # 为了更快的启动,并保留之前的数据,从而可以保存上一个case执行后的状态
    caps['noReset'] = True

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

  • from appium import webdriver

    caps = {}
    caps["platformName"] = "android"
    caps["deviceName"] = "hogwarts"
    caps["appPackage"] = "com.xueqiu.android"
    caps["appActivity"] = ".view.WelcomeActivityAlias"
    caps["autoGrantPermissions"] = "true"

    driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
    #追加一句
    driver.implicitly_wait(10)

    el1 = driver.find_element_by_id("com.xueqiu.android:id/home_search")
    el1.click()
    el2 = driver.find_element_by_id("com.xueqiu.android:id/search_input_text")
    el2.send_keys("alibaba\n")
    driver.hide_keyboard()
    el3 = driver.find_element_by_xpath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.view.ViewGroup/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.support.v4.view.ViewPager/android.widget.RelativeLayout/android.widget.ListView/android.widget.LinearLayout[1]/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.RelativeLayout[1]/android.widget.LinearLayout[2]/android.widget.TextView")
    el3.click()

    driver.quit()

    有个疑问,为什么加了driver.quit(),到最后一步添加到自选股就会失败。不加driver.quit(),添加到自选股就没有问题