In this short blog, we will explore a rather unique and powerful framework for UI testing called Selenide. Some of you may think, the name is somewhat similar to Selenium and you are not wrong. We can say that selenide is a derivative of selenium. With this thought, let’s start our blog tutorial.
What is Selenide?
Selenide is a testing framework powered by the Selenium web driver. As the creators’ page says, it comes with powerful selectors, easy configuration, concise fluent API for tests, Ajax support for stable tests.
We can simply say that selenide is a wrapper upon selenium web driver itself. However, Selenide is developed by another project team, so it is obvious this software comes with different features compared to Selenium. It is maximally developed for creating scripts that can test the operation of web products: detecting the necessary web objects, checking the execution of events, working with the UI, and so on.
Now, let’s ask the question, why selenide?
Most of us have heard about Selenium WebDriver. Also, most of us already know that it is not easy to create your framework using selenium. Many people tend to give up on selenium because there is so much to learn and understand about it. Hence, we need a simple and easy alternative to it. Fortunately, I stumbled upon a selenium based framework called Selenide.
Since I already had some experience with selenium so I was intrigued to discover more about selenide. I found that selenide is much easier and this framework is quite easy and much faster to build as compared to selenium.
Anyone who is willing to put in some effort can prepare their own skeleton for writing automated test scripts using selenide and it will be faster than preparing the same skeleton with Selenium. If one already knows about selenium and has some hands-on experience with it, using selenide will be a piece of cake for you.
Before we move ahead with setting up selenide on a maven project, let’s compare selenide with selenium so that you may get an idea, why it is much easier.
Selenide Over Selenium
In selenide, drivers for the most commonly used browser are already bundled with it. You don’t need to configure drivers in selenide in that case, as we do in selenium. Let me give you an example.
In selenium, we need something like this for configuring the drivers.
System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver_linux64/chromedriver"); WebDriver driver = new ChromeDriver(option); driver.get("https://www.google.com/");
In selenide, we don’t need to do this. Instead of this, we can do a similar task by using,
open("https://www.google.com/"); // this will directly open up chrome browser.
If you need to use any other browser, use the code snipped mentioned below,
System.setProperty("webdriver.gecko.driver", "/path/to/geckoDriver"); System.setProperty("selenide.browser", "Firefox"); open("https://www.google.com/")
And that’s it, we don’t need to make an instance of a driver, simply use the open() method. Simple, right?
This is just the tip of the iceberg, we can do so much more and in a much easier way as compared to selenium. But before exploring more, let’s see the steps that we need to set up selenide.
The setup too is easy. We just need to add selenide’s dependency in our pom.xml and it is done.
<dependency> <groupId>com.codeborne</groupId> <artifactId>selenide</artifactId> <version>5.25.0</version> <scope>test</scope> </dependency>
You check for the latest version here. https://mvnrepository.com/artifact/com.codeborne/selenide
Simple, isn’t it?
What else selenide has to offer?
If you know the basics of jQuery it is will be much better to understand. If not, then you are in the same boat as me. I also didn’t have any clue about jQuery but this turned out pretty easy to understand.
Check out the table below, it contains the comparison between selenium and selenide based on finding out the elements.
I hope you got what I was trying to demonstrate here. Locating web elements has been made very easy in selenide.
Another aspect of selenium that was quite tricky is “waits“. However, selenide has made it quite simple to use. Let me give you an example of that as well.
In selenium, we used waits in the fashion mentioned below.
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until( ExpectedConditions.visibilityOfElementLocated(By.className("className")));
However, if you take a look at what selenide has reduced it to, you would be surprised.
I think this is self-explanatory. On top of these, let’s explore assertions as well.
In selenium, for assertion we used,
WebElement header = driver.findElement(By.tagName("h1")); assertEquals(“Header Text", header.getText());
In selenide, it is much much easier.
I hope, I was able to make my point.
In this blog, we have seen that why selenide is much easier than selenium. And it can be used both for beginners and advanced automation testers For anyone interested to start their journey with test automation I would highly recommend starting it with Selenide. Selenide provides readable, simple locators, built-in waits, readable methods and actions. To dive deeper, check out Selenide official website, https://selenide.org/.