What is the benefit of the WebDriver protocol over injected JavaScript automation? - javascript

The W3C defines the WebDriver Protocol, which can be used to automate user inputs on web pages within browsers. It can be used with external browser drivers (such as Google Chrome's Chromedriver or the FireFox Gecko Driver), and actions like button presses and hover events (and many more) can be simulated.
However, I could get the same result by just injecting some custom written JavaScript code which directly generates the events and runs them within the web page context. I could for example just create an MouseEvent instance and dispatch it to simulate a click event.
I know that the WebDriver protocol is the state-of-the-art approach to browser automation, but why is that so? What are the benefits of using a protocol which requires browser dependent driver software, when I could just open the Webpage and run injected automation code?
I would probably still need external software to open a browser instance and inject the automation code, but I don't see the need for a full browser-external interface for event automation.

Jason Huggins started building the Core mode of Selenium (the original one) as JavaScriptTestRunner wherein a javascript automation script is injected to the web application to run automation.
Same origin policy was one of the main hurdles for this mode of automation which states that to execute javascript files on a web page, the javascript file should originate from the same domain on which the web page loaded from. For example: to run javascript function from js files on www.google.com page, the javascript files must be downloaded from www.google.com web server itself. The browser prevents the user from injecting a javascript file from outside and executing it.
So how did Jason do the automation? He included the JavaScriptTestRunner in the web application under test.
Expecting testers to have access to the web server to include the JavaScriptTestRunner into the server is not practical. Also, in production servers this is big NO-GO.
RC and then the WebDriver projects then came about to tackle these issues.
With WebDriver protocol, a user only needs access to the application under test in a browser to write UI automation. There is no need to have back end server access.
WebDriver architecture is beautifully designed to have 2 objects(primarily) to achieve automation - WebDriver to control the browser and find WebElements and WebElement to perform operations on the application UI.
// Open chrome
WebDriver driver = new ChromeDriver();
// open url
driver.get("url");
// find element
WebElement someElement = driver.findElement(By.id("some-id"));
// perform operation on element
someElement.click();

no risk of conflicts with other javascript running on the page
works on resources that are not html pages, have no dom, and won't run javascript
can access features (eg. browser logs) that injected js does not have permission to run
flow control is not broken by unexpected page navigation, reload, etc
easier to deal with switching between tabs, windows, frames when your code isn't running inside one of those frames

Related

Device finger print not getting recorded in Jmeter script

I face error while scripting Credit card transaction in jmeter.
Issue seems device finger print is not getting capture (which is dynamic ) .this dynamic parameter is not generated hence script fails .signature generation algorithm generates signature but jmeter fail to capture it .
As per JMeter project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
So if your fingerprint checking or signature generation algos rely on JavaScript execution in the client (browser) you won't be able to record and replay your scenario in JMeter.
The options are in:
Use a real browser, there is WebDriver Sampler which provides JMeter integration with Selenium browser automation framework, this way each thread (virtual user) will kick off a real browser and real browsers are normally capable of executing JavaScript
Replicate the logic of JavaScript in terms of fingerprint reporting or signature generation using JSR223 Test Elements and Groovy language

Trigger/Execute a java program from browser script

We are converting our java-swing based desktop app into web based using javascript + react. Our current swing app uses local file operations heavily and performs lot of read/write actions on client OS. As you know in browser environment it is not very easy/possible performing local file access because of security restrictions. I know there is File API in html5, but all file related operations needs user iteraction (file browse action should be originating from a real human, not by script). Additionally we have als other native features such as port reading etc which are not possible with browser and javascript.
Can we trigger a java program from an html page in same manner for example the application zoom can start its native executable directly from an link. I think during the install of native executable zoom app, it registers himself to windows regedit etc. Can we make same thing for an java app?

Simulate web browser user input programatically c++

How do i send a JavaScript command to a web browser from an external c++ application?
At the moment what i am currently doing is saving the HTML file locally, modifying it, and send a command to refresh the browser from my application.
This might be trivial for some, but I was wondering if i can send the JavaScript command directly to the web browser and see the changes happen without modifying the source code.
I am currently using the following: Firefox, Chrome and IE.
I tried with modify files from within my application using QWebEngineView but it takes a ridiculously long time to load the pages and some webpages are complaining that the browser is too old.

Start a background process with javascript

In general I am aware that one cannot call system libraries or dll's from javascript in browser. But in many of the application's I see browser starting other processes. For example:
As soon as I open Google Plus, it starts the googletalkplugin.exe (from folder C:\Users\Jatin\AppData\Local\Google\Google Talk Plugin) in the background. (Can be viewed in Resource monitor)
The same with facebook video chat. For the first time, it asks me to install a plugin and later when I start a chat, it starts a process.
On torrent sites, they provide magnet links. Clicking on torrent magnet link, it opens my systems default torrent client.
In a way, the same with flash and applet.
How do browsers trigger another process and communicate with it? Is there any open standard I am missing?
Ultimately I wish to do video, audio recording with screencast. For screen-recording, Java applet looks like the only solution but applet has its own Issues.
The flash player and applets use plugins, which are native applications to the OS, (i.e. (mostly) not JavaScript), they are not extensions but plugins. For Chrome see chrome://plugins/ to see the list of installed plugins.
For writing a browser plugin, refer to How to write a browser plugin?
The torrent link is totally different, they are done by registering an url protocol to handle. In other words, you say to the computer that, from now on, I will run any urls which have protocol of torrent, i.e.: starts with torrent://. See: Uri Scheme
When the browser sees the uri, it knows that is not handling torrent protocol itself, so it delegates that to OS, which knows what to do with it.
If the browser did know how to handle that, it probably would not delegated that to OS. For example: Google Chrome can handle mailto: links just well without registering mailto protocol to be handled by OS.
You can do this by writing a plugin. It's possible to write plugins that work on most popular browsers, using the same C++ code, using a library called Firebreath
Naturally there is no pre-existing standard plugin that allows the page to start any external application, because that would be a massive security hole and no (sane) user would agree to install such a plugin.
You have to write a specific plugin with capabilities carefully limited to what you need, so the user can agree to let you use just those capabilities. Again, think about how another page might exploit those capabilities before going down this route.

Open client side program using Javascript

I have created a Java program which takes some command line arguments to run. I need to make a browser extension to the program so that the program can be opened with data from the browser.
I know Javascript does not allow any local file access, but there are programs which doing the task I needed.
Examples are Internet Download Manager which has the browser extension for running it receiving command line arguments from the browser. Obviously extensions for most of the browsers including Chrome and Firefox are made using Javascript? Is there any way to do local program execution via JavaScript (I think there's a way surely)?
You can't directly run anything from your JS sandbox on client PC (just think about security risks!) There's other method however: Make your application register itself as protocol handler when it installs and use links with this protocol on your pages (think how e-mail clients serve mailto: or torrent clients serve magnet: links). Since you control both sending and receiving side, you can pass pretty much any information in those. You can find Windows example for registering a handle at MSDN. Should you need it for any other system, I'm pretty sure searching for "system_or_gui_name register protocol handler" will show you desired result among the first.

Categories

Resources