Is there a way currently to programmatically pull a coverage report from Chrome while Chrome is running under selenium or other automated control software?
From looking at this article, there is a reference in the comments that there's no way to export this data right now but there is a feature request.
There's another article here that talks about how the feature works and in the comments someone asks this same question. The response was that there's an API here that maybe you could take advantage of using a Chrome extension.
Now, Selenium only has access to the browser context via execute_script aimed to execute window.__coverage__; to collect the Front-end's coverage data. So, you need to instrument your source code using nyc and parse the returned value.
Related
The new version of UFT 12.01 is supporting up to Chrome 36 when it comes to web content.
What about Chrome´s extensions though?
I read somewhere that they cannot be automated.
From the other hand side, when I use developer tools (12) I can identify buttons, textboxes etc.
Is it possible to test a Chrome extension by using UFT?
PS: I specifically try to automate one extension called POSTMAN - Rest Client (https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en)
UFT's Chrome support doesn't work with other extensions since Chrome disallows extensions being injected into other extensions.
As a workaround you may be able to use UFT's Insight option to automate any technology that UFT doesn't support directly.
Specifically for the Postman extension, this is a simple REST Client. I Assume you want to use it in order to test your REST services rather than actually testing the Postman extension. If this is the case wouldn't a more natural way to approach this issue be to use a UFT API test?
API tests support calling and validating REST services with all the functionality previously available in HP's Service Test.
Basically what I need is a way to automatize the result of the following operations:
open a new tab;
open the Network tab in the developer tools;
load an URL;
select "Save All as HAR".
Often, proposed solutions involves the use of PhantomJS, browsermob-proxy, or pcap2har; those won't fit my case since I need to work with SPDY traffic.
I tried to dive into the Google Chrome Extensions API and indeed I managed to automatize some tasks, but still no luck for what concerns the HAR files generation. Now this method is particularly promising but I still can't figure out how would I use it.
In other words, I need something like this experiment from the Google guys. Note the following:
We used Chrome's remote debugging interface with a custom client that starts up the browser on the phone, clears its cache and other state, initiates a web page load, and receives the Chrome developer tools messages to determine the page load times and other performance metrics.
Any ideas?
Solution
For the curious, I ended up with a Node.js module that automates such kind of tests: chrome-har-capturer. This also gave me the opportunity to dig deeper into the Remote Debugging Protocol and to write a lower-level Node.js interface for general-purpose Chrome automation: chrome-remote-interface.
The short answer is, there is no way to get at the data you are after directly. The getHAR method is only applicable to extensions meant to extend DevTools itself. The good news is, you can construct the HAR file yourself without too much trouble - this is exactly what phantom.js does.
Start Chrome with remote debugging
Connect to Chrome on the debugging port with a websocket connection
Enable "Network" debugging, you can also clear cache, etc - see Network API.
Tell the browser to navigate to the page you want to capture, and Chrome will stream all the request meta-data back to you.
Massage the network data into HAR format, ala phantom.js
...
Profit.
For a head start, I have a post that with sample Ruby code that should you get started with steps 1-4: http://www.igvita.com/2012/04/09/driving-google-chrome-via-websocket-api/
By now there's a browser plugin to do that: https://github.com/devtools-html/har-export-trigger
It uses the WebExtensions DevTools API and I got it to work with both Firefox and Chrome.
See my code for Chrome here: https://github.com/theri/web-measurement-tools/blob/master/load/load_url_using_chrome.py#L175
Automatically installing the plugin in Chrome is a bit more complicated than in Firefox, but feasible - I extracted the plugin archive locally and then link to it in chrome_prefs.json (see same repository).
Not sure if it helps, HAR Recorder uses chrome debug protocol to record HAR and generate a har file (without opening devtools). If you want a variation, you can fork and make changes on it.
I compile the extension using the --pack-extension switch:
C:\Users\APOL0\AppData\Local\Google\Chrome\Application>chrome.exe --pack-extension="D:\MyExt"
Everything works fine: chrome generates Myext.crx and Myext.pem but I don't know how I can get extension ID for automatic installation using Windows' registry.
How can I get this ID without using "manual verification", ie. programatically?
Edit May 14, 2018: Added clarification and link to 3rd party tool.
There is no official supported method (at time of writing) to programmatically get the extension ID from a CRX without manually interacting with Chrome. (See official method below)
Unofficial Method
The only programmatic method I've found any reference to online is on this SO answer. The author of the answer later posted a link to a ChromeIdGenerator tool they wrote to accomplish this. The tool is based on how Chrome calculated its extension IDs at that point. Full disclosure: I have not tested the tool to ensure its accuracy, it is simply the only tool I've found to accomplish what you're asking.
Official Method (manual)
If you open up your Chrome Extensions manager page, you can drag and drop your Myext.crx onto the page (you must be in "Developer Mode") and it will load your extension, showing you the new extension id.
Recently, i have made a chrome ext, but anyone can read its source code by rename the crx to zip and extract it, how i secure my SC ?
The only way to prevent anyone with your extension from seeing the logic is to move it out of the extension that runs on a user computer and into a web service that the extension accesses.
Since this will slow down the works quite a bit, you should only do this for the really valuable parts of your code.
The best (and only?) way would be to obfuscate your JavaScript.
edit: Chrome Webstore does not allow you to obfuscate your JavaScript code. You can read it in the Chrome Webstore program policies
Code Readability Requirements:
Developers must not obfuscate code or conceal functionality of their
extension. This also applies to any external code or resource fetched by the
extension package. Minification is allowed, including the following forms:
Removal of whitespace, newlines, code comments, and block delimiters
Shortening of variable and function names
Collapsing files together
You can use Google Firebase API and related other storage services for write secure/safe business logic, because your google extension code is always open to show for every one....
:::: Example for your more help ::::
key-value from extension JS code ----- Transfer to Server ----> Firebase API perform your logics ---- send back to ----> extension JS code
FireBase is Free and light weight and perfect for business logic
I am on a mission to expand my knowledge and create an extension for chrome similar to how firephp works. I want to integrate with my existing logging and debugging api within my framework and I want to be able to send these messages to the console. Nothing really robust to start with just a way to send debug messages to the chrome console from php.
The plan is to send the messages via the headers and have the extension read those headers and interpret them. I've been trying to find information on accessing the response headers and can't find any examples. Some of the research has led me to possibly having to develop an NPAPI plugin to be able to accomplish this.
Before traveling down a dead end path I wanted to get the communities opinion here on which path I should be taking to find a solution.
Chrome cannot currently do this, but Google is working on it. A preliminary and incomplete implementation is in the development version of Chrome, or in Chrome Canary.
http://code.google.com/chrome/extensions/experimental.webRequest.html
onHeadersReceived
http://dev.chromium.org/developers/design-documents/extensions/notifications-of-web-request-and-navigation
You can track progress here.
http://crbug.com/50943
The web request api is now in stable and can be used to access header events.
https://developer.chrome.com/extensions/webRequest.html
Here is an extension that does what you are trying to do. It uses cookies to communicate, from what I can tell.