Share this page

# Tips & tricks - Web testing

The following tips and tricks are relevant when testing web applications.

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 runtime engine is running.

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.

In C#

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

In Java

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

In 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("My 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

## Bring the browser into focus

On a Windows OS, to bring a browser to the foreground, use the browser test object's Activate method. By default, the method's inFocus argument is True to bring the browser into focus to make sure it is ready for input.

For details, see the Java, JavaScript, and .NET SDK References.

## 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 Functional Testing for Developers 8942
Tips to improve your search results... OpenText™ Functional Testing for Developers Help Center OpenText™ Functional Testing for Developers Help 25.2 All View Local Help Center View Online Help Center Version: