Protractor quickly launches and closes the Chrome browser without completing the entire scenario

In order to test my application using protractor, I created a scenario. The application begins with a non-angular login page and then progresses to an angular page after logging in.

Here is the javascript code snippet that was utilized:

var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
var expect = chai.expect;
var myStepDefinitionsWrapper = function () {
    this.Given(/^that I login with valid user credentials$/, function (callback) {
        console.log("I'm in before URL");
        browser.driver.get('http://localhost:8000/#');
        console.log("I'm in after URL");
        browser.driver.wait(function() {
            console.log("I'm in Wait");
            return browser.driver.isElementPresent(by.xpath("//input[contains(@placeholder,'Username')]"));
        },10000);
        browser.driver.findElement(by.xpath("//input[contains(@placeholder,'Username')]")).then(function(username) {
            console.log("I'm in Username");
            username.sendKeys("welby");
        });
        browser.driver.findElement(by.xpath("//input[contains(@type,'password')]")).then(function(password) {
            console.log("I'm in Password");
            password.sendKeys("asdf");
        });

        browser.driver.findElement(by.xpath("//button[@type='submit']")).click();
        console.log("I'm after click");
        callback();
    });

     this.When(/^I click perform button in Tasks window$/, function (callback) {
         browser.waitForAngular();
         element(by.xpath("//*[text()[contains(.,'Smith, Sally')]]/following::td[2]/button[text()='Perform']")).click();
         console.log("Clicked Perform");
         callback();
    });
}

Output:

"C:\Program Files (x86)\JetBrains\WebStorm 10.0.4\bin\runnerw.exe" "C:\Program Files (x86)\nodejs\node.exe" node_modules\protractor\lib\cli.js E2E\protractor-conf.js Using the selenium server at http://127.0.0.1:4444/wd/hub [launcher] Running 1 instances of WebDriver 

 - I'm in before URL  
 - I'm in after URL
 - I'm after click
 - Clicked Perform

1 scenario (1 passed)  3 steps (3 passed)

[launcher] 0 instance(s) of WebDriver still running [launcher] chrome #1 passed

Process finished with exit code 0

Answer №1

It seems from the style of the code in your query that you are utilizing Cucumber.js as your test runner. In this scenario, you can exclude the callback parameter in your step definitions and simply use a promise:

this.Given(/^that I login with valid user credentials$/, function () {

    // The rest of the code remains the same.

    return browser.driver.findElement(by.xpath("//button[@type='submit']")).click();
});

And:

 this.When(/^I click perform button in Tasks window$/, function () {
     browser.waitForAngular();
     return element(by.xpath("//*[text()[contains(.,'Smith, Sally')]]/following::td[2]/button[text()='Perform']")).click();
});

You can learn more about the ability of Cucumber.js to utilize promises by visiting this link.

Protractor is based on Selenium. It is recommended to go through the entire "Understanding the API" section of the Selenium documentation to understand how the JavaScript version of Selenium handles and sequences promises.

Your current issue may be due to calling callback() prematurely, indicating to Cucumber.js that your step is done before Protractor (and Selenium) has completed the necessary actions. By returning a promise, Cucumber.js will wait until the promise resolves or fails before proceeding.

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

Effortlessly populate the i18n language within ng-grid using AngularJS

