自动化测试需对比实际结果与预期结果,给出测试结论。

1 条件判断 if ...else...

2 assert ...

#coding:utf-8
#断言 from selenium import webdriver dr = webdriver.Firefox()
dr.get("http://www.baidu.com") #if判断
if '百度' in dr.title:
print("test pass")
else:
print("test fail") #assert断言
assert ("百度") in dr.title #断言true,继续执行
dr.find_element_by_id("kw").send_keys("断言")
dr.find_element_by_id("su").click()
print("test pass") #故意写错title
assert '百度000' in dr.title, 'test fail' #断言false,抛出AssertionError异常,输出testfail,中止执行
dr.find_element_by_id("kw").send_keys("断言")
dr.find_element_by_id("su").click()
print("test pass") dr.quit()

Selenium入门18 断言的更多相关文章

  1. 自动化测试Java一:Selenium入门

    From: https://blog.csdn.net/u013258415/article/details/77750214 Selenium入门 欢迎阅读Selenium入门讲义,本讲义将会重点介 ...

  2. Selenium自动化测试Python一:Selenium入门

    Selenium入门 欢迎阅读Selenium入门讲义,本讲义将会重点介绍Selenium的入门知识以及Selenium的前置知识. 自动化测试的基础 在Selenium的课程以前,我们先回顾一下软件 ...

  3. Selenium 入门到精通系列:六

    Selenium 入门到精通系列 PS:Checkbox方法 例子 HTML: <html> <head> <title>测试页面</title> &l ...

  4. Selenium 入门到精通系列:五

    Selenium 入门到精通系列 PS:显式等待.隐式等待.强制等待方法 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019 ...

  5. Selenium 入门到精通系列:四

    Selenium 入门到精通系列 PS:鼠标右键.鼠标悬停.键盘操作方法 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019 ...

  6. Selenium 入门到精通系列:三

    Selenium 入门到精通系列 PS:Driver_Element 常用方法 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2 ...

  7. Selenium 入门到精通系列:二

    Selenium 入门到精通系列 PS:用户登录 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019-04-23 16:12 ...

  8. Selenium 入门到精通系列:一

    Selenium 入门到精通系列 PS:控制浏览器窗口大小.前进.后退.刷新 例子 #!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 20 ...

  9. Selenium入门6 操作元素,获取元素属性

    取元素的text,属性get_attribute,标签名tag_name 操作元素:send_keys输入,click点击,submit提交,clear清除输入 状态判断:is_display,is_ ...

随机推荐

  1. Idea如何设置代码超出长度限制时自动换行

    在[File]-->[Settings]-->[Code Sytle]中勾选[Wrap on typing]选项

  2. Juniper SRX550防火墙web页面CPU达到100%的故障解决办法

    Juniper SRX550防火墙web页面CPU达到100%的故障解决办法 利用telnet远程连接主机,对web页面注销重新登录即可,在配置中输入命令:run restart web-manage ...

  3. IHttpAsyncHandler IHttpHandler

    1.建立 .ashx 文件 2.异步HTTPHandler的实现https://www.cnblogs.com/HQFZ/p/5688759.html 3.Asp.net异步IHttpAsyncHan ...

  4. 电量分析工具 Battery Historian 的配置及使用

    1.Building from source code(通过各种配置后从源码构建) 官方流程看似很麻烦,但一上手,很快就搞定,让我情何以堪. ps:以下均是参考官方及网友做的 copy https:/ ...

  5. toTop插件(三)

    前言 当窗体内容过多会出现滚动, 点击回到顶部滚动条在在上边(大家都懂得,我语文学的不好,表达不清^_^) 看代码 CSS : .toTop{ position: fixed; width: 50px ...

  6. Silverlight 减小 Xap 的大小

    当Silverlight工程引用了很多dll后,加载的速度就会很慢,通过下面方式可以减小xap包的大小 勾选 “通过使用应用程序库缓存减小xap大小”,勾选此项后vs会自动将微软自身和外部引用不变的d ...

  7. Android NDK开发 Jni中打日志LOG(二)

    HelloJni.c文件中,加入头文件和函数声明.最终文件如下: #include <jni.h> #include <string.h> #include<androi ...

  8. git使用笔记-日志

    1.查看函数的历史修改 git log -L :git_deflate_bound:zlib.c2.查看HEAD的所有记录 git reflog $ git reflog 1a410ef HEAD@{ ...

  9. windows下端口转发 netsh

    添加映射表: netsh interface portproxy add v4tov4 listenport=(监听端口) connectaddress=(虚机IP) connectport=(虚机端 ...

  10. pat1038. Recover the Smallest Number (30)

    1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...