Tips & tricks - Web testing
The following tips and tricks are relevant when testing web applications.
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;
Use the Object Identification Center (OIC) with Web objects
Open your browser only after the runtime engine is running.
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:
IBrowser testBrowser = BrowserFactory.Launch(BrowserType.Chrome); MyWebSiteModel myWebSiteModel = new MyWebSiteModel(testBrowser); testbrowser.navigate("http://advantageonlineshopping.com/#/");
Browser testBrowser= BrowserFactory.launch(BrowserType.CHROME); MySite appModel = new MySite(testBrowser); testBrowser.navigate("http://advantageonlineshopping.com/#/");
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"); } }
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).
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.
See also: