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.
Related
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)
Sorry for this weird question.
Actually we go for selenium-webdriver to make manual test simpler,but what I felt is, for finding each and every webelement itself a hectic job. I actually do 'n' number of test to test my selenium code.
So, how can I make it simpler.
Thanks in advance!!
With my current experience with Selenium testing:
write your own methods
If you have repetitive sequences of actions to check something - pack it in your own methods like: find, click or find, get text attribute, assert if true etc.
make use of loops
Need to assert if text attribute is correct for N elements? Count number of elements, put your "testing" method inside loop for N repeats, compare against control-data stored in list/array etc.
use all what testing-framework can provide
In my case I test with the help of NUnit. If I have set of similar or even identical tests, why not to use [TestCase] instead of [Test]?
refactor / simplify
If you realize during or after test development that some parts of code are redundant - just replace them with corresponding methods you created instead. Code will get much shorter quickly and will be much easier to update if needed.
For me, the easiest way to find an element is by using css selectors. It is more natural and you can easily test your css selectors on chrome devtool by using the following construct like jquery, $('.classname').
BTW, I just created a small project to bootstrap a selenium project. You might want to check it out as it used shortcuts for selectors and I feel that it is more natural to have it that way, e.g. selector starts with '#' then us By.id, starts with '=', then use By.name.
Here's the project url: https://github.com/codezombies/easytest
You can use the tool fire-ie browser, this will help recognising elements without navigating to inspection page.
From below link, tool can be downloaded
http://toolsqa.com/selenium-webdriver/fire-ie-selenium-tool-ie-browser/
Another option is use Selenium IDE to identify the element. This is suggested option only for the non-technical users. Now Selenium IDE is available even on Chrome.
Selenium WebDriver is the most mainstream computerized test structure being utilized in programming improvement these days. Since it underpins all the principle programming dialects, for example, C#, Perl, Ruby, PHP, and JAVA, you have the opportunity to learn and make test code in any of these dialects. Selenium WebDriver+JAVA is the mix that is utilized the most. Obviously, information on HTML, javascript, and CSS is significant. Remember that an analyzer's employment is active. There will be numerous acceptable books on test mechanization. Nonetheless, the best preparation and range of abilities comes from dealing with genuine tasks.
Web advancement has expanded three-overlay contrasted and what it was years back. Various organizations are selecting to create sites to show their essence on the web. Also, testing is a significant piece of this web advancement measure. Concur? Obviously, it is. Most likely on that. In excess of a billion sites are live right now.
We see that various instruments are being delivered to assist with the turn of events and testing measures. On account of the web advancement specialists who are exploring and concocting good thoughts once in a while. You can discover various tooling alternatives on the lookout. Heaps of instruments are accessible to help you make your testing cycle simple and straightforward.
In a ton of testing instruments accessible out there, Selenium is perhaps the best device to date. The developing prominence of Selenium is a result of the wide scope of highlights that it offers. Selenium is open-source. You can download it liberated from cost. It is easy to comprehend and simple to utilize. With Selenium, you can play out your test on an assortment of programming dialects, for example, C#, Java, Python, etc, utilizing its Web Driver API. You can utilize it for mechanizing cell phones, including Android and iOS through Appium separated from for internet browsers.
Steps are as follows:
Choosing a Framework for Testing
How Do You Choose a Programming Language
Choosing a Unit Test Framework
Designing the Architecture of your Framework
Choose a Mechanism for Reporting
Building the “Selenium Test” Component
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.
I'm using intelliJ to write some java tests for an online client data management site. I'm just experimenting at the moment. I've managed to be able to check elements on a page and click links. I was just interested if anyone knows any other useful tests that I could run on the site?
I find that the best tests to do in selenium are the ones that automate interactivity. If it is a pretty standard, data only site, you can just check to make sure the site has working links and so on (there are other tools that do this online, so you may be wasting time using selenium for something so basic).
If you have an interactive web application, that's where selenium can help you to test various functionality.
I.e.
you can have a test case to check for logging in and logging out,
give the user different levels of access and see what they can see on
their screen.
Can they see administrative links?
What elements can
they see on certain pages?
Can they view other users on the system
(if this is an intranet, this might be useful)?
Can they edit these
fields (they shouldn't be able to, unless they are admin).
What
happens when an admin edits a field?
Does the site retrieve the new
value from the database or is the old value still persistant from the
database or cookies?
And so on...
There are a whole lot of tests to perform and they are very dependent on what you are programming and what you need to test. Instead of looking for selenium only tests, I would recommend you find a good book on best practices in software testing and try and learn the mindset instead of specific use cases.
Test I'm using:
login (form submission in general)
data retrieval and validation against db
accessing random links/sites and checking for errors
I'm really confused by the Selenium web site. At first they go to great lengths to explain Selenium IDE, but it outputs HTML test cases. But when you go to the Java documentation, it uses WebDriver which is pure java and your HTML test cases are useless. I found an export to JUnit feature from Selenium IDE but it doesn't use the WebDriver api, it wraps it inside the Selenium api, which doesn't even work. I get errors that I can only have one session at a time. I had only one test, made sure using netstat that I didn't have any other software listening on the port and disconnected the selenium instance. It just wouldn't work. Additionally the testcase extended from a deprecated class.
You cannot get back your test case to Selenium IDE from Java code so you can at that point throw the Selenium IDE away.
I converted the test case to pure WebDriver and I got it to work. So what is the recommended workflow for working with selenium and JUnit? Should I forget about Selenium IDE and recording actions in browser and just write everything in Java? Or is it still possible to use Selenium IDE somehow?
Having recently completed a project that used Selenium 2.0, I could find that the Selenium IDE is good only for prototying tests.
There are several drawbacks with the IDE that prevent it from being used to run Selenium tests. I could recall the following:
Typically you would want to run tests in a Suite. While the IDE does have this feature, I found that the IDE lacks a more important feature of running test setup and tear down scripts. This is trivial to achieve in JUnit/TestNG, but quite a pain with the recorded scripts in HTML. In short, the recorded tests aren't maintainable until you use a unit-testing library to run the tests from Java.
Data within the tests cannot be shared across tests; you will need to duplicate data in each test that requires it. This is expected when the tests are stored in a presentation language like HTML.
The default format of the exported tests does not use the page-object design pattern (which works very well for organizing Selenium tests). I didn't attempt creating my own format template for this, but this only convinced me that the best tests involving WebDriver and JUnit/TestNG are written by hand.
The optimal way of using the Selenium IDE is to create recordings of failed tests (by functional testers), instead of directly exporting the tests into your test suite. You could use the IDE to record the preliminary test so that the important aspects of the test (the assert/verify calls) are captured, and then rewrite it in your suite.
I use the IDE to create a "Work Flow Script", convert it into java code. Then I write everything from scratch in Java but with the info from the converted IDE script. That will have all ID's and so on but also in what order you have planned to "click" around, even some parts of it might be copied right off. Anyway it does speed things up a bit, but if you are using the webdriver it will complicate things a bit more and I have not yet moved over to the latest version.
Cheers
Stefan
The point is you can use either one, depending on your goal. In your case, WebDriver sounds like the way to go.
Selenium IDE is useful if you want to generate the HTML test cases.
Selenium WebDriver is useful for writing unit tests in Java (or other languages).
For a clear indication of this from the source, see the SeleniumHQ home page. It has a section on "Which part of Selenium is appropriate for me?", which answers your question.