Testcafe: Native dialog window handeling - google-chrome

I'm trying to upload a file to the site I'm testing (Using Chrome) with Testcafe. Below is my code so far,
await t
.setFilesToUpload(Selector('input.btn.btn-link.d-none'), file_path)
await t
.setNativeDialogHandler(() => true)
.click('#Ok');
Once I try to upload the file, browser pops up a native dialog window, my options are "Open" / "Cancel". How do I click "Open" ? Also I don't know how to get the Selector for Open button.
I'm running this on Linux, Java Script. Below is the error,
1) The specified selector does not match any element in the DOM tree.
 > | Selector('#Open')
Browser: HeadlessChrome 78.0.3904 / Linux 0.0.0
Screenshot: /app/code/screenshots/2019-12-11_22-28-52/test-2/HeadlessChrome_78.0.3904_Linux_0.0.0/errors/1.png
71 | //.handleAlert().click()
72 | //.click('#Open');
73 |
74 | await t
75 | .setNativeDialogHandler(() => true)
> 76 | .click('#Open');
77 |
78 | const history = await t.getNativeDialogHistory();
79 | await console.log(history);
80 | }
81 |}
at <anonymous> (/app/code/gen_lib/gen_lib.js:76:24)

async uploadFile() {
await this.t
.setFilesToUpload(<Your input selector>, [
'path to file/Image.jpg'
])
}

Related

Failed to compile react webapp after using javascript prisma for mysql

Hello beautiful humans!
I'm working on building a project that uses React Webapp for the frontend, using Prisma to go from javascript to MySql with Aiven to then Twitter API to create auto posts.
GitHub: https://github.com/jennjunod/twitter-tagging
Using this guide from Prisma... Using Miro as a visual representation
Failed to compile.
Error in ./src/reportWebVitals.js
Syntax error: 'import' and 'export' may only appear at the top level (3:0)
1 | const reportWebVitals = onPerfEntry => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
> 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
| ^
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
# ./src/index.js 19:23-54

How solve issue TypeError: strings.slice(...).reduce is not a function?

