top of page
Ravi Beck

10 coding watchouts for an Automation Developer - Part 4

Here's the continuation of previous blog

8. Assertions


Testing is all about validation and verification. While it is easier to find the elements or trigger actions, automation is complete only when the results of the action is verified.Asserts help to report if a test is pass or fail. And this can be achieved with a single line of code. Here is an example:public class ExampleAssertion { @Test public void assertionMethod(){ WebDriver driver = new ChromeDriver(); driver.get("http://www.google.com "); //Actual title is "Google" //We took title as "Yahoo" to make the test fail String title = "Yahoo"; String getTitle = driver.getTitle(); System.out.println("Assertion starts here..."); Assert.assertEquals(title, getTitle); driver.quit(); } } A test is considered successful only if it is completed without throwing any exception. If the assert condition is true then the program control will execute the next test step but if the condition is false, the execution will stop and further test step will not be executed.


9. Taking Screenshots of failed tests


An automated test may fail and quit and you can be lost in the exception stack trace trying to figure out the root cause. With automated tests, it can often be challenging to track down the exact issue that caused a failure. A simple way to gain insight into your test failures is to capture screenshots at the moment of failure. Generally, scripts fail in two conditions.

1-Script issue (some locator has been changed or application has some changes)- In this case, we need to modify our Selenium script as per the change in application.

2-Application issue- In this case, we need to inform to respective POC.


10. Cross Browser Testing


In today’s era, we have a wide variety of browsers out of which we always end up with the favourite one. So you might fail to check what the rest of the population is using to access a website.Whether you’re a developer, designer, or QA Engineer, you have to consider the countless methods end-users can utilize to interact with your website.Any website is made up of many different components and not all browser interpret those the same way. For example, JavaScript code can behave completely different in Internet Explorer 8 (if your web application runs on it ;)) than in more recent versions of Internet Explorer and Google Chrome.Because of these variations, the cross browser testing is a challenge and such an application should be tested separately on these browsers by using appropriate Selenium webdriver like InternetExplorerDriver, FirefoxDriver, ChromeDriver and ofcourse the headless browsers like HTMLUnit Browser.


To Conclude


There you have it! Working on Selenium WebDriver is really easy. I hope the automation test practices described above will be of help to you to achieve your automation goals.

9 views0 comments

Recent Posts

See All

Comments


bottom of page