Develop Selenium webdriver scripts using javascript - javascript

Can we develop selenium webdriver scripts using javascript only. If yes what are the advantages of using javascript instead of using java or C# or any language.? In what scenario we should consider Javascript over other languages?
Thank you.

There are numerous Javascript frameworks written on top of the JS selenium bindings (webdriver.io, nightwatch, protractor).
Benefits of JS over C# or Java
Less boilerplate
Grunt or gulp for build automaton > maven, msbuild or even gradle
Better integration with front-end frameworks (protractor)
JS is generally used in all web projects so it works as a universal language that all devs can understand.
NPM for dependency management and the massive number of libraries in it that may drastically reduce your workload.
Drawbacks
The Java bindings have more documentation / resources available to debug issues.
Speed (I find using the AjaxPageFactory in Java to be a lot faster than protractor and I have not found an equivalent in Javascript)
Promises can be complicated coming from Java or C#.
No support for Microsoft Edge currently.
As far as specific use cases if you use Angular heavily on the front-end Protractor is a tool designed specifically for functional testing of angular and should be used over C# or Java. Protractor can be used with frameworks such as React.js but it wasn't designed for it and you may need to include a lot of waitForElement type code.
A few things I have found really nice about protractor specifically is the configuration for more comprehensive multi-browser testing. To set this up in Java or C# involves a lot of configuration and in Protractor it could be as simple as make two changes to your conf.js file. I also find myself using a lot of grunt plugins to set up and tear down my tests which are very simple to configure.
I would recommend using Babel.js so you can utilize the es2015 JS syntax which makes the transition from Java or C# simpler due to the inclusion of classes and I personally find it much more cleaner for writing page objects.
One thing to be aware of is a lot of simple actions in Selenium for Java and C# are more complicated in Javascript because most actions return promises.
Java Version
int previousNumberOfItems = driver.findElements(By.className(".item")).size();
driver.findElements(By.cssSelector(".addItemButton")).click();
int currentNumberOfItems = driver.findElements(By.className(".item")).size();
assert.AssertTrue(currentNumberOfItems .contentEquals(previousNumberOfItems +1));
Protractor (JS) Version
element.all(by.className(".item")).count().then(function(number){
element(by.css(".addItemButton")).click();
expect(element.all(by.className(".item")).count()).toBe(number+1);
});
I can't really speak for nightwatch or webdriver.io they may be much better for testing non-angular apps using Javascript.

Yes you can use Nodejs protractor Jasime framework with WebDriver.
Here is some link:
Webdriver java script binding
Angularjs Jasmine

Related

Can I develop an Angular 5 app using JavaScript?

I'm new in web dev, and I am currently reading about Angular, and other frameworks. I know that Angular is written in TypeScript, but I'm wondering if it is possible to develop an app using Angular and JavaScript?
As TypeScript is a superset of JavaScript, existing JavaScript programs are also valid TypeScript programs.
(Wikipedia)
Meaning, All JavaScript is valid TypeScript. TypeScript only adds thing to the JavaScript language, you are not required to use these new features such as Types, you can skip them and just type normal JavaScript.
However, when you develop Angular applications you become a user of the #angular-cli package and tool which helps you generate boilerplate code for your files and projects. This code that is generated by the CLI is written using TypeScript features -- So if you for some reason refuse to use TypeScript, it will make your development experience worse since you will not be able to use all of the Angular tools that help your development, such as the CLI or the Documentation.
Yes.
Angular does use .ts files by default. But if you write simple javascript code in them it will still work. Valid javascript is also valid typescript.
Once you get up and running with angular though you will see the benefits of Typescript are worth it. It won't make sense to write an Angular app using just javascript.
The question you should ask yourself is why would you do that? TypeScript became a standard for large front-end applications. It stays ahead of the curve of EcmaScript, bringing more features that are only going to become part of the standard and then implemented. Not to mention static types, which ensure all sorts of runtime errors just never happen.
Also, TypeScript is a superset of JavaScript, you can write your ol' regular JS in .ts files and never worry about all the goodness TypeScript gives you if that is what you want.
Yes, You can but it would not be sophisticated and well-timed application If you want to avoid Typescript. Even ECMAScript 2017 also very similar to Typescript. So, It would be definitely better to go ahead with Typescript.
Introduction to Angular concepts
Angular is a platform and framework for building single-page client applications using HTML and TypeScript. Angular is written in TypeScript. It implements core and optional functionality as a set of TypeScript libraries that you import into your apps
read more

javascript library in my Java project?

