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

Appium_iOS_Safari测试脚本(2)

时间:2020-03-22 13:50:26      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:ext   drive   settime   down   query   coding   http   exce   select   

经过多次调试,在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()

 

Appium_iOS_Safari测试脚本(2)

标签:ext   drive   settime   down   query   coding   http   exce   select   

原文地址:https://www.cnblogs.com/jiguanghover/p/12545428.html

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