What are some useful tests to do in selenium? - java

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

Related

User-friendly migration of data between instances of an application

We have a web-based system that is essentially a survey application.
Up until now we've been loading new surveys in directly into the database (as flyway migrations). This is obviously not tenable long-term, and we need to put the power to create new surveys into the hands of the admin users. One aspect of this is adding the UI so that admin users can create new surveys.
However, we want the admin users to create and test any new surveys in a test environment first before letting it loose in production. As these surveys are complex, there is a real risk that a survey that is setup in a test environment is subtly different from how someone does the setup in the production environment. My aim is to remove this risk.
My question pertains to the technical mechanism(s) we could implement so that the admin users can, on a self-service basis, "migrate" surveys from their test environment (where they've done all of their testing and verification) to the production environment - such that we have a high confidence that the migrated survey(s) will be setup identically. Applications like Moodle already have this sort of functionality built-in.
I've considered:
Allowing users to create a checksum of a survey (perhaps based on the hashcode of all the elements) so they can know that the surveys across the two environments are identical. The issue then is that it would be annoying to try and find the exact difference between the surveys on the two instances.
Writing a UI that dumps raw SQL as the export and allowing these users to just splatting it into the production database, but it's incredibly bad from so many perspectives
Constructing our own domain-specific language that describes these surveys - but writing an input/output parser just seems so complex
Dumping the data to JSON (given that it's a RESTful web app, most of this is already done) and sucking it back in
At this stage, I'm leaning towards the JSON method, but would be keen to hear any other ideas or libraries that we could easily integrate into a Spring Boot app that would assist with this process.
To be honest, solving that kind of problem by introducing independent instances sounds like a terrible idea: Not only the migration part is tricky. You will have to ensure compatibility at all times. Imagine an admin uses an outdated version or does not configure his instance correctly (every admin's dream). Even if the migration itself produces no errors the results may be different in the end (and that's what you actually want to avoid).
As I understand it, you currently look at a survey as a bulk of raw information that somehow appears in your database and then gets displayed by the application. From that point of view you obviously can't tell the difference between a test survey and a production survey.
That's why you really should extend your model!
There is much more than just a survey. There is a survey draft and/or a survey preview area, a survey creation process that users go through, a process that spins of a production survey from a draft, etc.
If you add those concepts to your application a use case like the one you described should be easy to implement (you already mentioned a planned UI, right?).
Hope I could help you. Sorry, I know it doesn't exactly answer your question.

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.

how to form a framework in selenium driver for web automation where by just passing some metadata, the entire code must be generated

I need knowledge about how to develop a framework for web automation using selenium webdriver. please give me ideas and steps to create framework.
Now I'm able to locate all the web elements on web application by just writing a one big bunch of TestNG test code by using #Test annotation.
In my web application there are many places where I can reuse the code to do the same operation across all. So help me out to develop a best framework.
It depends on the problems you are facing.
If you want to clearly separate writing scenarios from editing the logic (for instance, you work in a team with testers who aren't software engineers but know Java and algorithmic well enough to construct elaborate scenarios from small building blocks), then it would be wise to introduce a layer of steps classes containing methods like openTheUserMenu(), fillTheFormDetails(String name, String surname, String address) etc.
If you write tests for some dynamically changing or developing project with UI elements changed or refactored often you would definitely need Page Object pattern to encapsulate the UI logic (so that in your steps you would write just mainPage.selectDateOnCalendar(Date date), and all the necessary typing and clicking would be written out in the page's method).
Finally, if you work closely with your client and need to formulate the requirements in natural language first, and then translate them into more formalized language for developers to implement the required functionality, you would need to use BDD and appropriate libraries like JBehave with scenarios written in phrases in high-level almost natural language mapped onto test methods in Java.
In short, this is it. If you want details, there are plenty of materials on the Net as was mentioned already. Just remember - you should invest in elaborate framework only if you really need one to solve the problems you are facing.

How to make Selenium automation simple?

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

Use Selenium RC directly or Selenium with Robot framework

I have to admit that I fell in love with Selenium for its record-and-play feature as well as the testcase generation functionality for those recorded actions from the IDE. But I am still hesitated to advance to the implementation stage because of the incidental details (e.g, locating the events with DOM, xpath..etc) that are built into the testcase during the recording, which could make the testcase failure prone whenever there is a html change once it's imported to the RC. I fully understand that it's a part of testers' jobs to adjust the expected results from time to time as part of the regression test, but I also do not wish the time spent on this is larger than the time that takes to do the manual test.
As far as I know Selenium with Robot framework has the keywords form of testcases. My guess is it allows us to extract the incidental details into various keywords, which could make the testcases being adjusted easier and are more maintainable. (Please correct me if I am wrong)
It will be appreciated to hear suggestions on how an effective UI automation environment should be setup. Should I just use Selenium RC or Selenium with Robot framework? And why?
Thanks in advance
You are absolutely right that incidental and often changing details in the produced scripts is the biggest problem of record-and-playback automation. You can obviously remove the details from the scripts after recording, but in my opinion it's better to build reusable libraries and code scripts manually from the start.
A good alternative for coding scripts using "real" programming languages is using some higher level automation framework such as Robot Framework that you mentioned. As you speculated, Robot's reusable keywords and also variables make extracting details away from tests very easy. The test cases in SeleniumLibrary's demo illustrates this very well and the demo also shows how to use Selenium through Robot.
You also asked about Sikuli. I've never used it myself but it sure looks interesting. You might be interested on this great how-to that explains how to use it through Robot Framework.
Our company is using Fitnesse, not Robot, to control Selenium however, we have the same problem. We switched from making assumptions about the DOM to only accessing elements by ID. Since this is cumbersome in Fitnesse we are currently working to add a Selenium backend to our own Framework (which previously only had backends for Java and Smalltalk).
So, by requiring that elements with certain ID's are present in the DOM we will of course break our tests if someone removes the elements from the page; however, we found that this behavious is very useful as this enforces the contract the tests made with the implementation and it is a good thing we find missing elements as soon as someone broke the implementation.
In addition, it is good practice to keep UI automation skin-deep: Only test what is present on the page with Selenium and test the business-logic by calling the underlying functions directly.

Categories

Resources