I am working on a project in Java that involves designing a speedometer. I am looking for any libraries that I can possibly use. However, I found a lot of such "gauge libraries" for javascript. Is there any way I can implement this javascript library in my project Java?
I think its all depend on the architecture of your application, for example building a reactive application on the JVM, using a technology like Vert.x will allow you to do that.
I strongly recommend vert.x, you will find a lot of magic there

Test Driven JavaScript Development with Django vs Node.js

I have a web project coded 80% in JavaScript and 20% in Django without a single unit testing as I rushed for Minimum Marketing Features. Now that the project is getting funded, I decided to invest some time to introduce TDD. I had a great deal of inspiration from this KickStarter-funded tutorial.
http://www.letscodejavascript.com/
The author uses Node.js, Jake, Lint, Nodeunit, and Karma to simplify the whole integration process. The server/client tests in all major browsers is done in a single command and I was really hooked to this idea, but it requires switching to Node.js.
I've searched for TDD in Django and ran into this tutorial that makes use of Selenium.
http://www.tdd-django-tutorial.com/
However this TDD was primarily based on unit testing in server. Here are the questions.
Can multiple client JavaScript testing be done in Django/Python?
I assume the answer is no since js files are nothing more than static library in Django. Correct me if I'm wrong.
Is it worth using Node.js just for the sake of TDD Javascript?
My logic was either you use Python or Node.js for the server, but since tools like Karma and Buster.js requires Node.js, I was wondering whether setting up the Node.js alongside Django just for multiple client testing is plausible choice when considering lower cost of maintenance.
Thank you :D
You can take a look at using selenium in your django test suite. Django's official docs cover this in moderate detail
To answer your question about Node.js - I would say that it's probably not worth the complexity to add node.js SOLELY for the purpose of running unit tests. Also, since your javascript is likely built to run in a browser, it's less likely that things will break down if you use a tool like selenium (which runs the code in an actual browser, providing a python scripting interface).

unit testing modular javascript

I am currently deriving a javascript framework pattern as an architecture for the client side development for an upcoming large scale application that I will developing.
I am looking to go with a module observer pattern in which each control I develop will have its own javascript file, holding no knoweldge of the other controls.
From designing this framework for my application, I am looking to integrate in a testing mechanism for my modules - a unit testing mechanism for javascript. I am not aware of any such frameworks or how I may set up such. Any suggestions?
As part of such testing, I will also need to mock up http requests.
The library I will be using in development is jquery.
The JQuery team has QUnit.
As for abstracting out AJAX, you should wrap it appropriately or just test the data manipulation methods.
Jasmine may be what you are looking for. It has built-in mock up support, and does not rely on any other frameworks.
They also have a separate module for faking AJAX responses.
The setup is simple. Just download the standalone version, write some testing suites, and view the SpecRunner.html in a browser.
Consider using JsTestDriver to run your JS tests. The main benefit it provides - it can run your tests on continuous integration environment, which is essential for unit testing practice.
Some additional features:
It can be used along with QUnit and other testing frameworks.
It can execute your tests in parallel across multiple browser.
It supports calculation code coverage.
List of mocking libraries you can find in another thread.
BoilerplateJS
is a reference architecture for large scale JavaScript product development. You can find the tests which are written using qunit, sinon and testr included under the tests folder.

Build automation and deployment for Javascript

i work at the digital department of a public broadcaster, together with two other frontend developers. We're currently looking into improving our Javascript workflow and build processes. Stuff like packaging, minifying, versioning, etcetera.
In an ideal scenario, we would have a global repository for all Javascript-related libraries (like jQuery) and stuff we build ourselves, that can be easily included in lots of projects and versioned.
All of our backend developers use Maven for this process with their Java code. I'm wondering if people have experience with Maven and Javascript, or maybe with other tools that might be good (or better) for the job. And in general if people have good resources about setting up workflow / build processes for frontend and javascript development.
We use Hudson (http://hudson-ci.org/) to continuously build/integrate our Python (Django via zc.buildout), R and several other types of projects. Whenever someone checks in code to the central VCS, a build is triggered and the test suite(s) will run. The build and test status is shown on a central screen in the office.
Hudson not only builds and tests, but also checks for coding style and syntax errors using pep8 and pyflakes, amongst others. Javascript is only checked with jslint at this point, but we may unit-test that in the future using something like xpcshell (more info).
** edit **
Go straight for Jawr, keeping rest in answer for alternatives
** edit **
First of all there's Ruby's rake which in theory can be used through jruby and in theory can be configured and run in the POM.
There's also Jake, but not sure if the latest Rhino supports CommonJS.
Whilst writing this awnser, I just came across Jawr which looks really interresting and there seems to be maven support/plugins.
The last option you already know about is dynamic loading using for example RequireJS or LABJS.

Categories

Resources