Share this page

# Tips & tricks - Web testing

In this topic:

## Work with the Web SDK

Make sure you include:

C#:`using HP.LFT.SDK.Web;`

Java: `import com.hp.lft.sdk.web.*;`

JavaScript: `var Web = LFT.Web;`

Back to top

## Use the Object Identification Center (OIC) with Web objects

Open your browser only after the UFT Developer runtime engine is running.

If you are using UFT Developer with Microsoft Edge Legacy, you must open the browser session with the Edge Agent for Functional Testing, accessible from the Start menu.

Back to top

## Declare your browser in your test

Even if you are working with objects from an application model, declare your browser in the context of your test and then pass the browser as an argument when you instantiate your application model class:

C#

    IBrowser testBrowser = BrowserFactory.Launch(BrowserType.Chrome);
    myWebSiteModel myWebSiteModel = new myWebSiteModel(testBrowser);
    testbrowser.navigate("http://advantageonlineshopping.com/#/");

Java

    Browser testBrowser= BrowserFactory.launch(BrowserType.CHROME);
    hpSite appModel = new hpSite(testBrowser);
    testBrowser.navigate("http://advantageonlineshopping.com/#/");

JavaScript

This example shows the browser variable defined globally, the browser is initialized and launched before each test, and then the navigation occurs inside each test.

For more details on JavaScript test structure, see Setting up and working with the JavaScript SDK.

    describe("HP site",function() {
        var browser;

        beforeEach(function (done) {
            LFT.SDK.init();

            Web.Browser.launch(Web.BrowserType.Chrome)
                .then(function(launchedBrowser){
                    browser = launchedBrowser;
                }).testDone(done);
        });

    it("should select and deselect web list",function(done) {
    	browser.navigate("http://mySite.com");

Back to top

## Decide which browser to use for your Web steps.

- Use the Launch method to open a new browser.
- Use the Attach method to run your steps on an open browser tab (or one that was opened by your application during the session).

Back to top

## Describe objects using XPath or CSS expressions

Use the XPathDescription and CSSDescription classes when it would be difficult to uniquely describe an object using properties and values.

The Object Identification Spy automatically generates suggested values that you can use for the XPath and CSSSelector properties.

Note:

- Keep in mind that XPath and CSS values are ordinal and can be more complex to maintain as your application changes over time.
- If two objects on a page have the same value for their id attribute, the XPath values generated for those objects may be identical.

Back to top

See also:

- Tips and tricks - General
- Tips and tricks - SAP GUI
- Tips & tricks - OCR methods (Windows only)

https://admhelp.microfocus.com UFT Developer 8942
Tips to improve your search results... UFT Developer Help Center UFT Developer Help 15.0-15.0.2 All View Local Help Center View Online Help Center back Go back in browser history forward Go forward in browser history Remove search highlights next topic Go to next topic previous topic Go to previous topic Print the current topic Version: