import unittest
from selenium import webdriver
from time import sleep
class LoginCase(unittest.TestCase):
def setUp(self):
self.dr = webdriver.Firefox()
self.dr.maximize_window()
self.dr.get('http://www.imooc.com/') #cnblog登录页面
sleep(3)
self.dr.find_element_by_id("js-signin-btn").click()
sleep(3) #定义登录方法
def login(self, username, password):
self.dr.find_element_by_name("email").send_keys(username)
sleep(2)
self.dr.find_element_by_name("password").send_keys(password)
self.dr.find_element_by_css_selector("[class='btn-red btn-full xa-login']").click()
def test_login_success(self):
self.login('zhangna@imooc.com', 'gjhkjjhghj') # 正确用户名和密码
sleep(3)
self.dr.get_screenshot_as_file("D:\\login_success.jpg") # 截图 可自定义截图后的保存位置和图片命名 def test_login_pwd_error(self):
self.login('zhangna@imooc.com', '123456')
sleep(3)
error_message = self.dr.find_element_by_id('signin-globle-error').text
self.assertIn('密码错误', error_message)
self.dr.get_screenshot_as_file("D:\\login_success.jpg") def tearDown(self):
self.dr.quit()
sleep(2)
print('自动测试完毕!')
if __name__=='__main__':
unittest.main() 最后截图保存到本地

Python+selenium实现登录脚本的更多相关文章

  1. python+selenium 浏览器的问题

    以前用selenium调用firefox是不需要驱动的,最近安装了python3.52+最新的firefox 发现调不起来了 搜索以后发现Firefox 47+需要搞个firefox的驱动 gecko ...

  2. 一次完整的自动化登录测试-基于python+selenium进行cnblog的自动化登录测试

    Web登录测试是很常见的测试!手动测试大家再熟悉不过了,那如何进行自动化登录测试呢!本文作者就用python+selenium结合unittest单元测试框架来进行一次简单但比较完整的cnblog自动 ...

  3. Python + Selenium 实现登录Office 365

    最近捡起之前用的Python + Selenium实现工作中需要的登录Office 365功能.(吐槽:国内网络真是卡,登录Office 365实属不易.另外Selenium这样的网站都要墙,无法理解 ...

  4. python+selenium+Robot

    准备工作: 1.下载python2.7 http://python.org/getit/ 2.下载下载setuptools [python 的基础包工具] 可以帮助我们轻松的下载,构建,安装,升级,卸 ...

  5. python+selenium运行报错UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

    使用python+selenium运行自动化脚本时,打印某一段文字出现UnicodeEncodeError: 'ascii' codec can't encode characters in posi ...

  6. Functional testing - python, selenium and django

    Functional testing  - python selenium django - Source Code : from selenium import webdriverfrom sele ...

  7. python selenium自动化(二)自动化注册流程

    需求:使用python selenium来自动测试一个网站注册的流程. 假设这个网站的注册流程分为三步,需要提供比较多的信息: 在这个流程里面,需要用户填入信息.在下拉菜单中选择.选择单选的radio ...

  8. 使用python selenium进行自动化functional test

    Why Automation Testing 现在似乎大家都一致认同一个项目应该有足够多的测试来保证功能的正常运作,而且这些此处的‘测试’特指自动化测试:并且大多数人会认为如果还有哪个项目依然采用人工 ...

  9. Python+Selenium WebDriver API:浏览器及元素的常用函数及变量整理总结

    由于网页自动化要操作浏览器以及浏览器页面元素,这里笔者就将浏览器及页面元素常用的函数及变量整理总结一下,以供读者在编写网页自动化测试时查阅. from selenium import webdrive ...

随机推荐

  1. [Lua快速了解一下]Lua的Table

    Lua中的Table其实就是一个Key Value的structure haoel = {name=, handsome=True} -table的CRUD操作 haoel.website=" ...

  2. 系统蓝屏stop:ox000007B错误解决方案

    解决方法:开机进入bios:BIOS->Advanced->SATA Mode:[AHCI改为ATA或Compatibility],然后F10保存退出. ATA是指硬盘使用IDE兼容模式, ...

  3. var 在linq中的使用

    一:掌握linq,写出超炫的代码 1. var关键字 [隐式类型] 隐式类型 和 匿名类型的不同叫法. 特性 和 属性 2.隐式类型 就是让编译器来推断的一种语法糖. 二:隐式类型的应用场景 1. 简 ...

  4. Consul ACL

    consul自带ACL控制功能,看了很多遍官方文档,没有配置步骤https://www.consul.io/docs/internals/acl.html 主要对各种配置参数解释,没有明确的步骤,当时 ...

  5. Conditional Expressions

    Conditional Expressions建立一些逻辑关系 The conditional expression classes from django.db import models clas ...

  6. NPOI CellStyle 设置

    public class ExcelNPOIUnit { public static void SetCell(IWorkbook workbook, ISheet sheet, IRow row, ...

  7. chipmunk几何算法

    /* Copyright (c) 2007 Scott Lembcke * * Permission is hereby granted, free of charge, to any person ...

  8. [转贴]VC编译器版本号_MSC_VER and _MSC_FULL_VER

    Visual Studio version and discrimination macros Abbreviation Product name [Visual Studio version] †1 ...

  9. (STM32F4) SysTick理解使用

    關於Cortex System Timer (Systick) 網上隨便google就可以找到許多相關範例. 他就是ARM提供的一個24-bit的下數(count-down)計時器我看大部分應用都是提 ...

  10. 适配器模式-如何把usb插到插座上

    前言 下面所写的内容不是实际的业务场景, 也可能不符合正常的生活习惯, 或者不满足一些人的口味 所写的内容包括之前的帖子,只是为了方便大家更好的记住这个设计模式,实际生活中要灵活应用 设计模式重思想, ...