当前位置:首页 » 自动清洗 » 怎样提高自动化测试
扩展阅读
ppt中空格就转行怎样处理 2024-11-17 23:09:38
怎样做好吃甜点 2024-11-17 22:55:25

怎样提高自动化测试

发布时间: 2023-09-14 10:20:17

A. 如何提高自动化测试的执行效率 selenium java

1. 环境准备
1.1 Java环境
安装, 配置jdk
1.2 Java IDE
因为Selenium支持Java/C#/Ruby/Python/Perl等,这里选择用Java。到Eclipse官方网站下载Eclipse, 解压
1.3 Selenium
到Selenium官方网站http://seleniumhq.org/download/下载Selenium IDE,Selenium Server, Selenium Client Driver
以上三者之间的关系是:
Selenium IDE可以录制脚本,执行脚本,修改脚本,将录制的脚本导出成其他语言(比如Java)---本篇不讨论
Selenium Server是和Selenium Client结合使用的,Server用来启动浏览器,接受Client端的请求,执行test;
Client端则是向Server端发送请求。

2. 在Eclipse中编辑并运行test
2.1 新建一个Java project: File-New-Java Project
2.2 在上一步建好的项目名称上点鼠标右键, 点击Build Path-Add External Archives...,将下载的selenium-java-2.21.0.jar(client)和selenium-server-standalone- 2.21.0.jar(server)加进来

2.3 启动selenium server.进入cmd,运行 "java -jar selenium-server-standalone-2.21.0.jar" --保证能找到改jar包。信息如下:

[java] view plain
信息: Launching a standalone server
22:16:21.484 INFO - Java: Sun Microsystems Inc. 17.1-b03
22:16:21.500 INFO - OS: Windows XP 5.1 x86
22:16:21.515 INFO - v2.21.0, with Core v2.21.0. Built from revision 16552
22:16:21.859 INFO - RemoteWebDriver instances should connect to: http://127.0.0.
1:4444/wd/hub
22:16:21.875 INFO - Version Jetty/5.1.x
22:16:21.875 INFO - Started HttpContext[/selenium-server/driver,/selenium-server
/driver]
22:16:21.875 INFO - Started HttpContext[/selenium-server,/selenium-server]
22:16:21.875 INFO - Started HttpContext[/,/]
22:16:22.062 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@5d173
22:16:22.062 INFO - Started HttpContext[/wd,/wd]
22:16:22.093 INFO - Started SocketListener on 0.0.0.0:4444
22:16:22.093 INFO - Started org.openqa.jetty.jetty.Server@32fb4f
[java] view plain
信息: Launching a standalone server
22:16:21.484 INFO - Java: Sun Microsystems Inc. 17.1-b03
22:16:21.500 INFO - OS: Windows XP 5.1 x86
22:16:21.515 INFO - v2.21.0, with Core v2.21.0. Built from revision 16552
22:16:21.859 INFO - RemoteWebDriver instances should connect to: http://127.0.0.
1:4444/wd/hub
22:16:21.875 INFO - Version Jetty/5.1.x
22:16:21.875 INFO - Started HttpContext[/selenium-server/driver,/selenium-server
/driver]
22:16:21.875 INFO - Started HttpContext[/selenium-server,/selenium-server]
22:16:21.875 INFO - Started HttpContext[/,/]
22:16:22.062 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@5d173
22:16:22.062 INFO - Started HttpContext[/wd,/wd]
22:16:22.093 INFO - Started SocketListener on 0.0.0.0:4444
22:16:22.093 INFO - Started org.openqa.jetty.jetty.Server@32fb4f

2.4 代码测试

[java] view plainprint?
import com.thoughtworks.selenium.DefaultSelenium;

public class SeleniumDemo01
{
public static void main(String[] args)
{
String host = "localhost";
int port = 4444;
String url = "http://www..com/";
String browserType = "*firefox";

String keyWordsLocator = "document.getElementById('kw')";
String search = "document.getElementById('su')";
DefaultSelenium selenium = new DefaultSelenium(host,port,browserType,url);
selenium.start();
selenium.open(url);
selenium.type(keyWordsLocator,"java selenium");
selenium.click(search);
selenium.waitForPageToLoad("50000");
selenium.stop();

}
}
运行结果:
1.firefox浏览器期待
2.打开网络主页
3.在搜索框中键入了"java selenium"
4.点击"网络一下"按钮
5.等等页面加载50s
6.关闭浏览器

B. 如何利用自动化测试提高软件测试效率

测试自动化实施前期 需要考虑很多因素,人力、物力、财力都是需要认真考虑与规划的。自动化测试在整个测试周期中何时开展,哪些测试工作可以由自动化测
试替代,这些都需要在开始部署自动化测试前,认真的思考。影响自动化测试效率的因素,不单单是大家看到可量化的测试工作,还有许多无形的因素影响着自动化
测试,如测试组织的部署等。因此,在真正实施前一定要认真规划和考虑自动化测试实施方案。
自动化测试的实施过程,完全不同于手动测试。自动化测试用例与手工测试用例也大不相同。自动化测试实施过程中,需要不断的开发与维护脚本,因此对测试人员能力有很高的要求。