2012-11-08 104 views
1

我想使用RFT在網頁上自動執行少量操作。 我經歷了一些鏈接和代碼,我試圖打開一個瀏覽器說谷歌使用RFT腳本。RFT使用腳本打開瀏覽器

我拿了一些代碼,但那不是在打開的瀏覽器上打開谷歌頁面的工作。

我不知道是否需要一些設置? 任何人都可以幫助我嗎?

的代碼,我是:::

import resources.Script1Helper; 
import com.rational.test.ft.*; 
import com.rational.test.ft.object.interfaces.*; 
import com.rational.test.ft.object.interfaces.SAP.*; 
import com.rational.test.ft.object.interfaces.WPF.*; 
import com.rational.test.ft.object.interfaces.dojo.*; 
import com.rational.test.ft.object.interfaces.siebel.*; 
import com.rational.test.ft.object.interfaces.flex.*; 
import com.rational.test.ft.object.interfaces.generichtmlsubdomain.*; 
import com.rational.test.ft.script.*; 
import com.rational.test.ft.value.*; 
import com.rational.test.ft.vp.*; 
import com.ibm.rational.test.ft.object.interfaces.sapwebportal.*; 


public class Script1 extends Script1Helper 
{ 
ProcessTestObject pto = startBrowser("www.google.com"); 
} 

回答

2

在RFT你可以使用startBrowser API如下:

startBrowser("http://wwww.google.com"); //To launch google.com with default browser  

startBrowser("Internet Explorer","http://www.google.com");//To open google with internet explorer.Internet Explorer is the string that identifies the browser , it could be Mozialla Firefox and should be configured in the Enable Environment for testing wizard(in the browser tab)  

RFT還對BrowserTestObject提供API使用loadURL( 「urlstring」)爲例如:

browser_htmlBrowser().loadUrl("http://www.google.com");//Here browser_htmlBrowser comes from the Object Map. 

上面的代碼會在第一次找到瀏覽器測試對象後加載google.com。

您也可以使用Find()api首先查找現有的瀏覽器,然後像上面那樣查找所有loadUrl()。 如:

TestObject[] browsers = find(atChild(".class","Html.HtmlBrowser")); 
    if(browsers.length == 0) 
    { 
     System.err.println("No browsre found"); 
     return; 
    } 
    //Else take the first found object(browser) and load the url 

    ((BrowserTestObject)browsers[0]).loadUrl("http://www.google.com"); 

    unregister(browsers);//Always clean up by calling unregister once done with the objects. 

希望有所幫助。

+0

+1的查找()/註銷() –

+0

嗨普拉卡什,但是這還沒有打開的網址瀏覽器和谷歌類型雖然TC運行沒有任何錯誤罰款,但我希望看到上運行的腳本發生這種情況。我怎樣才能做到這一點?有沒有我缺少的配置設置? – nisha

+0

嗨,startBrowser(「http://google.com」);將啓動在[配置 - >啓用測試環境]中配置的默認瀏覽器。腳本通常會執行給定的語句並完成,並且根據執行的代碼,它可能會等待某個對象執行操作。在startBrowser()之後,您可以讓瀏覽器加載一些睡眠。在上面給出的示例腳本中,沒有「在url上鍵入google」的代碼,它只是使用給定的url啓動瀏覽器。 – Prakash