How do find active element in Intern - intern

According to the documentation linked from the Intern Git project (https://github.com/admc/wd/blob/master/doc/api.md) it should be possible to use active() to obtain the active element on the page...
However, when I use this I don't see my callback or fired or get any output, e.g...
.keys(specialKeys.Tab)
.sleep(1000)
.active(function(err, element) {
console.log("Active Element is: ", err, element);
})
However I'm not seeing any output at all, nor any error conditions... I am however seeing the tab event occurring. Any ideas on what I'm doing wrong here?
Many thanks.

The functional API in Intern is Promise-based, so you don’t pass callbacks into any of the methods except for then, otherwise, or always. Step 4 of the Intern tutorial describes this in more detail. Your code would be:
.keys(specialKeys.Tab)
.sleep(1000)
.active()
.then(function(element) {
console.log("Active Element is: ", element);
})

Related

How do I add button in NetSuite client script and use it as trigger for script function?

I'm trying to add a button to the current record with the Client Script button definition on a script record, but for some reason it's not finding my function. I'm returning my function tryThisand there is a button on the page which I created on the script record with the function tryThis defined in the appropriate field, but the code doesn't run. Here's my script:
define (['N/currentRecord','N/search','N/record'] ,
function(currentRecord,search,record) {
function tryThis(context){
log.debug({
title: 'try this',
details: 'try this'
});
}
function pageInit(context) {
}
return {
pageInit: pageInit,
tryThis: tryThis
};
});
Nothing happens :(
Yes, the script is deployed.
How can I use this button on a client script??
This doesn't exactly answer your question directly, but I hope it may help. I tested this, and there appears to be nothing wrong with the way you've set it up - the only thing that seems to be not working is the log module, which I've come across before in client scripts.
Try running your function using a console.log() or alert() instead (both work for me).
Hopefully someone with more detailed knowledge of the N/log module's design and behavior will chip in, as the documentation seems to indicate that this should work.
At the bottom of your Client Script record in Edit mode you will find where you can easily set the button and function to call.

How to read nodejs documentation regarding callback parameters (node v8.x)

I am trying to understand the node.js documentation specifically for the https.get() method. https://nodejs.org/dist/latest-v8.x/docs/api/https.html#https_https_get_options_callback
What is unclear to me is the callback. The example in the document indicates the callback can take a res (response) object as its parameter but I am unsure if this is the only parameter it can take or more importantly where I can find the definition of the res object so I can know what properties and methods I can access on this object.
Is there a straightforward way to identify this?
I have read this thread: Trying to understand nodejs documentation. How to discover callback parameters and the answers seem to suggest that if there is a non-error argument that a callback can take it will be documented, but I am assuming that answer is outdated.
I've run into the same issue with many Node/NPM packages. Documentation sometimes does not describe the parameters well.
So, welcome to JavaScript in 2018! It's gotten a lot better, though, to be honest.
My go-to method is to try the methods and dump the information myself.
Try a console.dir(res) in your callback:
https.get('https://encrypted.google.com/', (res) => {
console.dir(res);
});
Alternatively, you can set a breakpoint in the callback and inspect it yourself. You can then probe the arguments object* to see what else, if anything, was passed as an argument, or do another console dump:
https.get('https://encrypted.google.com/', function (res) {
console.dir("args:", arguments);
console.dir("res:", res);
});
EDIT: Wait, apparently the arguments variable is not available to arrow functions, fixed the second example.
*From MDN:
The arguments object is not an Array. It is similar to an Array, but
does not have any Array properties except length.
From your link https://nodejs.org/dist/latest-v8.x/docs/api/https.html#https_https_get_options_callback, you can see that it works like the http version :
Like http.get() but for HTTPS.
With http.get() clickable.
On that page (https://nodejs.org/dist/latest-v8.x/docs/api/http.html#http_http_get_options_callback), we can see this :
The callback is invoked with a single argument that is an instance of http.IncomingMessage
With http.IncomingMessage clickable, linking this page :
https://nodejs.org/dist/latest-v8.x/docs/api/http.html#http_class_http_incomingmessage
I agree the Node documentation is not very clear about the callbacks in general, and that is a shame. You can still use IDEs with good intellisense (and JSDoc to identify the type of the function parameters), like VSCode.
Or you can use a debugger, always works :)
Edit: If you want to see all the parameters sent to a function, you can use the spread syntax like this :
function foo(...params) {
// Here params is an array containing all the parameters that were sent to the function
}
If you want the absolute truth, you can look at the implementation. Though that's fairly time consuming.
If you find that the documentation is wrong, or in this case could be improved by adding a sentence about the callback parameter to https.get(), please open an issue, or, better yet, a pull request. This is where the change needs to be made:
https://github.com/nodejs/node/blob/67790962daccb5ff19c977119d7231cbe175c206/doc/api/https.md

Is it possible to catch the response of search feature available in url

I am trying to write automated screenshotter using puppeteer in node.js which will navigate to particular url.url have one faeture for search box which will give the information for desired query.If we get desired output screenshot is taken and saved to "success" folder but we didnt get any result (like no result found), i want screenshot in "failure" folder. Is It possible to record the response and segregate the screenshots.
You can check html value and return value with page.evaulate() then you can use switch case according to incoming value and use page.screenshot() function.
Here is your question broken down to bits,
You are trying to,
write automated screenshotter using puppeteer in node.js
which will navigate to particular url.
url have one feature for search box.
which will give the information for desired query.
If we get desired output
screenshot is taken and saved to "success" folder
but we didnt get any result (like no result found),
i want screenshot in "failure" folder.
Is It possible to record the response and segregate the screenshots?
The answer is, Yes.
For example, it can be a simple google/yahoo/duckduckgo results scraper . Save screenshot depending on the result count.
You can use .goto to go to the page, .$$ to check the results, .screenshot to take screenshot depending on the results.
Here is an example code to check if there is any result or not,
let results = !!await page.$("div > div > h3 > a");
// returns if there is any result in google search
let path;
if (results) {
path = "success/mysuccessimage.png";
} else {
path = "failed/myfailimage.png";
}
await page.screenshot({ path });
Since you did not share any code, no one will be able to help you. But I guess I answered your question. Now, you can implement it in a thousand ways, peace.

What is the difference between these two jQuery references and why does one not work with .live?

EmployeeId is the id of a select element with a set of options. This approach will not work:
var tar = document.getElementById("EmployeeId");
$(tar).live("click", function(){
console.log("Changed");
});
However, this approach does:
$("#EmployeeId").live("click", function(){
console.log("Changed");
});
What is the difference between $("#EmployeeId") and $(tar)?? I was under the impression there was no difference between the two. Moreover, when I try
console.log($(tar));
console.log($("#EmployeeId"));
The same exact thing is sent to the console.
What am I missing, what is different, why is one approach not attaching the event handler?
.live needs the selector to work with, since it binds the event handler to document and then tests whether the origin (or any element in the path) of the event matches the selector.
If no selector is provided, it won't work. That's why chaining methods like $('foo').children().live(..) does not work either.
Since jQuery 1.7, .live is deprecated for various reasons listed in its documentation: http://api.jquery.com/live/.
Alternatives are .on (1.7) and .delegate (1.4.2).

Scraping URLs from a node.js data stream on the fly

I am working with a node.js project (using Wikistream as a basis, so not totally my own code) which streams real-time wikipedia edits. The code breaks each edit down into its component parts and stores it as an object (See the gist at https://gist.github.com/2770152). One of the parts is a URL. I am wondering if it is possible, when parsing each edit, to scrape the URL for each edit that shows the differences between the pre-edited and post edited wikipedia page, grab the difference (inside a span class called 'diffchange diffchange-inline', for example) and add that as another property of the object. Right not it could just be a string, does not have to be fully structured.
I've tried using nodeio and have some code like this (i am specifically trying to only scrape edits that have been marked in the comments (m[6]) as possible vandalism):
if (m[6].match(/vandal/) && namespace === "article"){
nodeio.scrape(function(){
this.getHtml(m[3], function(err, $){
//console.log('getting HTML, boss.');
console.log(err);
var output = [];
$('span.diffchange.diffchange-inline').each(function(scraped){
output.push(scraped.text);
});
vandalContent = output.toString();
});
});
} else {
vandalContent = "no content";
}
When it hits the conditional statement it scrapes one time and then the program closes out. It does not store the desired content as a property of the object. If the condition is not met, it does store a vandalContent property set to "no content".
What I am wondering is: Is it even possible to scrape like this on the fly? is the scraping bogging the program down? Are there other suggested ways to get a similar result?
I haven't used nodeio yet, but the signature looks to be an async callback, so from the program flow perspective, that happens in the background and therefore does not block the next statement from occurring (next statement being whatever is outside your if block).
It looks like you're trying to do it sequentially, which means you need to either rethink what you want your callback to do or else force it to be sequential by putting the whole thing in a while loop that exits only when you have vandalcontent (which I wouldn't recommend).
For a test, try doing a console.log on your vandalContent in the callback and see what it spits out.

Resources