Running various IT blocks within a Protractor loop to enhance web testing

After logging in to a web page, we need to use a for loop to perform multiple tests on the page. The ideal test scenario involves a table with buttons on each row that leads to another page where data needs to be validated. Currently, all expectations and assertions are placed in a single IT block, which is not an optimal solution. It's necessary to separate the tests into different IT blocks.

require('..\\waitAbsent.js');
require("../node_modules/jasmine-expect/index.js");
var EC = protractor.ExpectedConditions;

describe('Student Enrollment Page Content Validation', function() {


beforeAll(function () {
    browser.driver.manage().window().maximize();
    browser.get(globalVariables.loginMain);
    globalVariables.Email_Input_box.sendKeys(globalVariables.Demo_User);
    globalVariables.Password_Input_Box.sendKeys(globalVariables.Demo_PWD);
    globalVariables.Submit_Button.click();
    browser.wait(EC.invisibilityOf(globalVariables.Submit_Button), 25000, 'submit button is not disappearing yet');
});

async function Row_Numbers() {

    const RowCount = (globalVariables.tableData_Dashboard.all(by.tagName("tr")).count()).then(function(RC){

        return RC;

    });

}

for (var i = 1; i<Row_Numbers(); i++){

    function tableData(n){
        var row_1 = globalVariables.tableData_Dashboard.all(by.tagName("tr")).get(n);

        // get cell values
        var cells = row_1.all(by.tagName("td"));

        it ('should return the data fo the first cell', function(){
            var Student_ID = cells.get(0).getText().then(function (SID) {
                console.log(SID);

                return SID;

            });

            expect(Student_ID.toEqual('Something'));
        });

        it ("should show the button in this row", async function(){

            const Button = globalVariables['Edit_Button_' + n];
            // console.log(Button)
            expect(await Button.isDisplayed());
            Button.click();
            // do some thing

        });
    }tableData(i)
}

});

When running the test using this script, an error message appears:

E/launcher - Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined. This could be either because this is a non-angular page or because your test involve s client-side navigation, which can interfere with Protractor's bootstrapping. See https://github.com/angular/protractor/issues/2643 for details"

How can I modify the for loop to accomplish our objective?

Answer №1

I would like to share my thoughts on this matter.

To begin with, the reason for your angular error is that the Row_number function is declared outside of any it block, causing it to run before the beforeAll function has executed.

Additionally, there seems to be no necessity for the tableData function as substituting its parameter n with the loop's counter i would yield the same outcome.

Lastly, if your code requires navigating through multiple pages to conduct these tests, it might be more efficient to adopt a data-driven approach by creating separate data files for each test. Are the values in these table rows subject to change, or do they remain constant?

Update: Implementing this strategy could resemble the following code snippet (although untested):

beforeAll(() => {
    browser.driver.manage().window().maximize();
    browser.get(globalVariables.loginMain);
    globalVariables.Email_Input_box.sendKeys(globalVariables.Demo_User);
    globalVariables.Password_Input_Box.sendKeys(globalVariables.Demo_PWD);
    globalVariables.Submit_Button.click();
    browser.wait(EC.invisibilityOf(globalVariables.Submit_Button), 25000, 'submit button is not disappearing yet');
});

