I'm currently working on OPA5 tests for an SAPUI5 application and have encountered an issue with one of my test cases. The specific error I'm facing is: When.onTheWorklistPage.theTableShouldHaveAllEntries is not a function.
Context:
I have a series of OPA5 tests structured within the
ObjectJourneymodule.The test in question aims to verify whether pressing the 'Add' button on the worklist page displays the 'New Product' view.
Problem:
The error occurs at a step in my test scenario when calling the
theTableShouldHaveAllEntriesfunction within theWhen.onTheWorklistPageobject.It seems that this function is not recognized or properly defined within my test setup.
What I've Tried:
Function Definition: Checked the definition of
theTableShouldHaveAllEntrieswithin my page object (Worklist.js) to ensure it's correctly implemented and exported.Usage Verification: Reviewed the usage of
When.onTheWorklistPage.theTableShouldHaveAllEntriesin my test scenario to match the actual function definition.Debugging: Added console logs to trace the flow of execution and check the structure of
When.onTheWorklistPageobject.
Code :
webapp/test/integration/pages/Worklist.js:sap.ui.define([ "sap/ui/test/Opa5", "sap/ui/test/actions/Press", "sap/ui/test/actions/EnterText", "sap/ui/test/matchers/AggregationFilled", "sap/ui/test/matchers/AggregationEmpty", "sap/ui/test/matchers/Ancestor", "./Common", "./shareOptions" ], function (Opa5, Press, EnterText, AggregationFilled, AggregationEmpty, Ancestor, Common, shareOptions) { "use strict"; var sViewName = "Worklist", sTableId = "table", sAddButtonID = "addButton", sSearchFieldId = "searchField", sSomethingThatCannotBeFound = "*#-Q@@||"; function createWaitForItemAtPosition (oOptions) { return { id: sTableId, matchers: function (oTable) { return oTable.getItems()[oOptions.position]; }, actions: oOptions.actions, success: oOptions.success, errorMessage: "Table with ID " + sTableId + " does not contain an item at position '" + oOptions.position + "'" }; } Opa5.createPageObjects({ onTheWorklistPage: { baseClass: Common, viewName: sViewName, actions: Object.assign({ iPressTableItemAtPosition: function (iPosition) { return this.waitFor(createWaitForItemAtPosition({ position: iPosition, actions: new Press() })); }, iPressAdd : function () { return this.waitFor({ id:sAddButtonID, viewName : sViewName, actions : new Press(), errorMessage : "Add button not found" }); }, iRememberTableItemAtPosition: function (iPosition) { return this.waitFor(createWaitForItemAtPosition({ position: iPosition, success: function (oTableItem) { var oBindingContext = oTableItem.getBindingContext(); // Don't remember objects just strings since IE will not allow accessing objects of destroyed frames this.getContext().currentItem = { bindingPath: oBindingContext.getPath(), id: oBindingContext.getProperty("ProductID"), name: oBindingContext.getProperty("ProductID") }; } })); }, iPressOnMoreData: function () { return this.waitFor({ id: sTableId, actions: new Press(), errorMessage: "The table with ID " + sTableId + " does not have a button to show more items" }); }, iSearchForTheFirstObject: function () { return this.waitFor({ id: sTableId, success: function (oTable) { return this.waitFor({ controlType: "sap.m.ObjectIdentifier", matchers: new Ancestor(oTable), success: function (aIdentifiers) { var sFirstObjectTitle = aIdentifiers[0].getTitle(); return this.iSearchForValue(sFirstObjectTitle); }, errorMessage: "Did not find entries for table with ID " + sTableId }); }, errorMessage: "Did not find table with ID " + sTableId }); }, iSearchForValue: function (sSearchString) { return this.waitFor({ id: sSearchFieldId, actions: [ new EnterText({ text: sSearchString }), new Press() ], errorMessage: "Did not find the search field with ID " + sSearchFieldId }); }, iClearTheSearch: function () { return this.waitFor({ id: sSearchFieldId, actions: new Press({ idSuffix: "reset" }), errorMessage: "Did not find the search field with ID " + sSearchFieldId }); }, iSearchForSomethingWithNoResults: function () { return this.iSearchForValue(sSomethingThatCannotBeFound); } }, shareOptions.createActions(sViewName)), assertions: Object.assign({ iShouldSeeTheTable: function () { return this.waitFor({ id: sTableId, success: function (oTable) { Opa5.assert.ok(oTable, "Found the object Table"); }, errorMessage: "Did not find table with ID " + sTableId }); }, theTableShowsOnlyObjectsWithTheSearchStringInTheirTitle: function () { return this.waitFor({ id: sSearchFieldId, success: function (oSearchField) { var sSearchFieldValue = oSearchField.getValue(); return this.waitFor({ id: sTableId, success: function (oTable) { return this.waitFor({ controlType: "sap.m.ObjectIdentifier", matchers: new Ancestor(oTable), success: function (aIdentifiers) { Opa5.assert.ok(aIdentifiers.every(function (oIdentifier) { return oIdentifier.getTitle().indexOf(sSearchFieldValue) > -1; }), "All table entries match the search term"); }, errorMessage: "Did not find entries for table with ID " + sTableId }); }, errorMessage: "Did not find table with ID " + sTableId }); }, errorMessage: "Did not find search field with ID " + sSearchFieldId }); }, theTableHasEntries : function () { return this.waitFor({ id: sTableId, matchers: new AggregationFilled({ name: "items" }), success: function () { Opa5.assert.ok(true, "The table with ID " + sTableId + " has entries"); }, errorMessage: "The table with ID " + sTableId + " had no entries" }); }, theTableShouldHaveAllEntries: function () { return this.waitFor({ id: sTableId, success: function (oTable) { return this.waitFor({ controlType: "sap.m.ColumnListItem", matchers: new Ancestor(oTable), success: function (aItems) { var aAllEntities = this.getEntitySet("ProductSet"); var iExpectedNumberOfItems = Math.min(oTable.getGrowingThreshold(), aAllEntities.length); Opa5.assert.strictEqual(aItems.length, iExpectedNumberOfItems, "The growing Table has " + iExpectedNumberOfItems + " items"); } }); }, errorMessage: "Did not find table with ID " + sTableId }); }, theTitleShouldDisplayTheTotalAmountOfItems: function () { return this.waitFor({ id: sTableId, success: function (oTable) { var iItems = oTable.getBinding("items").getLength(); // all items, incuding the growing list return this.waitFor({ id: "tableHeader", matchers: new Ancestor(oTable), success: function (oHeader) { var sExpectedText = oTable.getModel("i18n").getResourceBundle().getText("worklistTableTitleCount", [iItems]); Opa5.assert.strictEqual(oHeader.getText(), sExpectedText, "The table has a title containing the number " + iItems); }, errorMessage: "The table header does not container the number of items " + iItems }); }, errorMessage: "Did not find table with ID " + sTableId }); }, theTableShouldContainOnlyFormattedUnitNumbers: function () { return this.theUnitNumbersShouldHaveTwoDecimals("sap.m.ObjectNumber", sViewName, "Object numbers are properly formatted", "Table has no entries which can be checked for their formatting"); }, iShouldSeeTheNoDataTextForNoSearchResults: function () { return this.waitFor({ id: sTableId, matchers: new AggregationEmpty({ name: "items" }), success: function (oTable) { Opa5.assert.strictEqual( oTable.getNoDataText(), oTable.getModel("i18n").getProperty("worklistNoDataWithSearchText"), "The table with ID " + sTableId + " should show the no data text for search"); }, errorMessage: "Did not find table with ID " + sTableId }); } }, shareOptions.createAssertions(sViewName)) } }); });Pages/NewProduct.js
sap.ui.require([ "sap/ui/test/Opa5", "./Common" ], function (Opa5, Common) { "use strict"; var sViewName = "Add", sPageId = "page"; Opa5.createPageObjects({ onTheNewProductPage: { baseClass: Common, assertions: { iShouldSeeThePage: function () { return this.waitFor({ id: sPageId, viewName: sViewName, success: function () { Opa5.assert.ok(true, "The 'New Product' title is shown."); }, errorMessage: "Did not display the 'New Product' page." }); } } } }); });AllJoureney.js :
sap.ui.define([ "sap/ui/test/Opa5", "./arrangements/Startup", "./WorklistJourney", "./NavigationJourney", "./NotFoundJourney", "./ObjectJourney", "./pages/NewProduct" ], function (Opa5, Startup) { "use strict"; Opa5.extendConfig({ arrangements: new Startup(), viewNamespace: "opensap.manageproducts.ManageProducts.view.", autoWait: true }); });ObjectJourney.js :
/*global QUnit*/ sap.ui.define([ "sap/ui/test/opaQunit", "./pages/Worklist", "./pages/Browser", "./pages/Object", "./pages/App" ], function (opaTest) { "use strict"; QUnit.module("Object"); opaTest("Should remember the first item", function (Given, When, Then) { // Arrangements Given.iStartMyApp(); //Actions When.onTheWorklistPage.iRememberTableItemAtPosition(1); // Assertions Then.onTheWorklistPage.theTitleShouldDisplayTheTotalAmountOfItems(); // Cleanup Then.iTeardownMyApp(); }); opaTest("Should start the app with remembered item", function (Given, When, Then) { // Arrangements Given.iRestartTheAppWithTheRememberedItem({ delay: 1000 }); // Assertions Then.onTheObjectPage.iShouldSeeTheRememberedObject().and.theObjectViewShouldContainOnlyFormattedUnitNumbers(); // Cleanup Then.iTeardownMyApp(); }); opaTest("Should see the 'New Product' view after pressing the 'Add' button ", function (Given, When, Then) { // Arrangements Given.iStartMyApp(); //Actions When.onTheWorklistPage.iWaitUntilTheTableIsLoaded().and.iPressAdd(); //Assertions Then.onTheNewProductPage.iShouldSeeThePage().and.iTeardownMyAppFrame(); }); });