Selenium with typescript - java

What is the advantage of using selenium with Typescript over selenium with Java.
Which type of web applications can be automated with Selenium+Typescript and why these cant be done with selenium+java?

In term of automation -> Type scripts basically used by tools like protractor which actually used javascript itself but provide extension to write scripts in typescript which then converted to javascript and pass further for execution.
The main use of typescript is its oops based so its easy to write maintainable code.
Protractor is a nodejs plug-in which use selenium wedriverjs binding internally
Your second question why typescripts:
Basically Protractor is use on Angular-JS client side websites. still you can automate non-angular websites also using Protractor
Normally selenium do not have the capability to understand if the element is ready due to even after page load completed, JavaScript is still working behind for Anugular/JS based website so Protractor provide wrapper which having additional functionality like waitForAngular
Additionally Protractor provide more locators identify strategy which is not present in normal selenium with java or c#
Refer:
http://www.protractortest.org/#/locators
As Protractor is build on wedriverjs we also need to script for it on JavaScript or typescript. basically even if you code in typescript internally it will convert it into typescript. people prefer typescript as it follows full oops unlike like JavaScript
Source:
http://www.protractortest.org/#/
there are more js based framework is in the market like:
WebdriverIO
Nightwatch
Now java also comes up with many library like JSWaiter etc which claim they can handle js based client side websites with java + selenium as well

No major benefits in my opinion, that's my tl,dr;
I can think of a couple of options you might have though:
You might be able to integrate the test framework with the front-end application repository. This can be useful if you are using a Typescript based framework (like React for example) and you can potentially use that to import the application data (for example stub responses for APIs that the developers are using for their dev work, assuming they are available there... just an example) and use that for testing the front-end code in isolation without the API dependencies.
The other reason I can think of is that if you did the above you can potentially execute your test cases as part of the CI of the front-end code, for example you can run a subset of the test cases with pull requests to make sure all is green before merging in the main branch.
Really you can do all the above with an external repo written in Java (hence, no major benefits)

Related

How to use alternative js/browser engine with htmlunit instead of rhino?

Throughout my experiences with using htmlunit, I have slowly come to realize that htmlunit does not interact well with javascript.
The rhino js engine which htmlunit uses is most definitely the root cause of these issues, and I was wondering if it was possible to use something like geckodriver instead while still using htmlunit.
Any help is appreciated.
Thanks.
Some facts
HtmlUnit uses a slightly modified (improved) version of the Rhino engine
the team behind HtmlUnit is working on an implementation based on (a slightly modified) Nashorn (the js engine from the jdk) but there is still a lot of work to do
from the experience with the Nashorn task i can tell you that is is not simple to use a different engine but as for any other open source project feel free to provide patches
HtmlUnit is a java only implementation, it is one of the benefits to have a browser simulation that works on many different platforms eg. you can simulate IE from a linux box
To make the long story short:
If you have problem with HtmlUnit's JavaScript support
Read this Submitting JavaScript bugs
analyze you problem
open a HtmlUnit issue here, including a simple test case
[optional] provide a patch
The development team behind is small but active. If you provide a simple test case, there is a good chance to get it fixed.

One Selenium test script should support the website in different languages

I have a website for testing and also need to Automate the website tests using selenium with java using BDD framework.
The website is built in English language and it supports 52 different languages too. The only difference will be URL change and text language changes.
What is the best way to Automate this type of website?
The requirement is, website should be automated and my selenium script should support the website when in all the languages. Is this a possible scenario?
Thought i have in my mind is put the list of URL's and texts for assertions of a website for all the languages,(Which is a gigantic process) in a repository and automate all the tests. Then Webdriver startup function will have a logic to identify for which language i am running the website tests for? and execute the tests accordingly. But finding for a better way
Couple of things.
Make different property files for each language. Actually if your site is localized it's already there, you just need to re-use that.
if you are using Maven you can choose this property file based on the variable you pass in maven command. which would be easy to configure in jenkins as well.
Use property files only for text verification for finding element use unique IDs, if element doesn't have that ask developers to use it rather than making any xpath/css which contains text.

Selenium WebDriver: To which extent can I rely on JavaScript?

I am developing a library that extends Selenium 2 with some custom commands. The library should be usable from Selenium's Java and Python bindings as well as in Selenium IDE. From my research, these three target bindings should cover at least 80% of all Selenium 2 scripts.
In order to implement my custom commands for Selenium IDE, I think I need to write a plugin for it in JavaScript.
My question is this: If I already have an implementation of my custom commands in JavaScript, is it safe to re-use this implementation for the Java- and Python bindings of my library?
I am thinking of an approach that injects the JavaScript implementation of my commands via WebDriver#executeScript. Here is a pseudocode implementation of what I am thinking of.
In Java:
public void fooJava() {
executeScript("Inject code.js");
executeScript("fooJavaScript();");
}
In code.js:
function fooJavaScript() {
// Implementation of command "foo" from Selenium IDE plugin.
}
So, to execute my custom command fooJava() in Java, my library's code.js would be injected into the browser via executeScript. This would contain a JavaScript implementation of foo, say fooJavaScript. In a next executeScript call, this fooJavaScript would then be called.
While this approach would prevent me from having to implement my custom commands three times (Java, Python, Selenium IDE), I have a few concerns:
When I inject my code.js, am I in danger of destroying global state of the web site?
To which extent can I rely on JavaScript? Will it work if an alert dialog is present? In practice, how many of the drivers used with Selenium do not support JavaScript? Eg. HtmlUnit?
Will this work in all major browsers (somewhat recent versions of IE, Chrome, Firefox, Safari)?
Your real-life experiences with this would be much appreciated.
Principle states you should not be using JS as your testing mechanism if you are just delivering a payload with WebDriver.
WebDriver = integration testsJS = if you want unit tests
I don't know your use cases exactly, but:
If you're trying to run integration tests, stick with WebDriver to best simulate user interaction. You also avoid cross-browser JS issues in the future by relying on the WebDriver hooks to interact with the page, as in, you are better off relying on the community to provide reliable basic DOM interaction APIs for each browser. If you can't trigger test conditions with browser interactions, you're getting into unit/code testing territory instead of integration testing.
If you are trying to run the JS for sake of essentially testing a single function or piece of code rather than an integrated interaction, you are trying to run a unit test. Unit tests are best done in JS with something like Jasmine (name any framework here).
Reasoning:
Integration tests should be written to be as implementation independent as possible. You should not need to know a function name to trigger an integration test, since someone might change the function name in the future or restructure the code.
Since you are filling a QE/tester role, you do not want to be responsible for breaking integration tests when code changes - if you use this and are responsible, then you will need to change a test every time there is a code restructure.
Sources: Experience as a QE in 10,000+ employee software co.

Invoke a GWT RPC service from Java directly

Is there an easy way to invoke a GWT RPC service endpoint directly from Java code? I mean real Java code, not Java code compiled down into javascript.
I ask because we want to run performance benchmarks/stress tests against a GWT RPC interface. I would like to write the test harness in Java and run it in a JVM (as opposed to javascript running in a browser).
I figure there must be a way to do this because I assume GWT Hosted mode requires such functionality. However, I can't really find any code in the GWT runtime that demonstrates how to cleanly do this. I've looked at the com.google.gwt.user.client.rpc package but the stuff in there seems to use JSNI which obviously wouldn't be usable by pure Java.
GWT SyncProxy allows you to access GWT RPC services (e.g methods) from pure Java (not JSNI) code. Thus you can use it to test your RPC interface.
See http://www.gdevelop.com/w/blog/2010/01/10/testing-gwt-rpc-services/ for details.
Are you trying to benchmark the business logic of the service, or how well GWT-RPC itself performs? If you are mostly worried about how well your backend code performs, you could just instantiate the class that implements your service directly:
MyServiceImpl impl = new MyServiceImpl();
impl.doSomething();
If you want to test a greater slice of the stack, including the RPC calls, take a look here. There is a section called "running your test in web mode" that has the following line: 'By default, tests run in hosted mode are run as normal Java bytecode in a JVM'. So if you use the described setup, I think you get your tests to run in java by default. Also on that page is info about GWT's built in profiling tools.
You could use a conventional load testing tool like Grinder to replay post requests to your service. That isn't quite what you are asking but it may be a better way to perform load testing on your application. Grinder can simulate many simultaneous users and so on.

Load-Testing a Java-Client-Server-Application

we use spring-remoting for a Client-Server-Application. Now we are in doubt how to realize a real load test with serialized objects.
The problem is that many load testing toolkits are based on plain text HTTP communication, so it's very easy to parameterize the http-requests. Because spring-remoting is based on serialized objects we can't easily parameterize the http-communication to the server.
My first idea was to encapsulate the endpoint of spring-remoting and to call the service over client-side service classes. But how can I realize calling the remote-service from multiply clients to gain a real load test scenario?
Are there any solution for wrapping the client-side service in an easy manner?
Has anybody some experiences how to realize it?
Thanks for advice.
There is a discussion on the Spring forums about how to use JMeter to do testing. To use JMeter you'll need to write a custom Sampler. They have examples on the JMeter site.
Alternatively, you could try Grinder. Testing scripts are written using jython but it is arguably easier to create tests for non-standard protocols.
There is a commercial JMeter plugin which allows this, see:
http://www.ubik-ingenierie.com/blog/load-testing-java-serialization-applications-with-jmeter/
To make your tests realistic, you will need to variabilize content in the
serialized objects.
This Java Serialization plugin will allow the following:
Easy recording of traffic with JMeter Proxy Server, a Test Plan using
custom Sampler will be created
Easy variabilization of requests (which will appear as XML) through as
easy syntax as for example ${searchedWord} where searchedWord can come from
a CSV or any user defined variable.
Easy extraction of data from responses using JMeter standard Post
Processors
Easy debugging of Request/Responses through standard JMeter View Results
Tree element
Disclaimer : I am member of the company that distributes this solution

Categories

Resources