Showing posts with label chrome. Show all posts
Showing posts with label chrome. Show all posts

Saturday, January 9, 2016

Selenium style automation script with plain JavaScript in Chrome

It is hard to beat Selenium for heavy browser scripting - it has a lot of features, support and infrastructure. But if you only need it occasionally, everything already exists in Chrome.

For example:

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

async function demo($x) {
    $x('//a[@title="Click here first"]')[0].click();
    await sleep(2000);
    $x('//button[text()=\"Click here then\"]')[0].click();
}

demo($x);


It even have advantages over Selenium: you can omit initialisation, like logins and captchas and script only functional parts. Perfect for boring repetitive tasks and adhoc testing.

Saturday, March 6, 2010

JSON formatting

Sometimes it is needed to format JSON to check it's content. Intellij IDEA and Eclipse do the job pretty well, but if these are not available it is easily possible in Google Chrome. To do it:
1) Go to Control the current page menu (document icon to the left of address input) then Developer/JavaScript console.
2) Enter console.log({qwe:123}) (where {qwe:123} is just any JSON object).
3) You got nice JSON object tree as output.
There is some noise from Chrome, but it is possible to see and browse your object.
Same feature is in Firefox with Firebug plugin, even the same syntax.


UPDATED: Nice online JSON formatting tool: http://chris.photobooks.com/json/default.htm .