zoukankan      html  css  js  c++  java
  • 自动化测试_百度--糯米中--携程-出行<一>

    1:接下来我们看看思路  和相应的功能

    使用python+selenium+unittest完成测试脚本

    打开chrome浏览器,窗口最大化,设置等待时间10s

    打开百度首页

    鼠标移动到更多产品,点击糯米   

    点击火车票

    始发站选择北京,终点站选择上海

    时间选择明天

    截屏搜素结果页面

    测试结果写入html文件

    • ActionChains是自动执行低级交互的一种方式,例如:鼠标移动,鼠标点按,键盘操作,文本操作等
    • click(element=null)                                 点击元素,参数为空时,鼠标在当前位置点击
    • send_keys(keys_to_send)                     向文本框发送文字、按键                                    
    • move_to_element(element)                   鼠标悬浮在某元素上
    • perform()                                               执行所有存储在ActionChains中的动作

    首先来看如何引入这个包

    from selenium.webdriver.common.action_chains import ActionChains

    当然,我们还要引入wedbriver的包,用来启动浏览器

    from selenium import webdriver
    # -*- coding: utf-8 -*-
    # __author__ = "Allen"
    import requests    
    import unittest           
    import HTMLTestRunner     
    import time 
    from selenium import webdriver
    from selenium.webdriver.common.action_chains import ActionChains
    from selenium.webdriver.common.keys import Keys
    
    class Baidu(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(10)
            self.driver.maximize_window()
    
        def tearDown(self):
            time.sleep(3)
            self.driver.quit()
    
        def test_login(self):
            self.driver.get('https://www.baidu.com/')
            gd = self.driver.find_element_by_link_text('更多产品')
    
            # 鼠标滑动到   更多产品  控件上
            ac = ActionChains(self.driver)
            ac.move_to_element(gd).perform()
            time.sleep(3)
            self.driver.find_element_by_link_text('糯米').click()
    
    
            # 获取当前打开的所有网页的标识
            pag = self.driver.window_handles
            # 切换到最新打开的网页   X上出行
            self.driver.switch_to_window(pag[-1])
            chux = self.driver.find_element_by_xpath('//*[@id="j-catg"]/li[4]/div')
    
    
            # 鼠标滑动到     出行     控件上
            ac = ActionChains(self.driver)
            ac.move_to_element(chux).perform()
    
            self.driver.find_element_by_xpath('//*[@id="j-catg"]/li[4]/ul/li[2]/a/div').click()
            # 获取当前 (target="_blank") 新 打开的所有网页的标识
            pag = self.driver.window_handles
            # 切换到最新打开的网页   X上出行
            self.driver.switch_to_window(pag[-1])
    
            # 清空输入框中内容
            self.driver.find_element_by_id('notice01').send_keys('北京')
            time.sleep(3)
            self.driver.find_element_by_id('notice08').send_keys('杭州')
            time.sleep(3)
    
            # 执行js语句,删除时间输入框的readonly属性
            js = 'document.getElementById("dateObj").removeAttribute("readonly")'
            self.driver.execute_script(js)
    
            self.driver.find_element_by_id('dateObj').clear()
            self.driver.find_element_by_id('dateObj').send_keys('2019-10-01')
            time.sleep(3)
            self.driver.find_element_by_xpath('//*[@id="searchtype"]/li[1]').click()
    
            self.driver.find_element_by_id('searchbtn').click()
            time.sleep(3)
    
            # 截屏
            self.driver.save_screenshot(r'223.png')
    
            # 断言判断北京在不在网页标题中
            self.assertIn('北京',self.driver.title)
    
    file = r'测试考试aa.html'
    # file1 = r'测试考试aa.txt'
    if __name__ == '__main__':
        suit = unittest.TestSuite()
        suit.addTests(unittest.TestLoader().loadTestsFromName('day17'))
        with open(file,'wb')as f:
            runner = HTMLTestRunner.HTMLTestRunner(f,verbosity=2)
            runner.run(suit)


  • 相关阅读:
    (绝对有用)iOS获取UUID,并使用keychain存储
    宏定义判断设备是否是iphone5
    如何在未越狱iOS设备上安装IPA
    制作iOS Ad-Hoc测试应用
    UIWebView中Html中用JS调用OC方法及OC执行JS代码
    ios开发入门- plist 文件读写
    [iOS] 如何将你的程序打包成ipa
    《网络对抗技术》Exp1 PC平台逆向破解——20181308邵壮
    公文传输系统冲刺总结——Day3
    MyOD实验 20181308
  • 原文地址:https://www.cnblogs.com/zhichao123/p/11245935.html
Copyright © 2011-2022 走看看