What is the reason for an object not being generated when using executeScript in Protractor?

In the context of a Protractor script testing an AngularJS app, I have included the following code within a describe block.

beforeEach(function() {
  browser.get('index.html#/device_list');
  browser.executeScript("chrome.bluetooth = {};");
  browser.executeScript("console.log('test')");
  browser.executeScript("alert('test')");
});

Running the tests without this code results in expected failures. However, upon adding it and executing the script, while the object isn't created and the console log doesn't appear, an alert is displayed (along with an asynchronous error).

I have attempted to remove the alert command, but there still isn't any object or log present.

Why is this happening? Is it feasible to create a basic object for test usage using executeScript in Protractor? If not, are there alternative approaches that don't require building a service?

To monitor the console log, I've integrated the following code snippet into the Protractor script:

browser.manage().logs().get('browser').then(function(browserLog) {
    if(browserLog.length > 0) {
        console.log(browserLog);
    }
});

Answer №1

Log only displays logs at the error level.

To achieve this, you must:

browser.executeScript("console.error('testing')");

Answer №2

executeScript function executes in the browser environment. Any log outputs from this function won't be visible in your node process but will appear in the browser's console log.

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

Issue: The 'in' operator is not allowed for searching

Passing Data from Child Component to Parent Component in AngularJS In my AngularJS project, I have two components: search and form. The search component is a child of the form component. Within the search component, there is a text input field that contai ...

Toggle the visibility of divs by swapping image on click

As a beginner in the realm of coding with Javascript, html, and related technologies, I am seeking guidance on how to enhance my current work. My goal is to create a webpage featuring 4 images serving as buttons, each corresponding to 4 hidden divs with d ...

Using JQuery to hide elements by setting CSS display as none instead of block

Is there a way to change the display of a content div to block when a specific tab is selected by the user, while hiding all other content divs? Here is the JQuery code I have tried so far: $(document).ready(function() { function resetTabs() { $("# ...

Not sure how to configure the settings for Firebase Firestore within the admin.firestore module

When trying to set an option at admin.firestore, I couldn't find the set method. It should be done like this: const settings = {timestampsInSnapshots: true} admin.firestore.settings(settings) However, I encountered a TypeError: Firestore.settings is ...

Unable to locate the controller in AngularJS

I am facing an issue with my AngularJS application where I have 2 separate JS files for different modules in different directories. When I try to start my app, I receive an error message stating that the controller SubAppCtrl cannot be found. Can someone p ...

Retrieve information from a row by clicking on it, then present it in a dialog box for editing

I'm working on a project using Angularjs to retrieve data from a table row when it's clicked and then display the data in an editable dialog box. I need help with implementing this feature. Here is my current progress: <table> ...

Set the constant value during the configuration stage

I have a special Angular constant that requires configuration after the initial app setup. This constant includes various endpoints, some of which are only determined after the app performs certain checks. Currently, I am handling this by returning some e ...

AngularJS validation for minimum character count prevents character overflow

Encountering an unusual "issue". I've set up a form with a textarea that has both a minlength and maxlength validation. In addition, there's a straightforward character count displayed: <textarea ng-trim="false" ng-model="form.text" minlengt ...

There was a ReferenceError that occurred as "require is not defined" in client-side JavaScript

I am currently working on developing a YouTube plugin with the source code available at https://github.com/abhishek-jha-24/EXTENSION. The primary javascript code is located in the content_scripts.js file, and I need to access a script1.py file from there t ...

Guide on setting thymleaf variable as ng-model

Is there a way to set the value of a Thymeleaf variable to ng-model? I'm attempting something along these lines: <input type="text" th:ng-init="myInput=${serverData.myInput}" ng-model="myInput" /> ...

AngularJS automatically toggles the selection of a radio button

I'm trying to implement functionality in my AngularJs code where a radio button is automatically selected and another one unselected when a user selects a checkbox and then a specific option from a dropdown. https://i.sstatic.net/hiKJP.png For exampl ...

What is the best way to pause or stop the $interval when exiting the ui-state

When using Angular with UI-router, I encountered a problem with $interval in a controller. Here is the code snippet to illustrate the issue: $scope.Timer = null; $scope.startTimer = function () { $scope.Timer = $interval($scope.Foo, 30000); }; $sco ...

Is there a method in JavaScript/jQuery to gently push or flick the scroll so that it can be easily interrupted by the user? Further details are provided below

I am looking for a solution in javascript that will allow the page to automatically scroll down slightly, but I also want the user to be able to interrupt this scroll. When using jquery for auto-scrolling, if the user begins manual scrolling while the ani ...

AngularJS mdDialog not supporting Tinymce functionality

I'm attempting to integrate the TinyMCE editor into an AngularJS mdDialog. Working Plunker: http://embed.plnkr.co/s3NsemdcDAtG7AoQRvLh/ Plunker with issues: http://embed.plnkr.co/fL8kGLl3b4TNdxW1AtKG/ All features are working fine except for the d ...

How can I stretch a background image using jquery to cover the entire document instead of just the window

I have implemented a plugin called https://github.com/srobbin/jquery-backstretch to effectively stretch the background image. The problem arises when the content of the page is long enough to create a scrollbar. In this case, while scrolling, the backgrou ...

Combining array outputs from both Promise.all and map functions

Hey, it might seem silly, but it's late and I'm struggling with this issue. My goal is to gather statistics for different types of values and store them in an array. However, the problem lies in the final result: // Data this._types = [{ id: 1, ...

The webpage is not refreshing or reloading despite using window.location.href

When creating a refreshcart() function, the window.location.href is assigned to currentUrl. However, when making an ajax call in the else block with window.location.href = currentUrl, true; it does not successfully refresh the page. $(document).ready(fu ...

Creating nested directories in Node.js

I am attempting to accomplish the following task Create a function (in any programming language) that takes one parameter (depth) to generate folders and files as described below: At depth 0, create a folder named 0, and inside it, create a file with its ...

Tips on changing a PHP array index into a JavaScript variable

I have retrieved user roles from the database using PHP and displayed them within <select> tags as shown below: <div class="col-md-3"> <select name="role" id="user_role" class="form-control" onkeyu ...

Manage multiple dropdown menus with a single main dropdown menu

I am currently working on building a main drop-down box that controls multiple other drop-down boxes. The additional drop-down boxes are generated in a loop, so I need a dynamic script that can work based on classes or IDs. For example: <form method=" ...