zoukankan      html  css  js  c++  java
  • Appium_iOS_Safari测试脚本(2)

    经过多次调试,在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()
  • 相关阅读:
    python 垃圾回收机制
    @property 取代getter setter方法
    ==值相等 is同一性
    循环获取文件名,拼接路径打印
    python 闭包
    python生成器
    hadoop集群环境搭建之zookeeper集群的安装部署
    hadoop集群环境搭建之安装配置hadoop集群
    hadoop集群环境搭建准备工作
    linux下安装jdk
  • 原文地址:https://www.cnblogs.com/jiguanghover/p/12545428.html
Copyright © 2011-2022 走看看