Pasting multiline into phantomjs interactive session - phantomjs

I'm trying to debug a script interactively by command line. If I paste a multiline command the interpreter seems unable to parse the line returns. E.g. trying to paste
page.onConsoleMessage = function(msg) {
console.log(msg);
};
Fails with:
phantomjs> page.onConsoleMessage = function(msg) {
Expected token '}'
phantomjs://repl-input:1 in global code
phantomjs> console.log(msg);
Can't find variable: msg
phantomjs://repl-input:1 in global code
phantomjs> };
Parser error
phantomjs://repl-input:1 in global code
Is there any way to make phantom recognise line returns or expect a multiline comment?

Related

First time when it runs it fails but when i hit re-run it works perfectly

For some reasons when i try to run my cypress code it fails (during the first initialization) and it throws an error like the variables im setting out of the file doesn't exist. (when they actually are...)
After it fails i click on the re-run button and everything works perfectly, what im trying to avoid is the problem with the ghost variables at the beginning... I tried different approaches like setting the variable to an environment variable, and nothing seems to work.
I have this constants in an external file:
export const constants = {
access_token: "",
_id: "",
payment: {},
access_token_QR: "",
QRCode: "",
url: "https://google.com/"
}
And on each cypress test for example i have something like this:
it("login SSO", () => {
constants.access_token = "asfdaaFDSA"#$20ASDG0A"#$ASDJFAJM2"
}
Then after that it goes to the next test:
it("Another test", () => {
cy.log(constants.access_token) // it does print the code.
}
And when it reaches a test that does a cy.visit it doesn't detect the url constants.url but when i reload the cypress it works perfectly for some reason i can't explain.
Is there any setting im currently missing?
I tried setting the variable in the same file but is not passing until it reloads the website i believe is something related to cache that makes it works?

How to properly handle file paths with spaces when calling task using ShellExecution

I've been banging my head trying to fix an issue with an VSCode extension I have created. This extension obtains the file path of the currently selected item in the VScode explorer tree. It then passes the path to a task for execution. The extension works fine for items that do not contain spaces in its file path but fails miserably when a path with a space is encountered.
Here is a simplified snippet:
import * as vscode from 'vscode';
export async function activate(context: vscode.ExtensionContext) {
let disposable = vscode.commands.registerCommand('playwright-vscode-trace-viewer.show', async (...args) => {
let path = args[0].fsPath;
const p: vscode.ShellQuotedString = {
value: path,
quoting: vscode.ShellQuoting.Escape
}
const shellExec = new vscode.ShellExecution('npx', ['playwright', 'show-trace', p]);
let tsk = new vscode.Task({ type: `trace-viewer${Math.random()}` },
vscode.TaskScope.Workspace,
'trace-viewer',
'trace-viewer',
shellExec,
'npx');
vscode.tasks.executeTask(tsk);
});
context.subscriptions.push(disposable);
}
export function deactivate() { }
When I execute the extension against a filepath:
c:\Users\ryanr\_repo\pw-tyscript\test-results\tests-start_server-bar-cw\trace (1).zip
It garbles up the path and fails ...
> Executing task: npx playwright show-trace c:\Users\ryanr\_repo\pw-tyscript\test-results\tests-start_server-bar-cw\trace` `(1`).zip <
No such file or directory: c:\Users\ryanr\_repo\pw-tyscript\test-results\tests-start_server-bar-cw\trace
I can execute the command manually using powershell like so:
npx playwright show-trace c:\Users\ryanr\_repo\pw-tyscript\test-results\tests-start_server-bar-cw\trace` `(1`).zip
I suspect I'm not calling vscode.ShellExecution correctly?

TypeError: Cannot read property 'get' of undefined when writing command

I am in the process of making my first discord bot, and right now I am in the process of making a "kick" command for my bot. However, whenever I run the "kick" command, it tells me the TypeError: Cannot read property 'get' of undefined error. I've tried everything, can someone help me?
My kick command:
module.exports = {
name: 'kick',
description: "This command kicks a member!",
execute(message, args){
const target = message.mentions.users.first();
if(target){
const memberTarget = message.guild.member.cache.get(target.id);
memberTarget.kick();
message.channel.send("User has been kicked");
}else{
message.channel.send(`You coudnt kick that member!`);
}
}
}

Debugger statement throws an error in vuejs app

I'm using a simple v-on:click="demo" method that is attached to my input. In my demo function I use debugger statement to stop JavaScript engine execution. The problem is that debugger statement throws none sense errors in es-lint module. My question is simple. How to make debugger work ?
Code
export default {
name: "Demo",
methods: {
demo: function () {
console.log('Running demo')
debugger
}
}
}
Error
Failed to compile.
./src/components/Demo.vue
Module Error (from ./node_modules/eslint-loader/index.js):
/app/src/components/Upload.vue
2:1 warning Insert `··` prettier/prettier
3:1 warning Insert `··` prettier/prettier
...
...
I found the problem. Apparently, ES-linter disallows debugger statement rule. To make debugger work again I had to add // eslint-disable-line comment to my debugger line. Below lines of code solved the debugger error.
debugger // eslint-disable-line
or
/* eslint-disable no-debugger */
debugger

Accumulate all JS warnings and errors during test runs in TestCafe

I would like to be able to access all JS warnings and errors from the Browser Console during test runs. With the "-e" (skip JS errors) flag disabled, the test stops at the first error, so clearly it is looking for them. With this flag enabled, I would like to be able to see which errors (and ideally warnings) fired during test runs.
I've tried using the ClientFunction and window.onerror methods. I've also tried the -r 'reports' flag -- I only see TestCafe errors, not JS errors from the page under test. I've tried "Accessing Console Messages" from https://devexpress.github.io/testcafe/documentation/test-api/accessing-console-messages.html but this only gives messaging thrown by console.log, etc ("Note that this method returns only messages posted via the console.error, console.warn, console.log and console.info methods. Messages output by the browser (like when an unhandled exception occurs on the page) will not be returned.")
const installErrorHandler = ClientFunction(() => {
window.onerror = error => {
console.log("ERROR::::::");
console.log(error);
};
});
Over in the Clojure space, when using the Etaoin webdriver implementation (on Chrome or Phantom.js), at any point simply performing a
(get-logs driver)
returns
{:level :warning,
:message "1,2,3,4 anonymous (:1)",
:timestamp 1511449388366,
:source nil,
:datetime #inst "2017-11-23T15:03:08.366-00:00"}
....
....
Including any 'unhandled exceptions'.
Can I not do this in TestCafe?
Probably your example with window.onerror does not work because it executes later that error occurs. I suggest you extract the error handler into a separate *.js file and inject it using the new testcafe feature: Inject Scripts into Tested Pages.
Look at the following example:
script to inject (log-errors.js):
window.unhandledErrors = [];
window.onerror = (message, source, lineno, colno, error) => {
window.unhandledErrors.push({ message, source, lineno, colno, error });
}
test:
import { Selector } from 'testcafe';
fixture('Log errors')
.page('http://example.com')
.afterEach(async t => {
const errors = await t.eval(() => window.unhandledErrors);
console.log(errors);
});
test('test', async t => {
//...
});
Run tests by the following command:
testcafe chrome test.js -e --cs=./scripts/log-errors.js
Note that Script Injection feature is available since 1.4.0 version.