I am currently working on an application that utilizes localization (i18n) with AngularJS. For this project, I decided to incorporate a basic ng-grid which can be found here. Here is a snippet of the code I am using: $scope.gridOptions = { data: 'f ...

What are the steps to set up chrome webdriver in headless mode?

After reviewing older posts, it seems like the code they provide is deprecated. The following code snippet I am currently using successfully opens the browser but not in headless mode due to the presence of a GUI. from selenium import webdriver from seleni ...

Generate a new subprocess and terminate it once the operation has been initiated

Using child processes in the following way: var exec = require('child_process').exec; var cmd = 'npm install async --save'; exec(cmd, function(error, stdout, stderr) { console.log('stdout: ' + stdout); ...

Ways to update HTML content generated by Ajax

Having some difficulties modifying the HTML content generated by AJAX. This is the code snippet from the page: @model IEnumerable<WE_SRW_PeerNissen.Models.Reservations> @{ ViewBag.Title = "List"; Layout = "~/Views/Shared/_Layout.cshtml"; } ...

Searching for an object in Vue 3 Composition API and displaying its contents

Experiencing a challenge with my first Vue.js project, seeking assistance in resolving the issue. Upon receiving a response from my API, I retrieve a list of projects and aim to locate the one matching the ID provided in the URL parameter. A peculiar error ...

What is the best way to save a scheduled cron reference in a database in order to deactivate it at a later time in a

I have implemented a system using cron to schedule push notifications. The user provides the push notification data and the scheduled time, and I use cron to send the notifications at the specified time. Below is the code snippet showing how I create a cr ...

How to initiate a refresh in a React.js component?

I created a basic todo app using React, TypeScript, and Node. Below is the main component: import * as React from "react" import {forwardRef, useCallback, useEffect} from "react" import {ITodo} from "../types/type.todo" import ...

Exploring XPath to target a specific group of elements in a class

Struggling with scraping Google Scholar and finding the right XPath expression. After inspecting the desired elements, I came across expressions like these: //*[@id="gs_res_ccl_mid"]/div[2]/div[2]/div[3]/a[3] //*[@id="gs_res_ccl_mid"]/d ...

Configuring React classes for compilation within Play

After incorporating a basic React class into my Play project at /app/assets/js: var Question = React.createClass({ render: function() { return (<div> <p>{this.props.content}</p> <br> <p>{this.props.an ...

Troubleshooting Issue: Incompatibility between AngularJS watchGroup() and Service modification

I am currently facing an issue where I cannot seem to watch multiple variables in a Service as they are being changed by other controllers. Here is what I have implemented: angular.module('carApp').controller('CarListCtrl', function ($ ...

The customized Vaadin component with a tag is missing from the MainView layout

I am attempting to integrate my custom vis component into the MainView VerticalLayout. However, it is appearing above the layout and the layout itself contains an empty component tag. Custom component code In this section, I have labeled my component as " ...

Animating with JQuery utilizing a dynamic attribute

We are facing a challenge with animating multiple divs that share the same class name and have different attribute values: <div class="chart-bar" style="width:10%;" bar-width="100%"></div> <div class="chart-bar" style="width:10%;" bar-wid ...

What is the best way to animate specific table data within a table row using ng-animate?

Are you working with Angular's ng-repeat to display a table with multiple rows? Do you wish to add an animation effect to specific cells when a user hovers over a row in the table? In the scenario outlined below, the goal is to have only certain cell ...

What is the correct way to exclude and remove a portion of the value within an object using TypeScript?

The function useHider was created to conceal specific values from an object with the correct type. For example, using const res = useHider({ id: 1, title: "hi"}, "id"), will result in { title: "hi" } being returned. Attempting ...

Is there a way to transfer a component as a prop to another component in React?

Just began my journey with React and coming from a Java background, please bear with me if the way I phrase this question is not quite right. I'm interested in "passing" an instance of a component to another component (which will then use that passed ...

The element 'stripe-pricing-table' is not a recognized property of the 'JSX.IntrinsicElements' type

I am currently trying to incorporate a pricing table using information from the Stripe documentation found at this link. However, during the process, I encountered an issue stating: "Property 'stripe-pricing-table' does not exist on type &ap ...

Express - An error occurred: Unable to access the property 'prototype' as it is undefined in the file request.js on line 31

My time has been consumed trying to troubleshoot this issue, yet I am puzzled by its origin and the reason behind this error. I am in the process of creating a basic website to hone my skills in React and have been attempting to retrieve data from Riot&ap ...

"Transitioning from jQuery to Vanilla Javascript: Mastering Scroll Animations

I'm seeking guidance on how to convert this jQuery code into pure Javascript. $('.revealedBox').each(function() { if ($(window).scrollTop() + $(window).height() > $(this).offset().top + $(this).outerHeight()) { $(this).addCla ...

Acquire information asynchronously in JavaScript while inside a for loop

Recently, I've been exploring this particular function snippet: function add_cnh(arr_clelem){ var id=arr_clelem.getElementsByClassName("present")[0].id; var date=arr_clelem.getElementsByClassName("present")[0].getAttribute('date'); v ...

Registering a component in Vue.js and checking for errors in component registration

Recently, I attempted to use the vuejs-countdown-timer component in one of our projects but encountered an error. Unknown custom element: - did you register the component correctly? For recursive components, make sure to provide the "name" option. The ...