it('test case', async () => {
    globalVariables.tableData_Dashboard.all(by.tagName("tr")).forEach((row) => {
        var cells = row.all(by.tagName("td"));

        var Student_ID = cells.get(0).getText().then((SID) => {
            console.log(SID);
            return SID;
        });

        expect(Student_ID.toEqual('Something'), 'should return the data fo the first cell');

        const Button = globalVariables['Edit_Button_' + n];
        // console.log(Button)
        expect(Button.isDisplayed(), 'should show the button in this row').toBe(true);
        Button.click();
        // perform some action

    });
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Choose the initial division within the table and switch the class

Here is a straightforward request - I need to employ jquery to target the first div with the class of "boxgrid captionfull" within the tr element with the classes "row-1 row-first," and switch the class to 'active_labBeitrag'. <table class="v ...

During the build process, Next.js encounters difficulty loading dynamic pages

My Next.js application is utilizing dynamic routes. While the dynamic routes function properly in development mode, I encounter a 404 error when deploying the built app to Netlify. https://i.stack.imgur.com/45NS3.png Here is my current code setup: In _ ...

Tips for adjusting the position of rows within a v-data-table - moving them both up and down

Is there a way to rearrange rows up and down in the table? I've been using the checkbox feature and the CRUD data table from the documentation, but I haven't found any examples on how to implement row movement. Currently, my v-data-table setup l ...

Contrasts between the storage of data in a static function versus a static object

Trying to figure out the best way to reset a react class component back to its initial state, I came across two different implementations. In my own version, I created an object with initial values and set the component's state equal to it: // My imp ...

How can I use AJAX to transmit a 2D array to a PHP page and then display each dimension individually?

Recently, I created a webpage with multiple checkboxes. Using jQuery, I am able to fetch data from these checkboxes and store them in a two-dimensional array. Here is an excerpt of my code: HTML snippet: <input type="checkbox" name="checkboxs[]" pric ...

Achieving Vertical Centering of Text in Bootstrap 5 Buttons with Flex Box to Prevent Overlapping Icons

How can I prevent the text on a Bootstrap 5 button with horizontally and vertically centered text, along with a right aligned icon, from overlapping when it wraps? Additionally, how do I ensure that the icon stays vertically centered when the button text w ...

What is the best way to make a JavaScript cookie remember the state of a DIV?

Seeking assistance with a test site here that is currently in development. I am attempting to make the notification at the top remain hidden once the close button is clicked. Below is my current script: <style type="text/css"> <!-- .hide { displ ...

Having trouble loading AngularJS 2 router

I'm encountering an issue with my Angular 2 project. Directory : - project - dev - api - res - config - script - js - components - blog.components.js ...

Error in Postman: Express and Mongoose throwing 'name' property as undefined

While trying to create and insert 'user' JSON documents according to the model below, upon sending a POST request to localhost:3000/api/student, I encountered an error using Postman: TypeError: Cannot read property 'name' of undefined ...

Trying to use 'cpa' before it is initialized will result in an error

I encountered the error stated above while using this particular route: router.put('/edit/:id', async (req, res) => { const cpa = await CPASchema.findById(req.params.id).then(() => { res.render('edit', { cpa:cpa }); cons ...

Conceal elements with a single click of a button

How can I use jQuery to hide all li elements with an aria-label containing the word COMPANY when the Search from documents button is clicked? Here is the HTML code: <ul class="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content" id="ui-id-1" t ...

Three.js dynamic bone animation: bringing your project to life

Can transformations be applied to the bones of a 3D model in three.js to create a dynamic animation? I attempted to move and rotate the bones of a SkinnedMesh, but the mesh did not update. loader = new THREE.JSONLoader(); loader.load(&apos ...

SequelizeIncludeError: unable to fetch data using the 'include' method

My database requests are handled using Sequelize.js, and I have set up a many-to-many relationship between two tables with a third junction table called polit_in_article. Let me walk you through my three tables: politician.js: module.exports = (sequelize ...

Anticipating the resolution of promises and observables in Angular 2

Within my accountService module, there is a dialog prompt that requests the user's username and password, returning a promise. If the user clicks on close instead of dismissing the dialog box and the validators require the input data before allowing t ...

In PhantomJS, where is the location of the "exports" definition?

Consider the following code snippet from fs.js: exports.write = function (path, content, modeOrOpts) { var opts = modeOrOptsToOpts(modeOrOpts); // ensure we open for writing if ( typeof opts.mode !== 'string' ) { opts.mode = ...

Accessing a file's source using the Box.net API and downloading the file contents

Recently, I've been busy working on a Web Application project (for fun) that focuses on editing files stored in the cloud. I'm utilizing the box.net API for this task, but I've come across a challenge - obtaining the source code of files. Un ...

StorageLimit: A new condition implemented to avoid saving repetitive values in the localStorage

Is there a way to store the text of an li element as a localStorage value only once when clicked? If it already exists in localStorage, a second click should have no effect other than triggering an alert. I'm currently using an if statement inside a ...

Update Material-ui to include an inclusive Datepicker widget

I have integrated the Material-ui Datepicker into my website to allow users to download timed event information from a database. The issue I am facing is that when users select two bracketing dates, events for the end date are not showing up correctly. F ...

React: Issue with function not recognizing changes in global variable

When the run button is clicked, it triggers an event. However, clicking on the skip button does not take me to Switch Case 2 as expected. Even though the skip state updates, the function still outputs the old value of skip. const CustomComponent = () => ...

Retrieving JSON data from an API

As a beginner with Jquery JSON and API's, I am trying to work on hitting an API that returns city names in JSON format. I need to display these city names dynamically on my webpage in a list format. Can someone guide me through this process? If you w ...