标签: loadrunner小布老师杂谈 |
分类: LoadRunner |
日常工作总结
Ø netstat命令
如果你在Windows操作系统,你可以使用netstat命令来查询PID,然后可以打开任务管理器,查看这个PID对应的进程名;如果PID没有显示,菜单》查看》选择列》选中PID即可;得知进程后,我们可以将进程杀掉。在windows控制台窗口下执行:netstat -nao | findstr 161
看倒数第1,3行,你看到是PID为4996的进程占用了161和162端口,如果进一步你想知道它的进程名称,你可以使用如下命令:tasklist | findstr 4996
可以看到是snmpagent.exe进程,如果你想杀死这个进程,你当然可以用前面描述的那种方法,在任务管理器里把它KILL了,但如果你喜欢高效一点,那么用taskkill命令就可以了。taskkill /pid 4996
那么这个进程就关闭了,此时也可以用 taskkill /pid 3017 /t /f 快速强制关闭此进程 。
如果你在Windows操作系统,你可以使用netstat命令来查询PID,然后可以打开任务管理器,查看这个PID对应的进程名;如果PID没有显示,菜单》查看》选择列》选中PID即可;得知进程后,我们可以将进程杀掉。在windows控制台窗口下执行:netstat -nao | findstr 161看倒数第1,3行,你看到是PID为4996的进程占用了161和162端口,如果进一步你想知道它的进程名称,你可以使用如下命令:tasklist | findstr 4996
可以看到是snmpagent.exe进程,如果你想杀死这个进程,你当然可以用前面描述的那种方法,在任务管理器里把它KILL了,但如果你喜欢高效一点,那么用taskkill命令就可以了。taskkill /pid 4996
那么这个进程就关闭了,此时也可以用 taskkill /pid 3017 /t /f 快速强制关闭此进程 。
Ø Route命令
PC添加一个ip:192.192.1.?
子网掩码:255.255.255.0 或者 255.255.252.0
CMD,以管理员身份运行
添加一条永久路由:route add 192.192.8.0 mask 255.255.252.0 192.192.1.1 –p
添加route 后可以用命令route print 查看是否添加了永久路由
route print 192.192.* 查看添加的192.192.?.?的静态路由
例子1:要显示IP路由表的完整内容,执行以下命令:
route print
例子2:要显示IP路由表中以10.开始的路由,执行以下命令:
route print 10.*
例子3:要添加默认网关地址为192.168.12.1的默认路由,执行以下命令:
route add 0.0.0.0 mask 0.0.0.0 192.168.12.1
例子4:要添加目标为10.41.0.0,子网掩码为255.255.0.0,下一个跃点地址为10.27.0.1的路由,执行以下命令:
route add 10.41.0.0 mask 255.255.0.0 10.27.0.1
例子5:要添加目标为10.41.0.0,子网掩码为255.255.0.0,下一个跃点地址为10.27.0.1的永久路由,执行以下命令:
route -p add 10.41.0.0 mask 255.255.0.0 10.27.0.1
例子6:要添加目标为10.41.0.0,子网掩码为255.255.0.0,下一个跃点地址为10.27.0.1,跃点数为7的路由,执行以下命令:
route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 metric 7
例子7:要添加目标为10.41.0.0,子网掩码为255.255.0.0,下一个跃点地址为10.27.0.1,接口索引为0x3的路由,执行以下命令:
route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 if 0x3
例子8:要删除目标为10.41.0.0,子网掩码为255.255.0.0的路由,执行以下命令:
route delete 10.41.0.0 mask 255.255.0.0
例子9:要删除IP路由表中以10.开始的所有路由,执行以下命令:
route delete 10.*
例子10:要将目标为10.41.0.0,子网掩码为255.255.0.0的路由的下一个跃点地址由10.27.0.1更改为10.27.0.25,执行以下命令:
route change 10.41.0.0 mask 255.255.0.0 10.27.0.25
本文链接: http://codingstandards.iteye.com/blog/1130135 (转载请注明出处)
ifconfig命令常用来显示系统中的网络接口(网卡)信息,也可以用来配置网络接口(configure a network interface),如激活、关闭、设置地址等。在Linux系统中,网卡命名规律:eth0为第一块以太网卡(Ethernet Card),eth1为第二块。lo为环回接口,它的IP地址固定为127.0.0.1,掩码8位。
格式:ifconfig
显示当前激活的网络接口信息。
If no arguments are given, ifconfig displays the status of the currently active interfaces.
格式:ifconfig {INTERFACE}
显示指定网络接口的信息。比如:eth0, eth1。
If a single interface argument is given, it displays the status of the given interface only;
格式:ifconfig -a
显示所有网络接口的信息,无论是否激活。
if a single -a argument is given, it displays the status of all interfaces, even those that are down.
Display info on all network interfaces on server, active or inactive.
其他格式,用来配置网络接口。
Otherwise, it configures an interface.
格式:ifconfig {INTERFACE} up
格式:ifup {INTERFACE}
激活指定网络接口。比如:eth0, eth1。
This flag causes the interface to be activated. It is implicitly specified if an address is assigned to the interface.
格式:ifconfig {INTERFACE} down
格式:ifdown {INTERFACE}
关闭指定网络接口。
This flag causes the driver for this interface to be shut down.
格式:ifconfig {INTERFACE} {IP}
格式:ifconfig {INTERFACE} {IP} netmask {NETMASK}
为指定网络接口设置IP地址和掩码,并自动激活。比如:eth0, eth0:0, eth0:1,后两个为虚拟网卡。
格式:ifconfig {INTERFACE} add {IP}
格式:ifconfig {INTERFACE}:0 {IP}
为指定网络接口添加IP地址。
格式:ifconfig {INTERFACE} del {IP}
为指定网络接口删除IP地址。
ifconfig不带参数,只打印处于激活状态的网络接口。
[root@jfht ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:1B:78:40:8C:20
inet addr:211.103.28.xx Bcast:211.103.28.31 Mask:255.255.255.224
inet6 addr: fe80::21b:78ff:fe40:8c20/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:134856806 errors:0 dropped:0 overruns:0 frame:0
TX packets:140723373 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1680519599 (1.5 GiB) TX bytes:2804853589 (2.6 GiB)
Interrupt:114 Memory:fa000000-fa012800
现在解释一下输出信息的含义:
eth0:网络接口
link encap:网络类型
HWaddr:网卡物理地址
Inet addr :IP地址
Bcast:广播地址
Mask:子网掩码
UP:正在使用的网络接口
RX packets,TX packets接收和传输的数据包个数
RX byte,TX byte表示接搜和传输的具体数目
Interrupt:终端信息
Base address:内存地址
eth1 Link encap:Ethernet HWaddr 00:1B:78:40:8C:22
inet addr:192.168.1.191 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::21b:78ff:fe40:8c22/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:29821173 errors:0 dropped:0 overruns:0 frame:0
TX packets:28680326 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4264958692 (3.9 GiB) TX bytes:427504706 (407.7 MiB)
Interrupt:122 Memory:f8000000-f8012800
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:30263265 errors:0 dropped:0 overruns:0 frame:0
TX packets:30263265 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:63016162 (60.0 MiB) TX bytes:63016162 (60.0 MiB)
ifconfig命令跟上-a参数,打印所有配置的网络接口,不论其是否激活。
[root@jfht ~]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:1B:78:40:8C:20
inet addr:211.103.28.xx Bcast:211.103.28.31 Mask:255.255.255.224
inet6 addr: fe80::21b:78ff:fe40:8c20/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:134856877 errors:0 dropped:0 overruns:0 frame:0
TX packets:140723396 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1680524793 (1.5 GiB) TX bytes:2804859207 (2.6 GiB)
Interrupt:114 Memory:fa000000-fa012800
eth1 Link encap:Ethernet HWaddr 00:1B:78:40:8C:22
inet addr:192.168.1.191 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::21b:78ff:fe40:8c22/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:29821183 errors:0 dropped:0 overruns:0 frame:0
TX packets:28680336 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4264959332 (3.9 GiB) TX bytes:427505346 (407.7 MiB)
Interrupt:122 Memory:f8000000-f8012800
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:30263271 errors:0 dropped:0 overruns:0 frame:0
TX packets:30263271 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:63016642 (60.0 MiB) TX bytes:63016642 (60.0 MiB)
sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
ifconfig命令跟上指定网络接口名称,就可以查看具体的网卡信息了。
[root@jfht ~]# ifconfig eth1
eth1 Link encap:Ethernet HWaddr 00:1B:78:40:8C:22
inet addr:192.168.1.191 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::21b:78ff:fe40:8c22/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:29821190 errors:0 dropped:0 overruns:0 frame:0
TX packets:28680343 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4264959780 (3.9 GiB) TX bytes:427505794 (407.7 MiB)
Interrupt:122 Memory:f8000000-f8012800
[root@jfht ~]#
VMWare虚拟机,网络连接采用NAT方式,操作系统为RHEL3.4。从Windows的cmd窗口通过ping命令来确认。
开始时,eth0处于激活状态。
C:\Users\zhy>ping 192.168.227.128
正在 Ping 192.168.227.128 具有 32 字节的数据:
来自 192.168.227.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.227.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.227.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.227.128 的回复: 字节=32 时间<1ms TTL=64
192.168.227.128 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
在Linux的console中执行 ifconfig eth0 down 命令之后,就无法ping通了。
C:\Users\zhy>ping 192.168.227.128
正在 Ping 192.168.227.128 具有 32 字节的数据:
请求超时。
请求超时。
来自 192.168.227.1 的回复: 目标主机无法访问。
请求超时。
192.168.227.128 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 1,丢失 = 3 (75% 丢失),
在Linux的console中执行 ifconfig eth0 up 命令之后,又可以ping通了。
C:\Users\zhy>ping 192.168.227.128
正在 Ping 192.168.227.128 具有 32 字节的数据:
来自 192.168.227.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.227.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.227.128 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.227.128 的回复: 字节=32 时间<1ms TTL=64
192.168.227.128 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
在eth0上已经有一个ip地址了,再在其上增加一个ip地址。
[root@node34 root]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E3:D2:65
inet addr:192.168.227.128 Bcast:192.168.227.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14766 errors:0 dropped:0 overruns:0 frame:0
TX packets:18009 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1530995 (1.4 Mb) TX bytes:3088071 (2.9 Mb)
Interrupt:10 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2310 errors:0 dropped:0 overruns:0 frame:0
TX packets:2310 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:203796 (199.0 Kb) TX bytes:203796 (199.0 Kb)
[root@node34 root]#
[root@node34 root]# ifconfig eth0:1 192.168.227.188 netmask 255.255.255.0
[root@node34 root]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E3:D2:65
inet addr:192.168.227.128 Bcast:192.168.227.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14878 errors:0 dropped:0 overruns:0 frame:0
TX packets:18097 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1541605 (1.4 Mb) TX bytes:3097295 (2.9 Mb)
Interrupt:10 Base address:0x2000
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:E3:D2:65
inet addr:192.168.227.188 Bcast:192.168.227.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:14883 errors:0 dropped:0 overruns:0 frame:0
TX packets:18106 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1541935 (1.4 Mb) TX bytes:3098261 (2.9 Mb)
Interrupt:10 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2312 errors:0 dropped:0 overruns:0 frame:0
TX packets:2312 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:203972 (199.1 Kb) TX bytes:203972 (199.1 Kb)
C:\Users\zhy>ping 192.168.227.188
正在 Ping 192.168.227.188 具有 32 字节的数据:
来自 192.168.227.188 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.227.188 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.227.188 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.227.188 的回复: 字节=32 时间<1ms TTL=64
192.168.227.188 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
[root@node34 root]# ifconfig eth0:1 del 192.168.227.188
[root@node34 root]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E3:D2:65
inet addr:192.168.227.128 Bcast:192.168.227.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15306 errors:0 dropped:0 overruns:0 frame:0
TX packets:18496 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1585467 (1.5 Mb) TX bytes:3141665 (2.9 Mb)
Interrupt:10 Base address:0x2000
eth0:2 Link encap:Ethernet HWaddr 00:0C:29:E3:D2:65
inet addr:192.168.227.189 Bcast:192.168.227.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:15311 errors:0 dropped:0 overruns:0 frame:0
TX packets:18505 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1585797 (1.5 Mb) TX bytes:3142711 (2.9 Mb)
Interrupt:10 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:2322 errors:0 dropped:0 overruns:0 frame:0
TX packets:2322 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:204852 (200.0 Kb) TX bytes:204852 (200.0 Kb)
C:\Users\zhy>ping 192.168.227.188
正在 Ping 192.168.227.188 具有 32 字节的数据:
来自 192.168.227.1 的回复: 目标主机无法访问。
请求超时。
请求超时。
请求超时。
192.168.227.188 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 1,丢失 = 3 (75% 丢失),
用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在。要想将上述的配置信息永远的存的电脑里,那就要修改网卡的配置文件了。
[root@node34 root]# ifconfig eth0:1 192.168.227.189
[root@node34 root]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E3:D2:65
inet addr:192.168.227.128 Bcast:192.168.227.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:215 errors:0 dropped:0 overruns:0 frame:0
TX packets:251 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21887 (21.3 Kb) TX bytes:22716 (22.1 Kb)
Interrupt:10 Base address:0x2000
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:E3:D2:65
inet addr:192.168.227.189 Bcast:192.168.227.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:215 errors:0 dropped:0 overruns:0 frame:0
TX packets:251 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:21887 (21.3 Kb) TX bytes:22716 (22.1 Kb)
Interrupt:10 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:394 errors:0 dropped:0 overruns:0 frame:0
TX packets:394 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:29423 (28.7 Kb) TX bytes:29423 (28.7 Kb)
[root@node34 root]# reboot
Broadcast message from root (pts/1) (Thu Jul 21 19:49:25 2011):
The system is going down for reboot NOW!
[root@node34 root]#
Last login: Wed Jul 20 12:19:18 2011 from 192.168.227.1
[root@node34 root]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:E3:D2:65
inet addr:192.168.227.128 Bcast:192.168.227.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:77 errors:0 dropped:0 overruns:0 frame:0
TX packets:104 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8916 (8.7 Kb) TX bytes:10906 (10.6 Kb)
Interrupt:10 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:354 errors:0 dropped:0 overruns:0 frame:0
TX packets:354 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:25651 (25.0 Kb) TX bytes:25651 (25.0 Kb)
[root@node34 root]#
[root@node34 root]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
[root@node34 root]# cat /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
ONBOOT=yes
#BOOTPROTO=dhcp
BOOTPROTO=static
IPADDR=192.168.227.227
NETMASK=255.255.255.0
ONBOOT=yes
[root@node34 root]# service network restart
正在关闭接口 eth0: [ 确定 ]
关闭环回接口: [ 确定 ]
设置网络参数: [ 确定 ]
弹出环回接口: [ 确定 ]
弹出界面 eth0: [ 确定 ]
[root@node34 root]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:E3:D2:65
inet addr:192.168.227.128 Bcast:192.168.227.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:389 errors:0 dropped:0 overruns:0 frame:0
TX packets:341 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:40273 (39.3 Kb) TX bytes:37785 (36.8 Kb)
Interrupt:10 Base address:0x2000
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:E3:D2:65
inet addr:192.168.227.227 Bcast:192.168.227.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:389 errors:0 dropped:0 overruns:0 frame:0
TX packets:341 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:40273 (39.3 Kb) TX bytes:37785 (36.8 Kb)
Interrupt:10 Base address:0x2000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:355 errors:0 dropped:0 overruns:0 frame:0
TX packets:355 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:25703 (25.1 Kb) TX bytes:25703 (25.1 Kb)
[root@node34 root]#
[root@jfht ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5706 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=static
BROADCAST=211.103.28.31
HWADDR=00:1B:78:40:8C:20
IPADDR=211.103.28.xx
IPV6INIT=yes
IPV6_AUTOCONF=yes
NETMASK=255.255.255.224
NETWORK=211.103.28.0
ONBOOT=yes
[root@jfht ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
# Broadcom Corporation NetXtreme II BCM5706 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=static
BROADCAST=192.168.1.255
HWADDR=00:1B:78:40:8C:22
IPADDR=192.168.1.191
NETMASK=255.255.255.0
NETWORK=192.168.1.0
ONBOOT=yes
[root@jfht ~]#
1、rowcount获取 webtable的行数
2、columncount(row)获取第row行webtable的列数
3、GetCellData(row,column)获取对应行列单元格的值
4、childitem(row,column,micclass,index)获取对应行列micclass对象,可对其进行操作e.g. Browser("Location Management System-").Page("Location Management System-").Frame("main").WebTable("ID"). ChildItem(row,5,"Link",0).click
5.GetRowWithCellText(text,column,row)从第column列第row行开始查找,row++,返回第一次与text值相同的行数e.g. Set table=Browser("Location Management System-").Page("Location Management System-").Frame("main").WebTable("ID")row=table.GetRowWithCellText("876600 ",1,1)
有好几天没怎么写东西了,可能是因为白天有点事情忙着,另外就是觉得自己确实是比较懒的。感觉学习效率不如以前那么高了,有些懒散。为了每天进步一点点是卓越的开始,只好继续写了。
1)IF语句的退出。使用EXITTEST,如下所有示例子:
Dim j
For j=0 to 4
print j
if(j=3) then
Exittest
end if
Next
QTP HELP中关于EXITTEST的相关释义:
Exits the entire QuickTest test or Quality Center business process test, regardless of the run-time iteration settings. The pass or fail status of the test remains as it was in the step prior to theExitTeststatement.
ExitTest[(RetVal)]
Argument |
Type |
Description |
---|---|---|
RetVal
|
Variant
|
Optional.The return value.
|
The following example uses theExitTeststatement to end the test run if a checkpoint on theuserNameedit box fails.
res = Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Check ( CheckPoint("userName") )
If res = False Then
ExitTest
End If
2)ExitTestIteration.退出业务流程测试的当前循环并继续下一次循环,或者如果没有其他运行时参数循环,则退出测试运行。 (转).关于ExitTestIteration的QTP HELP中如下释义及例子.
Exits the current iteration of the QuickTest test or Quality Center business process test and proceeds to the next iteration, or exits the test run if there are no additional run-time parameter iterations. The pass or fail status of the test iteration remains as it was in the step prior to theExitTestIterationstatement.
ExitTestIteration[(RetVal)]
Argument |
Type |
Description |
---|---|---|
RetVal
|
Variant
|
Optional.The return value.
|
The following example uses theExitTestIterationstatement to end the test run if a checkpoint on theuserNameedit box fails.
res = Browser("Welcome: Mercury Tours").Page("Welcome: Mercury Tours").WebEdit("userName").Check ( CheckPoint("userName") )
If res = False Then
ExitTestIteration
End If
3)FOR循环语句强制退出.EXIT FOR
提供一种退出For循环的方法。只能在For...Next或For Each...Next循环中使用。Exit For将控制权转移到Next之后的语句。在嵌套的For循环中使用时,Exit For将控制权转移到循环所在位置的上一层嵌套循环。
Provides a way to exit aForloop. It can be used only in aFor...NextorFor Each...Nextloop.Exit Fortransfers control to the statement following theNextstatement. When used within nestedForloops,Exit Fortransfers control to the loop that is one nested level above the loop where it occurs.
4)DO..LOOP循环语句强制退出.EXIT DO
提供一种退出Do...Loop语句的方法。只能在Do...Loop语句中使用。Exit Do将控制权转移到Loop语句之后的语句。在嵌套的Do...Loop语句中使用时,Exit Do将控制权转移到循环所在位置的上一层嵌套循环。
Provides a way to exit aDo...Loopstatement. It can be used only inside aDo...Loopstatement.Exit Dotransfers control to the statement following theLoopstatement. When used within nestedDo...Loopstatements,Exit Dotransfers control to the loop that is one nested level above the loop where it occurs.
5)EXIT FUNCTION
立即从出现的位置退出Function过程。继续执行调用Function的语句后面的语句。
Immediately exits theFunctionprocedure in which it appears. Execution continues with the statement following the statement that called theFunction.
6)Exit Property
在Property过程中,可以使用Exit Property退出过程。程序会从调用Property过程的语句之后的语句继续执行。
Immediately exits thePropertyprocedure in which it appears. Execution continues with the statement following the statement that called thePropertyprocedure.
7)Exit Sub
立即从出现的位置退出Sub过程,继续执行调用Sub的语句后面的语句。
Immediately exits theSubprocedure in which it appears. Execution continues with the statement following the statement that called theSub.
关于以上退出语句相关的EXAMPLE如下所示:
The following example illustrates the use of theExitstatement:
Sub RandomLoop Dim I, MyNum Do ' Set up infinite loop. For I = 1 To 1000 ' Loop 1000 times. MyNum = Int(Rnd * 100) ' Generate random numbers. Select Case MyNum ' Evaluate random number. Case 17: MsgBox "Case 17"Exit
For ' If 17, exit For...Next. Case 29: MsgBox "Case 29"Exit
Do ' If 29, exit Do...Loop. Case 54: MsgBox "Case 54"Exit
Sub ' If 54, exit Sub procedure. End Select Next Loop End Sub
综合以上的实例,增加几个语句:
Dim j
j=1 '当J=0时会调用RandomLoop,当J=1时会强制退出IF判断语句,不会调用RANDOMLOOP并打印出该程序未调用RANDOMLOOP.
If j=0 Then
Call RandomLoop
Else
Print "该程序未调用RandomLoop"
'exittest
End If
Sub RandomLoop
Dim I, MyNum
Do ' Set up infinite loop.
For I = 1 To 1000 ' Loop 1000 times.
MyNum = Int(Rnd * 100) ' Generate random numbers.
Select Case MyNum ' Evaluate random number.
Case 17: MsgBox "Case 17"
Exit For ' If 17, exit For...Next.
Case 29: MsgBox "Case 29"
Exit Do ' If 29, exit Do...Loop.
Case 54: MsgBox "Case 54"
Exit Sub ' If 54, exit Sub procedure.
End Select
Next
Loop
End Sub
PS:END与EXIT不一样,END是结束一个结构,EXIT是强制退出一个结构(转)
(qtp)Reporter对象的ReportEvent方法
2010-02-06 11:21:02| 分类: QTP | 标签: |字号大中小 订阅
描述
在test result中报告测试结果。
语法
Reporter.ReportEvent EventStatus, ReportStepName, Details [, in]
Argument
Type
Descrīption
EventStatus
Number or pre-defined constant
状态值:
0 或 micPass:将本步骤的运行结果状态设置为“Pass”,并向Result中产生报告信息。
如果想在报告中生成“通过”报告,用本状态值。
1 或 micFail: 将本步骤的运行结果状态设置为“Fail”,并向Result中产生报告信息。当脚本中运行本语句时,整个测试的结果状态是“fails”。
如果想在报告中生成“失败”报告,用本状态值。如果运行了本语句,则整个测试的状态为“Fail”。
2 或 micDone:仅向Result中产生报告信息,但不影响整个测试的结果状态。
如果想在报告中生成“完成”报告,用本状态值。
3 或 micWarning: S向Result中产生报告信息,但是不会中断测试的运行,也不影响测试的 pass/fail status。
如果想在报告中生成“警告”报告,用本状态值。运行这个语句后,整个测试结果状态为“Warning”。
ReportStepName
String
将在报告中显示的步骤名称(object name).
Details
String
报告的详细信息。这些信息是本条报告的“Details”信息。
in
N/A
Not in use.
举例: 下面的例子使用ReprotEvent方法来报告一个失败信息。
Reporter.ReportEvent 1, "Custom Step", "The user-defined step failed."
或
Reporter.ReportEvent micFail, "Custom Step", "The user-defined step failed."
2. MsgBox 函数
在运行脚本的过程中,弹出对话框,等待用户手工点击按钮干预。本语句根据用户点击按钮的情况得到返回值。
这个语句适用于脚本的调试过程。
Ø 语法
MsgBox(prompt[, buttons][, title][, helpfile, context])
Ø 参数
prompt 将在对话框中显示的信息。最大长度为1024字符。如果内容有多行,可以用(Chr(13))来表示回车符,或用(Chr(10))表示换行符,或用(Chr(13) & Chr(10))表示回车-换行符。
buttons 按钮的值。默认值为0。
title 弹出框的标题,将显示在标题栏。
Ø Settings
按钮值的说明:
内容
值
描述
vbOKOnly
0
只显示OK按钮
vbOKCancel
1
显示OK以及Cancel按钮。
vbAbortRetryIgnore
2
显示Abort、Retry以及Ignore按钮。
vbYesNoCancel
3
显示Yes、No以及Cancel按钮
vbYesNo
4
显示Yes和No按钮
vbRetryCancel
5
显示Retry和Cancel按钮
vbCritical
16
Display Critical Message icon.
vbQuestion
32
Display Warning Query icon.
vbExclamation
48
Display Warning Message icon.
vbInformation
64
Display Information Message icon.
vbDefaultButton1
0
First button is default.
vbDefaultButton2
256
Second button is default.
vbDefaultButton3
512
Third button is default.
vbDefaultButton4
768
Fourth button is default.
vbApplicationModal
0
应用程序模式。用户必须对信息框做出响应,脚本运行才能继续。
vbSystemModal
4096
系统模式。所有的应用被挂起,直到用户对信息框做出响应。
Ø 返回值
MsgBox功能的返回值
内容
值
按钮
vbOK
1
OK
vbCancel
2
Cancel
vbAbort
3
Abort
vbRetry
4
Retry
vbIgnore
5
Ignore
vbYes
6
Yes
vbNo
7
No
用 变量名=MsgBox(prompt[, buttons][, title][, helpfile, context])的方法获取返回值。
3. InputBox函数
弹出对话框,等待用户输入内容或点击按钮。返回值是输入的内容。
Ø 语法
InputBox(prompt[, title][, default][, xpos][, ypos][, helpfile, context])
Ø Arguments
prompt 将在对话框中显示的信息。最大长度为1024字符。如果内容有多行,可以用(Chr(13))来表示回车符,或用(Chr(10))表示换行符,或用(Chr(13) & Chr(10))表示回车-换行符。
title 弹出框的标题,将显示在标题栏。
default 输入框的默认值。
Ø 例
Dim Input
Input = InputBox("Enter your name")
MsgBox ("You entered: " & Input)
4. WshSell对象的Popup Method
在一个弹出框中显示文本信息。
Ø 语法
intButton = object.Popup(strText,[nSecondsToWait],[strTitle],[nType])
Ø Arguments
object WshShell对象.
strText 希望在弹出框中显示的文本信息。
nSecondsToWait 可选。希望弹出框保持显示的最长时间。(单位秒)。
strTitle 弹出框的标题
nType 一个数值,代表希望在弹出框中显示的按钮或图标。这个值决定了如何使用信息框。
IntButton 返回值。表示用户点击的按钮值。
Ø 注意
无论which host executable file is running (Wscrīpt.exe or Cscrīpt.exe),Popup method都会弹出信息框。
如果nSecondsToWaitis 为0,弹出框一直等到用户干预才关闭。如果nSecondsToWaitis 大于0,如果没有用户干预,则弹出框一直等到nSecondsToWaitis时间后自动关闭。
如果不设置“strtitle”,则弹出框的标题默认为"Windows scrīpt Host."。
“nType”的意思与MessageBox function的ntype相同。
按钮值
值
描述
0
显示OK按钮.
1
显示OK及Cancel按钮。
2
显示Abort, Retry, 及Ignore按钮。
3
显示Yes, No, 及Cancel按钮。
4
显示Yes及 No按钮。
5
显示 Retry 及 Cancel按钮。
图标类型值
值
描述
16
显示"Stop Mark"图标。
32
显示 "Question Mark"图标。
48
显示 "Exclamation Mark"图标。
64
显示"Information Mark"图标。
返回值
如果用户没有在窗口等待的时间范围内(nSecondsToWait)点击按钮,则返回-1。
值
描述
1
OK按钮
2
Cancel 按钮
3
Abort 按钮
4
Retry 按钮
5
Ignore 按钮
6
Yes 按钮
7
No 按钮
Ø Example
[VBscrīpt]
Dim WshShell, BtnCode
Set WshShell = Wscrīpt.CreateObject("Wscrīpt.Shell")
BtnCode = WshShell.Popup("Do you feel alright?", 7, "Answer This Question:", 4 + 32)
Select Case BtnCode
case 6 Wscrīpt.Echo "Glad to hear you feel alright."
case 7 Wscrīpt.Echo "Hope you're feeling better soon."
case -1 Wscrīpt.Echo "Is there anybody out there?"
End Select
获取RO对象的text属性
'SystemUtil.Run "startclient.bat","","D:\EZview\ZST-release\client\bin",""
Dim a,b,c
'a=JavaDialog("登录").JavaButton("登录").Gettoproperty("text")
a=JavaDialog("登录").JavaButton("登录").Getroproperty("text")
JavaDialog("登录").JavaButton("登录").click
b=JavaDialog("EzView").JavaButton("确定").Getroproperty("text")
c=a&" "&b
msgbox c
DataTable.ImportSheet(FileName,SheetSource,SheetDest)
DataTable.ExportSheet(FileName,DTSheet)
用上述的方法,在脚本中导入导出excel中的数据。对应的是文件名,文件路径,还有excel的sheet名。
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''函数功能:Quick 和 Robot 常用库函数''''''''''''''''''''''''''''''
'''''说明:1.以QTP_开头的函数只适用于QuickTest''''''''''''''''''''''''
''''' 2.以Robot_开头的函数只适用于Robot''''''''''''''''''''''''''
''''' 3.除以上外,QuickTest和Robot都适用'''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''以下为QuickTest和Robot都适用函数''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'生成整数随机数
Public Function Rand(min,max)
Randomize '对随机数生成器做初始化的动作。
Rand = Int((max * Rnd) + min)
End Function
'脚本之间共享变量,以及相互调用函数
Public Sub Include(sInstFile)
Dim oFSO, f, s
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set f = oFSO.OpenTextFile(sInstFile)
s = f.ReadAll
f.Close
ExecuteGlobal s
End Sub
'获取当前日期
Public Function Get_Data()
Dim currentDate
currentDate = Date
Get_Data = currentDate
End Function
'月日年 122611
Public Function Converts_Data()
Dim currentDate,year1,month1,day1,date1
currentDate = Date
year1 = Mid(currentDate,3,2)
If(Mid(currentDate,7,1)<>"-")Then
month1 = Mid(currentDate,6,2)
Else
month1 = "0"&Mid(currentDate,6,1)
End If
temp = (Len(currentDate)-1)
If(Mid(currentDate,temp,1)<>"-")Then
day1 = right(currentDate,2)
day1 = day1+1
Else
day1 = right(currentDate,1)+1
day1 = "0"&day1
End If
date1 = month1&day1&year1
Converts_Data = date1
End Function
'获取当前时间
Public Function Get_Time()
Dim currentTime
currentTime = Time
Get_Time = currentTime
End Function
'随机函数生成
'输入值:生成值范围 i~j
'返回值:随机数
Public Function Get_RandNum(fromNum,toNum)
If (fromNum<0) Or (toNum<0) Then
MsgBox "只接受大于零的输入"
ElseIf fromNum>toNum then
MsgBox "起始值必须小于结束值"
Else
Dim RunTime
Randomize
RunTime = Int((10 * Rnd) + 1)
Dim MyValue,i
For i = 1 To RunTime
Randomize
MyValue = Int(((toNum - fromNum + 1) * Rnd) + (fromNum))
Next
Get_randNum=MyValue
End If
End Function
'值交换函数
Public Sub swap(byref a,byref b)
Dim c
c = a
a = b
b = c
End Sub
'是否是质数函数
'是质数返回true,否则返回false
Function IsPrimeNumber(num)
Dim i,flag
flag = true
If num = 1 Then
flag = False
ElseIf num < 1 Then
MsgBox "只能接受大于0的数"
flag = False
Else
For i = 2 To (num - 1)
If ((num Mod i) = 0) Then
flag = False
Exit For
End If
Next
End If
IsPrimeNumber = flag
End Function
'读指定文本文件指定行内容
Function ReadLine(pathway, rowcount)
Dim fso,myfile,i,flag
flag = 1
Set fso=CreateObject("scripting.FileSystemObject")
If fso.FileExists(pathway) then
Set myfile = fso.openTextFile(pathway,1,false)
Else
flag = 0
End If
For i=1 to rowcount-1
If Not myfile.AtEndOfLine Then
myfile.SkipLine
End If
Next
If flag = 1 then
If Not myfile.AtEndOfLine Then
ReadLine = myfile.ReadLine
Else
ReadLine = "文本越界"
End If
myfile.close
Else
ReadLine = "文件不存在"
End If
End Function
'随机生成字符串
Function MakeString(inputlength)
Dim I,x,B,A
If IsNumeric(inputlength) Then
For I = 1 To inputlength
A = Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
Randomize
x=Get_RandNum(0,35)
B = A(x)
makestring =makestring +B
Next
MakeString = makestring
else
msgbox ("只接受数字输入")
End If
End Function
'启动资源管理器
Sub ZYGLQ()
Dim WshShell
set WshShell = CreateObject("Wscript.Shell")
WshShell.SendKeys "^+{ESC}"
Set WshShell = nothing
End Sub
'启动运行
Sub Run()
Dim WshShell
set WshShell = CreateObject("Wscript.Shell")
WshShell.SendKeys "^{ESC}R"
Set WshShell = nothing
End Sub
'发送电子邮件
Function SendMail(SendTo, Subject, Body, Attachment)
Dim ol,mail
Set ol=CreateObject("Outlook.Application")
Set Mail=ol.CreateItem(0)
Mail.to=SendTo
Mail.Subject=Subject
Mail.Body=Body
If (Attachment <> "") Then
Mail.Attachments.Add(Attachment)
End If
Mail.Send
ol.Quit
Set Mail = Nothing
Set ol = Nothing
End Function
'去掉字符串中的重复项
Function NoRepeat(Inp,Sp)
Dim aa,flag,words,length,i,j,k,sp1,sp2,cc
aa = Inp
Do
flag = False
words = Split(aa,Sp)
length = UBound(words)
For i = 0 To (length -1)
sp1 = words(i)
For j = (i+1) To length
sp2 = words(j)
If sp1 = sp2 Then
flag = True
aa = ""
For k = 0 To (j-1)
aa = aa & words(k) & sp
Next
For k = (j + 1) To length
aa = aa & words(k) & sp
Next
cc = Len(aa)
aa = Left(aa,(cc - 1))
End If
Next
If flag = True Then
Exit For
End if
Next
Loop Until flag = false
NoRepeat = aa
End Function
'求字符串长度(中文算2个西文字符)
Function GetLen(Str)
Dim singleStr, i, iCount
iCount = 0
For i = 1 to len(Str)
singleStr = mid(Str,i,1)
If asc(singleStr) < 0 Then
iCount = iCount + 2
Else
iCount = iCount + 1
End If
Next
GetLen = iCount
End Function
'运行指定程序
Sub RunApp(command)
Dim WshShell
set WshShell = CreateObject("Wscript.Shell")
WshShell.Exec command
End Sub
'求下一天是几号的函数
Function Nextday(ByVal inputday)
Dim temp, num, OPYear, OPMonth, OPDay, ret, flag
temp = Split(CStr(inputday), "-")
num = UBound(temp) + 1
OPYear = temp(0)
OPMonth = temp(1)
OPDay = temp(2)
flag = 0
If OPMonth = 1 Or OPMonth = 3 Or OPMonth = 5 Or OPMonth = 7 Or OPMonth = 8 Or OPMonth = 10 Or OPMonth = 12 Then
If OPDay > 31 Or OPDay < 1 Then
flag = 1
End If
ElseIf OPMonth = 4 Or OPMonth = 6 Or OPMonth = 9 Or OPMonth = 11 Then
If OPDay > 30 Or OPDay < 1 Then
flag = 1
End If
Else
If ISLeapYear(OPYear) Then
If OPDay > 29 Or OPDay < 1 Then
flag = 1
End If
Else
If OPDay > 28 Or OPDay < 1 Then
flag = 1
End If
End If
End If
If flag = 1 Or num <> 3 Then
MsgBox "输入参数不对劲", , "Nextday函数提示"
Else
If OPMonth = 1 Or OPMonth = 3 Or OPMonth = 5 Or OPMonth = 7 Or OPMonth = 8 Or OPMonth = 10 Or OPMonth = 12 Then 'big month
If OPDay = 31 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
ElseIf OPMonth = 4 Or OPMonth = 6 Or OPMonth = 9 Or OPMonth = 11 Then 'small month
If OPDay = 30 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
Else 'February
If ISLeapYear(OPYear) Then
If OPDay = 29 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
Else
If OPDay = 28 Then
OPDay = 1
If OPMonth = 12 Then
OPMonth = 1
OPYear = OPYear + 1
Else
OPMonth = OPMonth + 1
OPYear = OPYear
End If
Else
OPDay = OPDay + 1
End If
End If
End If
ret = OPYear & "-" & OPMonth & "-" & OPDay
Nextday = ret
End If
End Function
'是否闰年
Function ISLeapYear(ByVal inYear)
If ((inYear Mod 4 = 0 And inYear Mod 100 <> 0) Or inYear Mod 400 = 0) Then
ISLeapYear = True
Else
ISLeapYear = False
End If
End Function
'计算两个日期之间相隔几天
Function Days(ByVal SourceData, ByVal DesData)
Dim flag, temp1, temp2, OPYear1, OPYear2, OPMonth1, OPMonth2, OPDay1, OPDay2, i, tempDay
temp1 = Split(SourceData, "-")
temp2 = Split(DesData, "-")
If ((UBound(temp1) + 1) <> 3) Or ((UBound(temp2) + 1) <> 3) Then
MsgBox "输入参数不对劲", , "Days函数提示"
End If
OPYear1 = temp1(0)
OPMonth1 = temp1(1)
OPDay1 = temp1(2)
OPYear2 = temp2(0)
OPMonth2 = temp2(1)
OPDay2 = temp2(2)
If CInt(OPYear1) <> CInt(OPYear2) Then
If CInt(OPYear1) > CInt(OPYear2) Then
flag = "big"
ElseIf CInt(OPYear1) < CInt(OPYear2) Then
flag = "small"
End If
Else
If CInt(OPMonth1) <> CInt(OPMonth2) Then
If CInt(OPMonth1) > CInt(OPMonth2) Then
flag = "big"
ElseIf CInt(OPMonth1) < CInt(OPMonth2) Then
flag = "small"
End If
Else
If CInt(OPDay1) <> CInt(OPDay2) Then
If CInt(OPDay1) > CInt(OPDay2) Then
flag = "big"
ElseIf CInt(OPDay1) < CInt(OPDay2) Then
flag = "small"
End If
Else
flag = "="
End If
End If
End If
If (flag = "big") Then
i = 1
tempDay = DesData
Do
tempDay = Nextday(tempDay)
i = i + 1
Loop Until tempDay = SourceData
i = i - 1
ElseIf (flag = "small") Then
i = 1
tempDay = SourceData
Do
tempDay = Nextday(tempDay)
i = i + 1
Loop Until tempDay = DesData
i = i - 1
Else
i = 0
End If
Days = i
End Function
'检查身份证号是否正确
Function Identification(Text1)
xian = Text1
If (Not IsNumeric(Left(Text1, 15)) And Not IsNumeric(Left(Text1, 18))) Or Text1 = "" Then
Identification = False
Exit Function
End If
lenx = Len(Trim(Text1))
If lenx = 15 Or lenx = 18 Then
If lenx = 15 Then
yy = "19" & Mid(xian, 7, 2)
mm = Mid(xian, 9, 2)
dd = Mid(xian, 11, 2)
aa = Right(xian, 1)
End If
If lenx = 18 Then
yy = Mid(xian, 7, 4)
mm = Mid(xian, 11, 2)
dd = Mid(xian, 13, 2)
aa = Right(xian, 1)
End If
If CInt(mm) > 12 Or CInt(dd) > 31 Then
Identification = False
Exit Function
Else
Identification = True
Exit Function
End If
Else
Identification = False
Exit Function
End If
End Function
'检查是否存在数字
Function checkString (myString)
checkString = False
Dim myChr
For myChr = 48 to 57
If InStr(myString,Chr(myChr)) > 0 Then
checkString = True
Exit Function
End If
Next
End Function
'查询Access数据库字符出现次数
Function Access_GetCount(DBlocation,TableName,Value)
set con=createobject("adodb.connection")
con.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & DBlocation
set record = createobject("adodb.recordset")
sql="select * from " & TableName
record.open sql,con
DO
if(record("name")=Value)then
num=num+1
end If
record.MoveNext
loop until record.eof=True
record.close
set record=Nothing
con.close
set con=Nothing
If num = 0 Then
Access_GetCount = 0
Else
Access_GetCount = num
End If
End Function
'按ASCII码值冒泡排序
Function BubbleSort(VString,Spl,Func)
Dim Str,StrLength,i,j
Str = Split(VString,Spl)
StrLength = UBound(Str) + 1
For i = 1 To (StrLength-1)
For j = (i+1) To StrLength
If Func = 1 then
If Asc(Str(i-1)) < Asc(Str(j-1)) Then
Call Swap(Str(i-1),Str(j-1))
End If
Else
If Asc(Str(i-1)) > Asc(Str(j-1)) Then
Call Swap(Str(i-1),Str(j-1))
End If
End If
Next
Next
j = ""
For i = 1 To StrLength
j = j & Str(i-1) & Spl
Next
j = Left(j,(StrLength * 2 -1))
BubbleSort = j
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''以下为仅QuickTest适用函数'''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'让QTP运行时保持最小化
Public Sub QTP_Small()
Dim objQTPWin
Set objQTPWin = GetObject("" , "QuickTest.Application")
objQTPWin.WindowState = "Minimized"
Set objQTPWin = Nothing
End Sub
'恢复QTP窗口
Public Sub QTP_Big()
Dim objQTPWin
Set objQTPWin = GetObject("" , "QuickTest.Application")
objQTPWin.WindowState = "Restored"
Set objQTPWin = Nothing
End Sub
'写文件函数(追加)
'输入值:写入内容
Public Function QTP_WriteFile(pathway,words)
Dim fileSystemObj,fileSpec,logFile,way
Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
fileSpec = pathway
Set logFile = fileSystemObj.OpenTextFile(fileSpec, 8, true)
logFile.WriteLine (CStr(words))
logFile.Close
Set logFile = Nothing
End Function
'写文件函数(改写)
'输入值:写入内容
Public Function QTP_WriteFile_Change(pathway,words)
Dim fileSystemObj,fileSpec,logFile,way
Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
fileSpec = pathway
Set logFile = fileSystemObj.OpenTextFile(fileSpec, 2, true)
logFile.WriteLine (CStr(words))
logFile.Close
Set logFile = Nothing
End Function
'读Excel文件元素
Public Function QTP_Read_Excel(pathway,sheetname,x,y)
Dim srcData,srcDoc,ret
set srcData = CreateObject("Excel.Application")
srcData.Visible = True
set srcDoc = srcData.Workbooks.Open(pathway)
srcDoc.Worksheets(sheetname).Activate
ret = srcDoc.Worksheets(sheetname).Cells(x,y).value
srcData.Workbooks.Close
Window("text:=Microsoft Excel").Close
QTP_Read_Excel = ret
End Function
'写Excel文件元素并保存退出
Public Function QTP_Write_Excel(pathway,sheetname,x,y,content)
Dim srcData,srcDoc,sp1,sp2,num,use,a1,a2,a3
set srcData = CreateObject("Excel.Application")
srcData.Visible = True
set srcDoc = srcData.Workbooks.Open(pathway)
srcDoc.Worksheets(sheetname).Activate
srcDoc.Worksheets(sheetname).Cells(x,y).value = content
' sp1 = Split(pathway,".")
' sp2 = Split(sp1(0),"\")
' num = UBound(sp2)
' use = sp2(num)
' Set a1 = Description.Create()
' a1("text").value="Microsoft Excel - " + use + ".xls"
' a1("window id").value="0"
' Set a3 = Description.Create()
' a3("Class Name").value="WinObject"
' a3("text").value= use + ".xls"
' Window(a1).WinObject(a3).Type micCtrlDwn + "s" + micCtrlUp
Dim WshShell
Set WshShell=CreateObject("Wscript.Shell")
WshShell.SendKeys "^s"
wait(1)
srcData.Workbooks.Close
Set srcDoc = nothing
Window("text:=Microsoft Excel").Close
End Function
'定时停留弹出框函数
Sub QTP_Msgbox(Value,waitTime,Title)
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Popup Value, waitTime, Title
Set WshShell = Nothing
End Sub
'改变Excel的单元格颜色
Public Function QTP_Change_Color(pathway,sheetname,x,y,color)
Dim srcData,srcDoc,sp1,sp2,num,use,a1,a2,a3
set srcData = CreateObject("Excel.Application")
srcData.Visible = True
set srcDoc = srcData.Workbooks.Open(pathway)
srcDoc.Worksheets(sheetname).Activate
If color = "red" Then
srcDoc.Worksheets(sheetname).Cells(x,y).Interior.color=vbred
ElseIf color = "green" Then
srcDoc.Worksheets(sheetname).Cells(x,y).Interior.color=vbgreen
Else
MsgBox "输入的颜色参数不正确,只接收""red""和""green"""
End If
Dim WshShell
Set WshShell=CreateObject("Wscript.Shell")
WshShell.SendKeys "^s"
wait(1)
srcData.Workbooks.Close
Set srcDoc = nothing
Window("text:=Microsoft Excel").Close
End Function
'捕获当前屏幕(截图)
Public Function QTP_Capture(pathway)
Dim datestamp
Dim filename
datestamp = Now()
filename = Environment("TestName")&"_"&datestamp&".png"
filename = Replace(filename,"/","")
filename = Replace(filename,":","")
filename = pathway + "\" + ""&filename
Desktop.CaptureBitmap filename
'Reporter.ReportEvent micFail,"image","<img src='" & filename & "'>"
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''QuickTestPlus 帮助文件对于Excel库函数 仅QTP适用''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim ExcelApp 'As Excel.Application
Dim excelSheet 'As Excel.worksheet
Dim excelBook 'As Excel.workbook
Dim fso 'As Scripting.FileSystemObject
Function CreateExcel() 'As Excel.Application
Dim excelSheet 'As Excel.worksheet
Set ExcelApp = CreateObject("Excel.Application") 'Create a new excel Object
ExcelApp.Workbooks.Add
ExcelApp.Visible = True
Set CreateExcel = ExcelApp
End Function
Sub CloseExcel(ExcelApp)
Set excelSheet = ExcelApp.ActiveSheet
Set excelBook = ExcelApp.ActiveWorkbook
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
fso.CreateFolder "C:\Temp"
fso.DeleteFile "C:\Temp\ExcelExamples.xls"
excelBook.SaveAs "C:\Temp\ExcelExamples.xls"
ExcelApp.Quit
Set ExcelApp = Nothing
Set fso = Nothing
Err = 0
On Error GoTo 0
End Sub
Function SaveWorkbook(ExcelApp, workbookIdentifier, path) 'As String
Dim workbook 'As Excel.workbook
On Error Resume Next
Set workbook = ExcelApp.Workbooks(workbookIdentifier)
On Error GoTo 0
If Not workbook Is Nothing Then
If path = "" Or path = workbook.FullName Or path = workbook.Name Then
workbook.Save
Else
Set fso = CreateObject("Scripting.FileSystemObject")
If InStr(path, ".") = 0 Then
path = path & ".xls"
End If
On Error Resume Next
fso.DeleteFile path
Set fso = Nothing
Err = 0
On Error GoTo 0
workbook.SaveAs path
End If
SaveWorkbook = 1
Else
SaveWorkbook = 0
End If
End Function
Sub SetCellValue(excelSheet, row, column, value)
On Error Resume Next
excelSheet.Cells(row, column) = value
On Error GoTo 0
End Sub
Function GetCellValue(excelSheet, row, column)
value = 0
Err = 0
On Error Resume Next
tempValue = excelSheet.Cells(row, column)
If Err = 0 Then
value = tempValue
Err = 0
End If
On Error GoTo 0
GetCellValue = value
End Function
Function GetSheet(ExcelApp, sheetIdentifier) 'As Excel.worksheet
On Error Resume Next
Set GetSheet = ExcelApp.Worksheets.Item(sheetIdentifier)
On Error GoTo 0
End Function
Function InsertNewWorksheet(ExcelApp, workbookIdentifier, sheetName) 'As Excel.worksheet
Dim workbook 'As Excel.workbook
Dim worksheet 'As Excel.worksheet
'In case that the workbookIdentifier is empty we will work on the active workbook
If workbookIdentifier = "" Then
Set workbook = ExcelApp.ActiveWorkbook
Else
On Error Resume Next
Err = 0
Set workbook = ExcelApp.Workbooks(workbookIdentifier)
If Err <> 0 Then
Set InsertNewWorksheet = Nothing
Err = 0
Exit Function
End If
On Error GoTo 0
End If
sheetCount = workbook.Sheets.Count
workbook.Sheets.Add , sheetCount
Set worksheet = workbook.Sheets(sheetCount + 1)
If sheetName <> "" Then
worksheet.Name = sheetName
End If
Set InsertNewWorksheet = worksheet
End Function
Function CreateNewWorkbook(ExcelApp)
Set NewWorkbook = ExcelApp.Workbooks.Add()
Set CreateNewWorkbook = NewWorkbook
End Function
Function OpenWorkbook(ExcelApp, path)
On Error Resume Next
Set NewWorkbook = ExcelApp.Workbooks.Open(path)
Set OpenWorkbook = NewWorkbook
On Error GoTo 0
End Function
Sub ActivateWorkbook(ExcelApp, workbookIdentifier)
On Error Resume Next
ExcelApp.Workbooks(workbookIdentifier).Activate
On Error GoTo 0
End Sub
Sub CloseWorkbook(ExcelApp, workbookIdentifier)
On Error Resume Next
ExcelApp.Workbooks(workbookIdentifier).Close
On Error GoTo 0
End Sub
Function CompareSheets(sheet1, sheet2, startColumn, numberOfColumns, startRow, numberOfRows, trimed) 'As Boolean
Dim returnVal 'As Boolean
returnVal = True
If sheet1 Is Nothing Or sheet2 Is Nothing Then
CompareSheets = False
Exit Function
End If
For r = startRow to (startRow + (numberOfRows - 1))
For c = startColumn to (startColumn + (numberOfColumns - 1))
Value1 = sheet1.Cells(r, c)
Value2 = sheet2.Cells(r, c)
If trimed Then
Value1 = Trim(Value1)
Value2 = Trim(Value2)
End If
If Value1 <> Value2 Then
Dim cell 'As Excel.Range
sheet2.Cells(r, c) = "Compare conflict - Value was '" & Value2 & "', Expected value is '" & Value1 & "'."
Set cell = sheet2.Cells(r, c)
cell.Font.Color = vbRed
returnVal = False
End If
Next
Next
CompareSheets = returnVal
End Function
'写入word文件
Sub QTP_WriteWord(pathway,content)
Dim oWord,oRange,oDoc
Set oWord = CreateObject("Word.Application")
oWord.documents.open pathway,forwriting, True
Set oDoc = oWord.ActiveDocument
Set oRange = oDoc.content
oRange.insertafter content
oWord.ActiveDocument.Save
' Dim WshShell
' Set WshShell=CreateObject("Wscript.Shell")
' WshShell.SendKeys "^s"
' wait(1)
oWord.Application.Quit True
Set oRange = Nothing
Set oDoc = Nothing
Set oWord = Nothing
End Sub
另外,请参考:
【notepad++列编辑】
通常我们编辑文件的方式是行编辑,Notepad++还有一种列编辑模式。顾名思义,列编辑就是能够按列对文件进行编辑,操作方法如下:
1. 同时编辑连续的列区域:
鼠标先在要进行列编辑的起点点击,再同时按shift+alt不放,鼠标在要进行列编辑的结尾区域点击。
2. 在起点到文档结尾所有列插入数据:
鼠标先在要插入数据的位置点击,再按alt+c,在弹出的对话框中输入要插入的数据,确定后就在后面所有列插入数据了。
3. 同时在不连续的列插入数据:
先在菜单:设置-首选项-编辑中,选中“multi-editing settings”的"enable(ctl+mouse click/selection)"
按住ctl不放,同时鼠标左键点击不连续的行,点击的位置就是要同时插入数据的位置。
标签: 杂谈 |
分类: QTP/VBS20100524 |
方法 1. 使用 "InvokeApplication" 命令调用可执行应用程序
Note: In most situations, you should use a SystemUtil.Run statement to run applications or to open files in their default application. The InvokeApplication statement is supported primarily for backward compatibility.
例子:
InvokeApplication "E:\Program Files\Internet Explorer\IEXPLORE.EXE"
方法 2. 使用 "SystemUtil.Run" 命令打开一个文件或应用程序
When specifying a non-executable file, the file opens in the associated application.
Note: A SystemUtil.Run statement is automatically added to your test when you run an application from the Start menu or the Run dialog box while recording a test.
Tip: You can also use this method to perform operations on the specified file, similar to the usage of the Windows ShellExecute command.
例子:
SystemUtil.Run “IEXPLORE.EXE”
注意:SystemUtil.Run 和 InvokeApplication的区别在于是否需要指定完整路径
例:
Open a Text File in the Default Text Application (Notepad)
Sub CloseDescendentProcesses_Example()
'The following example uses the Run method to open a file named type.txt
'in the default text application (Notepad). It then types "happy days",
'saves the file using shortcut keys, and then closes the application.
SystemUtil.Run "C:\type.txt", "", "", ""
Window("Text:=type.txt - Notepad").Type "happy days"
Window("Text:=type.txt - Notepad").Type micAltDwn & "F" & micAltUp
Window("Text:=type.txt - Notepad").Type micLShiftDwn & "S" & micLShiftUp
Window("Text:=type.txt - Notepad").Close
End Sub
方法 3. 使用ExecuteFile 函数执行外部定义的函数
If you decide not to associate a function library (any VBScript file) with a test, but do want to be able to call its functions, subroutines, and so forth from an action in your test or from another function library, you can do so by inserting an ExecuteFile statement in your action.
When you run your test, the ExecuteFile statement executes all global code in the function library making all definitions in the file available from the global scope of the action's script.
注意:用ExecuteFile语句执行的函数文件是不能被QTP调试进去的
(You cannot debug a file that is called using an ExecuteFile statement, or any of the functions contained in the file. In addition, when debugging a test that contains an ExecuteFile statement, the execution marker may not be correctly displayed. )
To execute an externally-defined function:
1. Create a VBScript file using standard VBScript syntax. For more information, see the Microsoft VBScript Language Reference (Help > QuickTest Professional Help > VBScript Reference > VBScript).
2. Store the file in any folder that you can access from the computer running your test.
3. Add an ExecuteFile statement to an action in your test using the following syntax:
ExecuteFile FileName
where FileName is the absolute or relative path of your VBScript file.
4. Use the functions, subroutines, and so forth, from the specified VBScript file as necessary in your action.
方法 4. 使用 "WshShell.Exec" 方法
- Runs an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams.
Remarks
The Exec method returns a WshScriptExec object, which provides status and error information about a script run with Exec along with access to the StdIn, StdOut, and StdErr channels. The Exec method allows the execution of command line applications only. The Exec method cannot be used to run remote scripts. Do not confuse the Exec method with the Execute method (of the WshRemote object).
例子:
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("calc")
Do While oExec.Status = 0
WScript.Sleep 100
Loop
WScript.Echo oExec.Status
参考:
http://www.qtp10.com/2009/11/call-external-file-and-applications-in.html
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Testing_is_believing/archive/2010/03/18/5394213.aspx