Appium_iOS_Safari测试脚本(2)

╄→尐↘猪︶ㄣ 提交于 2020-03-22 13:16:42

经过多次调试,在Safari上的测试脚本终于可以运行了,不过部分元素还是无法识别,还需要继续调试;

#!/usr/bin/env/python
# -*-coding:utf-8-*-

import pytest
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


class TestSafari:

    def setup(self):
        self.driver = webdriver.Safari()
        self.driver.get("https://www.xxxyyy.org")
        self.driver.maximize_window()  # 最大化窗口
        self.driver.implicitly_wait(10)  # 隐式等待

    def test_login_demo(self):
        try:
            login_click = """
                            setTimeout(function() {
                                // 延迟 5 秒点击查询按钮(setTimeout是异步执行)
                                var login = document.querySelector("#Header>li:nth-child(4)>div>span:nth-child(1)") ; 
                                login.click() ;
                            } , 5000) ;
                            """
            self.driver.execute_script(login_click)  # JS查询并点击
            sleep(1)
            # input username
            email_input = WebDriverWait(self.driver, 10).until(
                EC.visibility_of_element_located((By.XPATH, '//*[@id="Qign"]/table/tbody/div/div/div[1]/form/div[2]/input')))
            # email_input = self.driver.find_element_by_xpath(
            #     '//*/input[@name="email"]')
            email_input.send_keys("aaa@163.com")
            sleep(1)

            # input password
            pass_input = self.driver.find_element_by_xpath(
                '//*[@id="Bign"]/table/tbody/tr/td/div/form/div[3]/input')
            pass_input.send_keys("bbbbbb")

            # assert login page
            login_phone_text = self.driver.find_element_by_xpath(
                '//*[@id="Sign"]/table/tbody/div/div/div[1]/form/div[1]')
            assert 'Login with Phone' in login_phone_text.text

            # click login button
            login_btn = WebDriverWait(self.driver, 10).until(
                EC.visibility_of_element_located(
                    (By.XPATH, '//*[@id="Sign"]/table/tbody/div/div/div[1]/form/div[5]/button')))
            login_btn.click()
            
        except Exception as e:
            print("Login exception>>",e)

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

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!