當前位置:首頁 » 自動清洗 » 怎樣提高自動化測試
擴展閱讀
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. 如何利用自動化測試提高軟體測試效率

測試自動化實施前期 需要考慮很多因素,人力、物力、財力都是需要認真考慮與規劃的。自動化測試在整個測試周期中何時開展,哪些測試工作可以由自動化測
試替代,這些都需要在開始部署自動化測試前,認真的思考。影響自動化測試效率的因素,不單單是大家看到可量化的測試工作,還有許多無形的因素影響著自動化
測試,如測試組織的部署等。因此,在真正實施前一定要認真規劃和考慮自動化測試實施方案。
自動化測試的實施過程,完全不同於手動測試。自動化測試用例與手工測試用例也大不相同。自動化測試實施過程中,需要不斷的開發與維護腳本,因此對測試人員能力有很高的要求。