Could somebody provide clarification on the functions being called in the Angular Test Code, specifically evaluate() and dragAndDrop()?

Exploring the drag and drop functionality of an angular-Gridster application using Protractor with a test code.

I have some questions about the functions being used in the code snippet below. Can someone clarify the purpose of evaluate() - the API definition is confusing, and what does dragAndDrop() do? I couldn't find this function mentioned anywhere.

describe('DragAndDrop Test', function () {

require('jasmine-expect');

beforeAll(function () {
    context = new Context();
    context.get();
    browser.waitForAngular();
    browser.driver.manage().window().maximize();

});

it('should perform a drag and drop operation on a tile', function () {

    //setting the target location for dragging the box
    var target = { x: 400, y: 400 };
    var box = element(by.css('.ng-scope.gridster-item'));

    //fetching scope variables to determine box position
    box.evaluate('standardItems').then(function (scope) {

        //asserting that the box starts at column 0 and Row 0
        expect(scope[0].col).toEqual(0);
        expect(scope[0].row).toEqual(0);
    });

    //performing the drag and drop action on the box
    browser.actions().dragAndDrop(box, target).perform();
    browser.waitForAngular();

    //fetching updated scope after the drag and drop
    box.evaluate('standardItems').then(function (scope) {

        //verifying if the box was moved to column and row 2 as intended
        expect(scope[0].col).toEqual(2);
        expect(scope[0].row).toEqual(2);
    });
    
    //checking the pixel location post drag and drop
    box.getLocation().then(function (location) {
        expect(location.x).toEqual(476);
    });
});
});

var Context = function () {

//loading the website
this.get = function () {
    browser.get('https://rawgit.com/ManifestWebDesign/angular-gridster/master/index.html#/main');
};
};

Answer №1

utilizeEvaluate() function allows you to evaluate an expression within the element's scope, making it easier to access specific variables:

Executes the input as if it belongs to the current element's scope.


performDragAndDrop() is classified as a "browser action" and is inherited from WebDriverJS (remember that Protractor is based on WebDriverJS):

A convenient method for executing a "drag and drop" action. The target element can be moved to another element's location or by an offset (in pixels).

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

"Encountering a strpos() issue while working with the Simple HTML DOM

Efficient HTML Parsing Comparison (1 min, 39s) <?php include('simple_html_dom.php'); $i = 0; $times_to_run = 100; set_time_limit(0); while ($i++ < $times_to_run) { // Find target image $url = "http://s ...

Chromium cannot be initiated by WebDriver in a Docker environment

After writing e2e-tests for an angularjs app with protractor that were working fine, I decided to run these tests within a docker container. Within the container, I initiated Xvfb :0 -ac -screen 0 1024x768x24 & and set the DISPLAY=:0 environment variab ...

Tips for maintaining the reference of a Three.js object after importing it as an .obj file

If you want to learn how to incorporate a .obj file into your scene, the official documentation provides a helpful example that can be found here. const loader = new OBJLoader(); // Load the resource loader.load( // Resource URL 'models/monst ...

What is the best way to include a &nbsp; in a map function using JavaScript?

A challenge I encountered while working in React is as follows: <Grid item> { rolePriorities.map((rp, index) => ( <Chip key={index} label={rp} color="primary" sx={{ color: "whitesmoke" }} /> ...

Finding a date from a calendar with a readonly property in Playwright

Just starting out with the playwright framework after working with Protractor before. I'm trying to figure out the correct method for selecting a date in Playwright. selector.selectDate(date) //having trouble with this ...

Save information for each session with a set expiration time

Currently, I am working on a mobile application using Angular (specifically Ionic 5) and I am in need of a solution to maintain session data for my users throughout their workflow. Initially, I thought about utilizing the sessionStorage feature for this p ...

Utilizing jQuery BBQ for Seamless Transitions – From Fading to Sliding and More

This is my first time posting a question here, even though I am an active user of stackoverflow. I have developed a website using jQuery BBQ to load pages through AJAX while still maintaining the ability to track history with the back button and other fun ...

What is the process of linking current components to Angular?

New to Angular and currently navigating my way through an existing codebase. There is a particular element that already exists in the root document (index.html) before Angular library is loaded. Due to this, the ng-click directive does not get registered. ...

The process of updating UseContext global state in React Native and ensuring that the change is reflected across all screens

Struggling with updating global state values using React useContext on different screens? Attempting to change theme color in the App, but changes only appear on the current screen and not carried over to others? Looking for assistance in resolving this ...

ng-include: Child scope access problem

I am currently facing an issue with my app while using DayPilot Scheduler. home.html: <div class="container-fluid"> <daypilot-scheduler id="scheduler" daypilot-config="schedulerConfig" daypilot-events="events"></daypilot-scheduler> ...

Steps for adjusting the position of this div in relation to the main container

Apologies in advance for my lack of HTML skills. I am struggling with a page layout issue. I have a website at . When the window is resized, the ads div on the right side overlaps the main container. What I would like to achieve is to make this ads div re ...

301 redirection will be implemented on the upcoming static export

Working on a Next.js project, I utilized static export for better performance and SEO. Yet, I've come across an issue with URL changes. I'm looking to incorporate a 301 redirect to ensure search engines and users are directed to the correct pages ...

Is there a way to determine if a property contains a string value?

In my main.js file, I have a function called $scope.onError which is triggered when there is an error while uploading an attachment. The function logs the error message received from the server and assigns it to the variable $scope.errorMessage. If the val ...

AngularJS options for selecting items: radio buttons and checkboxes

I am currently working on creating a concatenated string based on the selection of radio buttons and checkboxes. There are two radio button groups and one checkbox group. One of the radio button groups is functioning correctly, but the other automatically ...

Is it possible to modify the location of my CSG object prior to performing subtraction in Threejs with ThreeCSG?

Looking to carve out specific "voids" in platforms using ThreeCSG. The goal is to have these voids positioned at particular locations on the larger platform. var geometry = new THREE.CubeGeometry( 500, 10, 500 ); var hole_geometry = new THREE.CubeGeom ...

PassportJS ensuring secure authentication across all routes

Currently, I am implementing passportJS to secure my API Endpoints within an Express application. So far, the following code is functioning properly. app.get("/route1", passport.authenticate('basic', { session: false }), (req, res) => { ...

How can I cut an array by value in Vue?

I am working on a component that has a list of objects and I need to implement functionality where, when toggled, the objects' title prop is either added to or removed from an array. Adding the value was easy to do, but removing it has proven challeng ...

Combining two arrays of names and values into a fresh object using Javascript

Trying to merge two arrays, one for column headers: cNames = ["Year","Count"] And another for data: mData = ["2005",50212,"2006",51520,"2007",52220,"2008",52143] The goal is to combine them like this: [ { Year: "2005", Count: 5021 ...

Displaying Vue v-for data in console.log

One interesting issue arises when printing a list in HTML and checking the output in HTML versus in console.log. It seems that the output is duplicated in the console. After some investigation, I made the following observations: Not showing the product ...

Switching the border of a div that holds a radio button upon being selected

I have a piece of code that I use to select a radio button when clicking anywhere within a div, which represents a product photo. To make it clear for the customer, I want to add a border around the selected product. Here is the initial code: <script t ...