SeleniumIDE與eclipse如何連接使用
第五步:復(fù)制轉(zhuǎn)換的腳本
第六步:新建一個(gè)class
第七步:把復(fù)制的腳本粘貼到eclipse中
第八步:更改錯(cuò)誤
錯(cuò)誤1:
錯(cuò)誤2:
更改的效果:
1. 打開Firefox,利用IDE錄制腳本(依次點(diǎn)擊瀏覽器界面:工具->Selenium IDE)
2. 把錄制好的腳本轉(zhuǎn)換成其他語言(非HTML)
備注1:可以點(diǎn)擊Selenium IDE界面:Option->Format
或是導(dǎo)出為其他語言,點(diǎn)擊Selenium IDE界面:文件->Export Test Case As..
備注2:這里以Java/JUnit4/Remote Control為例
3. 打開eclipse,新建一個(gè)class,把轉(zhuǎn)換的腳本粘貼到class中
4. 在class中建立一個(gè)主函數(shù)
5. 打開selenium服務(wù)器(selenium.bat)
6. 選擇class界面,點(diǎn)擊右鍵,選擇Run as->Java Application
7. 如果運(yùn)行成功,在Console里面就不會(huì)報(bào)錯(cuò),若不能允運(yùn)行成功,其Console里面則會(huì)產(chǎn)生相應(yīng)的提示信息
下面舉例說明:
測(cè)試用例:
1. 打開百度網(wǎng)頁,輸入cydtest,點(diǎn)擊百度一下
2.點(diǎn)擊陳永達(dá)測(cè)試網(wǎng)站的連接,進(jìn)入到陳永達(dá)測(cè)試網(wǎng)站
具體步驟:
第一步:
第二步:
第三步:錄制腳本
第四步:轉(zhuǎn)換語言
第五步:復(fù)制轉(zhuǎn)換的腳本 第六步:新建一個(gè)class 第七步:把復(fù)制的腳本粘貼到eclipse中 第八步:更改錯(cuò)誤 錯(cuò)誤1: 錯(cuò)誤2: 更改的效果:
1 try { 2 ts.test2(); 3 } catch (Exception e1) { 4 e1.printStackTrace(); 5 } |
第九步:打開selenium服務(wù)器
第十步:運(yùn)行腳本
這樣就能把你從IDE上錄制的腳本拿到eclipse中運(yùn)用了
下面是具體的腳本
</pre> package selenium_2; import com.thoughtworks.selenium.*; import org.junit.After; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; import java.util.regex.Pattern; public class test_selenium{ private Selenium selenium; @Before public void setUp(){ //localhost:利用本機(jī)打開瀏覽器 //4444:打開的端口 //*chrome:用Firefox瀏覽器 //http://www.baidu.com/:在IDE界面Base URL里面的網(wǎng)站 selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.baidu.com/"); //啟動(dòng)selenium,前提是selenium服務(wù)器已經(jīng)啟動(dòng) selenium.start(); } @Test public void test2(){ //這里open的地址,是上面地址補(bǔ)充,比如錄制的網(wǎng)址為http://www.baidu.com/XXX.abc,那么這里open("/XXX.abc") selenium.open("/"); //把窗口最大化 selenium.windowMaximize(); selenium.type("id=kw", "cydtest"); selenium.click("id=su"); selenium.waitForPageToLoad("30000"); selenium.click("link=陳永達(dá)的軟件測(cè)試"); } @After public void tearDown() throws Exception { //關(guān)閉selenium,及為關(guān)閉運(yùn)行的瀏覽器 selenium.stop(); } //更改完成后,就自己新建一個(gè)主函數(shù) public static void main(String[] agrs){ //把class轉(zhuǎn)換成一個(gè)實(shí)體 test_selenium ts=new test_selenium(); //用創(chuàng)建的實(shí)體調(diào)用你建立的方法,用于運(yùn)行方法里面的具體操作 ts.setUp(); ts.test2(); } } <pre> |
posted on 2013-07-10 10:34 順其自然EVO 閱讀(304) 評(píng)論(0) 編輯 收藏 所屬分類: selenium and watir webdrivers 自動(dòng)化測(cè)試學(xué)習(xí)