Unable to execute karate script() method - javascript

I am trying to migrate one of selenium test to karate, while doing this I am using script() method defined in documentation which is used in karate for evaluating the given string as JavaScript within the browser but I am getting this
driver.executeScript("sauce:job-result=passed");
Also Sharing my feature file which getting failed:
Also Even I tried calling below statement in my script but still getting the same error
* script("console.log('hello world')")
I am using testImplementation("com.intuit.karate:karate-core:1.2.0.RC1") version with gatling

First - try version 1.2.0.RC6 that has some fixes for the console.log() issue.
I also must say that sauce:job-result=passed does not look like valid JavaScript to me. Please take some time to read the docs: https://github.com/karatelabs/karate/tree/master/karate-core#karate-vs-the-browser
If still stuck, follow this process. That is the only way to replicate and for us to determine what fixes we need to make (if any): https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue
See this answer for ideas on how to troubleshoot things at your end: https://stackoverflow.com/a/71952132/143475

Related

How to properly use the sheets.spreadsheets.values.GET in the Google Sheets API?

So I'm a first year programming student with near 0 experience so please forgive me if I'm going at this the wrong way.
I'm building a website that will take an array of strings and display them as well as run some code relating to those strings. For this assignment, I have to use an API, so I wanted to use the google sheets API in order to achieve my idea. I understand that I need to use the command
sheets.spreadsheets.values.GET
to get my spreadsheet data as a JS array, which is perfect for what I want to do. Inside the Google dev console, I am able to test the command and receive my array, so I know that I have the API se t up correctly.
However when I go to my website, which has Jquery linked fyi, and I put in the get command into the console I get the error:
Uncaught SyntaxError: Unexpected identifier
This is weird to me since I'm just copy-pasting from the Dev console into the early version of my website this command:
GET https://sheets.googleapis.com/v4/spreadsheets/MY_Spread_Sheet_ID/values/Sheet1!A1%3AA200?valueRenderOption=FORMATTED_VALUE&key={ApiKeyCode}
I was under the impression that the console should have reported back the contents of my spreadsheet as an array, but instead I get the error.
At first I thought that I must have needed to link the google sheets API to my code like you would with JQuery but I can't find documentation on how to do that, so that might be my problem.
Sorry about my poor English skills.
Could you include your code in your post? FYI, the function spreadsheets.values.get() does not return directly a value, but instead it calls a callback function with the returned values.

Getting more information from “SyntaxError: Parse error” message in PhantomJS/CasperJS

I have a long CasperJS script. When I run it I get:
phantomjs file.js
SyntaxError: Parse error
Is there a way to get some more information about the error.
At least a line number? or any hint at all?
Try run the file.js with node, so for your example:
node file.js
It's not possible to determine this in PhantomJS itself. The documentation on phantom.onError says:
This is the closest it gets to having a global error handler in PhantomJS
And this doesn't catch the syntax error. If you try to run it with the --debug=true option, you will see a lot of debug messages, but the final error has still the same amount of information.
Another thing that I tried was to use a second PhantomJS script which reads the original script and tries to eval it. The phantom.onError event is triggered in this case, but the trace argument is empty.
The good thing is that PhantomJS/CasperJS scripts are just JavaScript, so you can paste them to http://jslint.com/ or run a dedicated jslinter on them to see where the problem lies. There are some options that you have to mark on the site or otherwise you will get a lot of errors:
add phantom to the global variables box,
enable node.js mode and
tolerate "everything" (or those things that you actually want to tolerate)
I spent a whole 8hrs on this to find a trick for this problem. The trick is to run "phantomjs" and type 'require "path_to_js_file"'. I used 2.1.1 version of phantomjs. Likely 2.2 also works.
Then there will be a stack trace that shows which line is the offender. You won't see this in testem output.
In my case, if you define a property twice for an object, it will work for chrome, firefox etc, but not phantomjs. Lint might help but there are >5K lint errors for the project I work on and it is practically impossible to see what's wrong. Also the particular problem is likely hidden under the same bucket of "javascript strict mode violation". Nodejs didn't complain this either.

Socket.io failed to load websocket.js

