【问题标题】:RFT open browser using scriptRFT 使用脚本打开浏览器
【发布时间】:2012-11-08 20:31:23
【问题描述】:

我想使用 RFT 自动化网页上的一些操作。 我浏览了一些链接和代码,然后尝试使用 RFT 中的脚本打开浏览器,比如 google。

我拿了一些代码,但这并不能在打开的浏览器上打开谷歌页面。

我不知道是否需要一些设置? 谁能帮我解决这个问题?

我的代码是:::

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");
}

【问题讨论】:

    标签: rft


    【解决方案1】:

    在 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.
    

    希望对您有所帮助。

    【讨论】:

    • 嗨 Prakash,但这并没有打开浏览器并在 url 上键入 google,尽管 TC 运行良好,没有任何错误,但我想在运行脚本时看到这种情况。我该怎么做?我是否缺少任何配置设置?
    • 嗨,startBrowser("google.com"); 将启动在 [Configure -> Enable Environment for Testing] 中配置的默认浏览器。脚本通常会执行给定的语句并完成并取决于在执行的代码上,它可能会等待某个对象执行操作。您可以在 startBrowser() 之后让浏览器加载一些睡眠。在上面给出的示例脚本中,没有“在 url 上键入 google”的代码,它只是启动具有给定 url 的浏览器。