Selenium_Python–search_client.py

继续写我的UI自动化测试,今天要完成一个完整的登陆,查找Client, 登出操作: 1.测试用例如下: 2.录制这个测试用例, 下图是已经录制好的Selenium 脚本: 其中: a. 紫色部分是comment(注释); b. 深绿色部分是加入的断言; c. 在某些可能需要页面加载的部分加入等待时间pause(3000), 表示等待3s; d. 淡绿色部分就是录制过程中的脚本,执行的时候是黄色,执行成功则显示为绿色; e. comment 和pause 部分视情况而定,这里都是需要在录制脚本成功以后手动加入的动作; 3.脚本回放: a. 左上方部分可以选择Fast/Slow调节回放的速度; b. 在页面加载较慢的地方加入pause, 比如login, search… c. 图上所示两个run button, 右边一个是执行当前测试用例,左边是执行当前测试套件下的所有用例,视情况而定; 4.加入断点: a. 在某个command行右击选择‘Set/Clear Start Point’ 可以设置/取消脚本从当前行执行; b. 在某个command行右击选择‘Execute this command’ 可以单独执行此行脚本,查看结果; 5.查看执行结果并导出用例: 将测试用例导出成.html文件,可以方便我们查看录制脚本的过程: 6.一般来说,导出的录制脚本都是需要修改和调试的,要不无法作为.py 文件执行 导出自动化脚本成python 2/unittest/web driver 程序,利用pycharm 编辑器打开调试,遇到几个问题: a. 之前手动加入的pause会有一些警告信息,导出的断言也会报错: # Warning: … Read moreSelenium_Python–search_client.py

Python_Note_11–set 用法

今天写几个小程序练练手: list1 = [‘a’, ‘b’, ‘apple’, ‘are’, ‘b’, ‘cannot’, ‘a’, ‘b’] list2 = [99, 10, 2, 45, 3, 55, 98, 99, 100, 2000, 4] 1.scan list 中某个元素a出现的次数: def scan1(li): return len([elem for elem in li if elem == ‘a’]) scan1(list) — result is: 2 2.scan list 中长度不为1的元素: def scan2(li): return [elem for elem in li … Read morePython_Note_11–set 用法

Python_Note_8–Super()

1.Defined for super() super(type[, object-or-type]) Return the superclass of type. If the second argument is omitted the super object returned is unbound. If the second argument is an object, isinstance(obj, type) must be true. If the second argument is a type, issubclass(type2, type) must be true. super() only works for new-style classes. A typical use … Read morePython_Note_8–Super()

Python_Note_7–class

Here we need learn more about class 1.game.py from sys import exit from random import randint class Game(object): def __init__(self, start): self.quips =[ “First line to play game”, “Haha, we need study more”, “Good job, girl!” “Try to move on!” ] self.start = start def play(self): next = self.start while True: print “\n——–” room = … Read morePython_Note_7–class

Python_Note_6–dictionary 基本操作

Here are some usage for dict in python. 1.fotmat cities = {‘BJ’: ‘Beijing’, ‘SH’: ‘Shanghai’, ‘TJ’: ‘Tianjing’, ‘XA’: “Xi’an”, ‘SZ’: ‘Shenzhen’} 2.add items cities[‘NJ’] = ‘Najing’ 3.del items del cities[‘TJ’] 4..pop() items cities.pop(‘TJ’) 5..copy(), cities_2 is a copied dict of cities. cities_2 = cities.copy() 6..clear() print cities.clear() # result is {} 7..has_key() print cities.has_key(‘BJ’) # … Read morePython_Note_6–dictionary 基本操作

Python_Note_5–LearningList

Tips for this week. 1.txt = open(filename, “w”) 2.txt.read() 3.txt.close() 4.def print_one(arg1): 5.raw_input(“>”) 6.from sys import argv 7.from os.path import exists 8.exists(filename) # return True or False 9.len(indata) 10.print “Arg1: %r, Arg2: %r” % (arg1, arg2) 11.print ”’This is what you see will what will print, like ###,’\n””sth ”’ 12.import shutil 13.shutil.copy(src, dst) 14.shutil.copyfile(src, dst) … Read morePython_Note_5–LearningList

Python_Note_4–ifelse,for-loop,while-loop

Another day with a not very good effection, try girl! 1.if…elif…else if 1 > 2: print “Not possible!” elif 1 == 2: print “Is this a joke?” else: print “This is true.” notice: the : after if, elif and else. 2.for-loop elements = [] for i in range(1, 8, 2): print “Adding %d to the … Read morePython_Note_4–ifelse,for-loop,while-loop

Python_Note_3–file.open,write,close

It’s not a easy time to learn so many things, but it’s worth and funny. python file action: 1.code context: from sys import argv from os.path import exists import shutil script, from_file, to_file =argv # unpack target = open(from_file, “w+”) # “w+” clear all, and re-write file, can seek(0), then read without close it. print … Read morePython_Note_3–file.open,write,close