I tried to use socket.io in an simple app.
When it is calling the following js file:
node_modules\socket.io\lib\transports\websocket.js
The following line failed to load (It didn't really fail. It actually returned some empty result and failed some later codes using protocolVersions):
var protocolVersions = require('./websocket');
I debugged a little bit and it seems that the intention of this line is to load the following js file:
node_modules\socket.io\lib\transports\websocket\index.js
However because there is also a "websocket.js" (the file being run) under the "transports" folder, the require functions always tries to load "websocket.js" instead, and return some unexpected results.
I changed the folder name to "websockets" and call "require('./websockets')" instead, and it fixed the problem. However this is a shared library I am not feeling comfortable messing up its codes.
I am trying to understand why this problem happened this way and what should be the best way to work around it. I am sure this piece of codes has been well tested before released.
You probably already noticed that I am using backslash '\' to separate the path. Yes I am running it on Windows! Will that create any difference?
Thanks!

Calling a function in a JavaScript file with Selenium IDE

So, I'm running these Selenium IDE tests against a site I'm working on. Everything about the tests themselves is running fine, except I would like to do a bit of clean-up once I'm done. In my MVC3 Razor based site, I have a JavaScript file with a function that gets a JsonResult from a Controller of mine. That Controller handles the database clean-up that Selenium IDE otherwise couldn't handle.
However, I'm having a hard time finding any sort of documentation on how to do this. I know I can do JavaScript{ myJavascriptGoesHere } as one of the Values for a line in the test, but I can't seem to find a way to tell it to go find my clean-up function.
Is it even possible for Selenium IDE to do this sort of thing?
If it comes down to it, I can just make a separate View to handle the clean-up, but I'd really like to avoid that if possible.
Thanks!
If you want to execute your own JavaScript function that exists in your test page from Selenium IDE, you need to make sure you access it via the window object. If you look at the reference for storeEval for instance, it says:
Note that, by default, the snippet will run in the context of the
"selenium" object itself, so this will refer to the Selenium object.
Use window to refer to the window of your application, e.g.
window.document.getElementById('foo')
So if you have your own function e.g. myFunc(). You need to refer to it as window.myFunc().
This can be very handy for exercising client-side validation without actually submitting the form, e.g. if you want to test a variety of invalid and valid form field values.
If you use runScript, that should already run in the window's context.
This works for me.
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string title = (string)js.ExecuteScript("myJavascriptGoesHere");
Make sure your javascript works first before using it here!
Actually to access your page javascript space, you need to get the real window of your page : this.browserbot.getUserWindow()
See this statement to get the jQuery entry point in your page (if it has jQuery of course ^^ )
https://stackoverflow.com/a/54887281/2143734

JavaScript: Ci is not defined

I just spent half an one our to find out what caused the Error-Message "Ci is not defined" in my JavaScript code. I finally found the reason:
It should be (jQuery):
$("asd").bla();
It was:
("asd").bla();
(Dollar sign gone missing)
Now after having fixed the problem I'd like to understand the message itself: What does Firefox mean when it tells me that "Ci" is not defined. What's "Ci"?
Update:
I'm using the current version of Firefox (3.0.3).
To reproduce, just use this HTML code:
<html><head><title>test</title>
<script>
("asd").bla();
</script>
</head><body></body></html>
To make it clear: I know what caused the error message. I'd just like to know what Firefox tries to tell me with "Ci"...
I don't know which version of FF you are using, but regardless, the message is probably referring to the fact that bla() is not a function available on the String object. Since you were missing the $, which means you were missing a function, ("asd") would evaluate to a string, and then the JavaScript interpreter would try to call bla() on that object. So, if you had the following code in your project:
String.prototype.bla = function() {};
// now this next line will execute without any problems:
("asd").bla();
So, it is possible that Ci is some internal Firefox symbol that simply refers to the idea of a function. That is my guess, I imagine you are going to need someone that knows something about Firefox's internals to get a better answer to this question...
UPDATE: I am running your example code in the exact same version of FF as you are, but it reports the error as:
Error: "asd".bla is not a function
Source File: file:///C:/test.html
Line: 3
Perhaps you have an extension/plug-in running that does something with this? Maybe some Greasemonkey script or something?
Jason seems to be right. Many plugins (e.g. Firebug, Geode) use Ci as a shortcut:
const Ci = Components.interfaces;
So the plugins seem to cause that strange error message.
Assuming it's CodeIngiter, it can't find the js file.

Categories

Resources