I recently dicovered Gatsby and I want to use this template for my own website:
https://github.com/toboko/gatsby-starter-fine
When downloading it, manage to run it http://localhost:8000/ but I get this error which I can escape:
TypeError: strings.slice(...).reduce is not a function
I added my repository here so you can take a look too: https://github.com/melariza/gatsby-starter-fine
Could you take a look and help fix it?
Screenshot of the error:
enter image description here
Here's the error text:
TypeError: strings.slice(...).reduce is not a function
css
/Users/mga/Sites/gatsby-starter-fine/.cache/loading-indicator/style.js:5
2 |
3 | function css(strings, ...keys) {
4 | const lastIndex = strings.length - 1
> 5 | return (
6 | strings.slice(0, lastIndex).reduce((p, s, i) => p + s + keys[i], ``) +
7 | strings[lastIndex]
8 | )
View compiled
Style
/Users/mga/Sites/gatsby-starter-fine/.cache/loading-indicator/style.js:14
11 | const Style = () => (
12 | <style
13 | dangerouslySetInnerHTML={{
> 14 | __html: css`
15 | :host {
16 | --purple-60: #663399;
17 | --gatsby: var(--purple-60);
View compiled
▶ 18 stack frames were collapsed.
(anonymous function)
/Users/mga/Sites/gatsby-starter-fine/.cache/app.js:165
162 | dismissLoadingIndicator()
163 | }
164 |
> 165 | renderer(<Root />, rootElement, () => {
166 | apiRunner(`onInitialClientRender`)
167 |
168 | // Render query on demand overlay
View compiled
I guess the problem is related to Node and its dependencies. The repository is not an official Gatsby starter and the last commit dates from 3 years ago. Gatsby is now on version 4.14 while the starter is on ^2.0.50. Two major versions happened during the last 3 years only in Gatsby so imagine the rest of the dependencies.
The starter doesn't contain a .nvmrc file or engine property in the package.json so the Node version that runs that project is unknown. Be aware that if you clone or fork that project, you will have a lot of deprecated dependencies and you'll have several migrations to do (from v2 to v3 and from v3 to v4).
So my advice is to reject that repository and use one of the officials. If that's not an option, try playing around with the version of Node, starting from 12 onwards, reinstalling the node_modules each time you upgrade or downgrade the version.

Access file name in the transformed gulp stream

I have the following gulp task configured:
var assets = plugins.useref.assets({searchPath: './'}),
css = plugins.filter('**/main.css'),
html = plugins.filter('**/*.html');
return gulp
.src(config.html.srcheader)
.pipe(plugins.plumber())
// collect all assets from source file by the means of useref
.pipe(assets)
//// minify main.css
.pipe(css)
.pipe(plugins.csso())
.pipe(css.restore())
//// Take inventory of the file names for future rev numbers
.pipe(plugins.rev())
//// Apply the concat and file replacement with useref
.pipe(gulp.dest(config.rootdir))
.pipe(assets.restore())
.pipe(plugins.useref())
//// Replace the file names in the html with rev numbers
.pipe(plugins.revReplace())
.pipe(transformStream())
//// rename source
.pipe(html)
.pipe(plugins.rename(config.html.customer.targetheader))
.pipe(gulp.dest(config.html.dir));
The code takes css files, minifies them, adds a revision (e.g. main-abcde123.css), replaces the occurrence of the source file with the processed file. This is done by the means of gulp-useref/gulp-rev/gulp-rev-replace plugins (plugins is an object with all loaded plugins i.e. plugins.useref - refers to gulp-useref plugin)
This code works fine.
I'm trying to make some modifications with the result css file in the same stream. That is done by the means of transformStream() function which looks as follows:
function transformStream() {
var collect = function(file, enc, cb) {
console.log(file);
return cb();
}
var emit = function(cb) {
return cb();
}
return through.obj(collect, emit);
}
In this context through is gulp-through2 plugin.
Please take a look at the following code console.log(file);.
I'm trying to get the file name of the minified css. The code above displays the following:
<File "assets/main-34d85b66.css" <Buffer 40 63 68 61 72 73 65 74 20 22 55 54 46 2d 38 22 3b 40 66 6f 6e 74 2d 66 61 63 65 7b 66 6f 6e 74 2d 66 61 6d 69 6c 79 3a 22 6d 74 63 22 3b 73 72 63 3a ... >>
i.e. it contains not the file name but some kind of a buffer. I read the through2 documentation but it did not clarified the things.
So, my question is: how I can access the actual file name?
You can grab the properties from file from doing some simple iteration over it:
for (var property in file) {
console.log(property);
}
/*
history
cwd
base
stat
_contents
isBuffer
isStream
isNull
isDirectory
clone
pipe
inspect
*/
If you're looking for file name only, then file.relative is what you need.
file.history will give you working directory + file name
file.cwd for current working directory
file.base for base path
etc.
Have you tried gulp-filenames? I'm not sure how it would work in this context, but it will store the new, versioned file name in memory. Something like this:
...
return gulp
.src(config.html.srcheader)
.pipe(plugins.plumber())
.pipe(assets)
.pipe(css)
.pipe(plugins.csso())
.pipe(css.restore())
.pipe(plugins.rev())
.pipe(gulp.dest(config.rootdir))
.pipe(assets.restore())
.pipe(plugins.useref())
.pipe(plugins.revReplace())
.pipe(plugins.fileNames('my-css-file'))
}
Then you can get the filename later with
function transformStream() {
var fileName = plugins.fileNames.get('my-css-file')
}

Chrome 16 websocket binary

I'm trying to set up a websocket server in node.js but having problems. I found a bit code here on stackoverflow and heres the servercode I have now:
var net = require("net"), crypto = require("crypto"), users = [];
net.createServer(function(socket) {
this.name = "Anonymous";
users.push(socket);
socket.on('data', function(buffer) {
if(buffer.toString('utf-8').substring(0, 14) === "GET / HTTP/1.1") {
this.securyPattern = /Sec-WebSocket-Key: (.*)/g;
this.key = this.securyPattern.exec(buffer);
this.magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
this.sha1 = crypto.createHash("sha1");
this.sha1.update(this.key[1] + this.magic);
this.accept = this.sha1.digest("base64");
socket.write("HTTP/1.1 101 Switching Protocols\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: " + this.accept + "\r\n\r\n");
} else {
console.log(buffer);
console.log(buffer.toString('utf-8'));
}
});
socket.on('end', function() {
users.splice(users.indexOf(socket), 1);
});
}).listen(1337);
Everything works fine as it connects, and users.length is updated when that happens and when someone disconnects.
The problem is that I dont know how to read messages except the header (which is plain text), so the lines that I have to print the buffer and buffer.toString('utf-8') only prints something binary different all the time, example for the word "hello":
<Buffer 81 85 71 dc c1 02 19 b9 ad 6e 1e>
??q??☻↓??n▲
<Buffer 81 85 8e 8f 0f a2 e6 ea 63 ce e1>
????☼???c??
I'm sending this "hello" with Chrome 16 using:
myWebSocket.send("hello"); where myWebSocket is the WebSocket object.
So how do I read and write messages to the socket with this?
Note that after the handshake, the data is framed with 2 or more header bytes at the beginning of each frame. Also, note that payload sent from the client (browser) to the server is masked using a simple 4-byte running XOR mask.
The framing definition is defined in section 5 of the spec
Instead of implementing your own WebSocket server in Node you might consider using a higher level abstraction like Socket.IO.
Here's my code on handling that buffer:
socket.ondata = function(src,start,end) {
src = src.slice(start,end);
var maskKeys = [src[2],src[3],src[4],src[5]];
var dest = new Array();
for(var i=0;i<src.length-6;i++){
var mKey = maskKeys[i%4];
dest[i] = mKey ^ src[6+i];
}
console.log(new Buffer(dest).toString());
}
Found from here: http://songpengfei.iteye.com/blog/1178310

Fullpath of current TCL script

Is there a possibility to get the full path of the currently executing TCL script?
In PHP it would be: __FILE__
Depending on what you mean by "currently executing TCL script", you might actually seek info script, or possibly even info nameofexecutable or something more esoteric.
The correct way to retrieve the name of the file that the current statement resides in, is this (a true equivalent to PHP/C++'s __FILE__):
set thisFile [ dict get [ info frame 0 ] file ]
Psuedocode (how it works):
set thisFile <value> : sets variable thisFile to value
dict get <dict> file : returns the file value from a dict
info frame <#> : returns a dict with information about the frame at the specified stack level (#), and 0 will return the most recent stack frame
NOTICE: See end of post for more information on info frame.
In this case, the file value returned from info frame is already normalized, so file normalize <path> in not needed.
The difference between info script and info frame is mainly for use with Tcl Packages. If info script was used in a Tcl file that was provided durring a package require (require package <name>), then info script would return the path to the currently executing Tcl script and would not provide the actual name of the Tcl file that contained the info script command; However, the info frame example provided here would correctly return the file name of the file that contains the command.
If you want the name of the script currently being evaluated, then:
set sourcedScript [ info script ]
If you want the name of the script (or interpreter) that was initially invoked, then:
set scriptAtInvocation $::argv0
If you want the name of the executable that was initially invoked, then:
set exeAtInvocation [ info nameofexecutable ]
UPDATE - Details about: info frame
Here is what a stacktrace looks like within Tcl. The frame_index is the showing us what info frame $frame_index looks like for values from 0 through [ info frame ].
Calling info frame [ info frame ] is functionally equivalent to info frame 0, but using 0 is of course faster.
There are only actually 1 to [ info frame ] stack frames, and 0 behaves like [ info frame ]. In this example you can see that 0 and 5 (which is [ info frame ]) are the same:
frame_index: 0 | type = source | proc = ::stacktrace | line = 26 | level = 0 | file = /tcltest/stacktrace.tcl | cmd = info frame $frame_counter
frame_index: 1 | type = source | line = 6 | level = 4 | file = /tcltest/main.tcl | cmd = a
frame_index: 2 | type = source | proc = ::a | line = 2 | level = 3 | file = /tcltest/a.tcl | cmd = b
frame_index: 3 | type = source | proc = ::b | line = 2 | level = 2 | file = /tcltest/b.tcl | cmd = c
frame_index: 4 | type = source | proc = ::c | line = 5 | level = 1 | file = /tcltest/c.tcl | cmd = stacktrace
frame_index: 5 | type = source | proc = ::stacktrace | line = 26 | level = 0 | file = /tcltest/stacktrace.tcl | cmd = info frame $frame_counter
See:
https://github.com/Xilinx/XilinxTclStore/blob/master/tclapp/xilinx/profiler/app.tcl#L273
You want $argv0
You can use [file normalize] to get the fully normalized name, too.
file normalize $argv0
file normalize [info nameofexecutable]
seconds after I've posted my question ... lindex $argv 0 is a good starting point ;-)