Executing JavaScript using PHPUnit-SeleniumWould you like to learn how to run

After seeking answers, I stumbled upon this question where a similar script was attempted:

class viewerTest extends LoginLoader{    
public function testNewViewer(){
    $this->url('new-viewer.php');
    $this->byName('viewers_streetname')->value('street');    
    $script = file_get_contents("./viewerScript.js");
    $this->execute(array(
        'script' => $script,
        'args'   => array()
    ));
 }}

Unfortunately, the expected outcome did not materialize. The intention was to validate mandatory inputs and display the names of unfilled inputs, but no names were displayed.

Could there be an error in my approach?

PS: The function file_get_contents() is functioning properly.

Below is the content of viewerScript.js :

function valid_viewer_submit(){

    var datastring = $("#edit-viewer").serialize();
    ...
    ...
    ...    
    error_div.innerHTML = error;
};        

Answer №1

Within the javascript provided, a function was defined but never executed...

An additional line needed to be inserted which reads as follows:

$this->execute(array(
    'script' => 'valid_viewer_submit();',
    'args'   => array()
));

Answer №2

Issue resolved successfully.

For some reason, making modifications to the JavaScript code as shown below resulted in success:

// function valid_viewer_submit(){

      var datastring = $("#edit-viewer").serialize();
      ...
      ...
      ...    
      error_div.innerHTML = error;
// }; 

After implementing these changes, the functionality improved.

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

jquery disable document manipulation function

I need to make some updates to a simple function that involves the current textarea. $(document).on("keydown", updated_textarea_var, function (e) { // do stuff }); To achieve this, I tried disabling the previous function and running a new one w ...

Error: Unable to retrieve the specified ID

One unique aspect of my backbonejs app is the model structure: var Store = Backbone.Model.extend({ urlRoot: "/stores/" + this.id }); This is complemented by a router setup like so: var StoreRouter = Backbone.Router.extend({ routes: { 's ...

What causes delayed state updates in React/NextJS until another state is updated or a fast refresh occurs?

UPDATE: Version 13.3.0 is coming soon! In my code, I have a state variable named localArray that I need to update at a specific index. To achieve this, I decided to create a temporary array to make modifications and then set the state with the updated val ...

Discovering elements in Selenium that are dynamically loaded using JavaScript

My endeavor to automate form completion using selenium is being hindered by a peculiar issue. The particular form I am interacting with does not load instantly in the HTML code; instead, it is loaded dynamically through JavaScript after the initial page lo ...

Guide on how to check Selenium Side Runner Command Line (selenium-side-runner) Test Suite outcomes within the Test section of Azure DevOps Release pipeline

Currently, I am utilizing the Selenium .side file to conduct various tests using selenium-side-runner in Command Line on Azure DevOps Release Pipeline. I am interested in exploring the possibility of obtaining the test suite result output directly in the ...

Repositioning singular particles within a Three.JS particle array

Having an issue with my Three.js project. I've been working on a particle system and trying to animate particles as the frames are rendered. However, I'm running into a problem where the particles aren't moving at all. The code snippet I use ...

Encountering a PDF loading error when integrating ReactPDF in a React project

Having trouble trying to display a PDF file using the PdfReact component. Every time I attempt to load the PDF, I encounter the following error: Warning: Ignoring invalid character "114" in hex strinpdf.worker.js:342 Warning: Ignoring invalid character " ...

What could be causing the issue with "class not being recognized as a constructor" error that I am encountering?

When attempting to create an instance from modules in routing, I consistently encountered the error message "class is not a constructor." Below is the code snippet: export class Modules{ modules : object = { masterdata : MasterdataModule, shop : ...

My goal is to populate all of these elements with Javascript

My goal is to have all the boxes filled with "excellent": https://i.sstatic.net/oHW6W.png let a = document.querySelectorAll('.select2-choice'); a.forEach((e) => {console.log(e)}) a.forEach((e) => {e.innerHTML = ` <span ...

I encountered an issue with rendering static images when attempting to package my node-express app with pkg

Struggling to display an image from the public folder in my express app? I could use some guidance on configuring the path to properly render images or css files within the public folder when creating an executable file using pkg. Here's a snippet of ...

Unexpected behavior observed with excessively large string arrays

I am facing an issue with my array containing 58112 words. Whenever I try to check if a word is in the list, it always returns false, except for the first word. While I cannot share my entire code due to its length, here are the key details: isWord("a ...

Guide on utilizing the latest insertCSS and removeCSS features in manifest version 3

Need help with using the new insertCSS and removeCSS in manifest v3. The documentation is not very clear and lacks examples. I have a CSS file that I need to inject into a page and then remove it. The code looks something like this: background.js documen ...

Expanding Input Options Based on Dropdown Selections (PHP and JavaScript)

I am looking to dynamically add new input fields based on the option value selected from a dropdown menu. Here is an example of what the dropdown looks like: <form action="#" method="post"> <select name="job" id=& ...

Trouble with updating the view when an array is modified in ng-repeat? It seems like using $scope.$apply() may not

When updating the array inside a function, the view does not automatically update. However, if you use console.log to check the array after pushing values, it shows the updated array. Even trying $scope.apply() inside $timeout did not solve this issue. Ja ...

Flexbox causing issues with relative positioning at the bottom of the screen in various browsers

My flex component looks like this: <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" ... width="100%" height="100%" creationComplete="init()"> ....... <components:Naviga ...

reach an agreement on the implementation of infinite scrolling when navigating backwards

I'm looking to create a feature where clicking the back button will return me to the same position on the page. A great example of this is on . If you scroll down, click on a product, and then go back from the product page, you'll be taken back t ...

Troubleshooting encoding problems with Google Cloud's Speech-to-Text API using Node.js

I'm currently working on a project that involves capturing audio from a user's microphone and sending it to a server for translation using Google's Speech-to-Text API. I am utilizing navigator.mediaDevices.getUserMedia() to access the audio, ...

How to effectively use the LIKE statement in mysql with node.js

app.post('/like/:level/:name', function(req, res){ connection.query("SELECT * from books where " + req.params.level + " like '%" + req.params.name + "'%", function(err, rows, fields) { if (!err){ var row = rows; res.send(row); console.l ...

Every Other Element

I'm currently stuck on a math problem and could use some help. The task is to write a JavaScript function that identifies elements at even positions in an array. The array is composed of number elements. The desired result should be displayed in an el ...

Ways to update the hamburger menu icon after it has been clicked

I am trying to create a hamburger style menu where the icon changes to a cross when clicked. How can I achieve this effect using JavaScript? Here is the HTML structure: <ul class="navigation"> <li class="nav-item"><a href="#">Home&l ...