324. Refactoring the Selenium Automation code to make it readable

Till now we've Refactored the code by:

1. Increasing the @Test Annotation methods to hold the single Tests (i.e. Now allowing @Test Annotation method to have more than one Test)

2. Using @BeforeClass and @AfterClass JUnit instead of @Before and @After Annotation to reduce the execution time or to reduce the number of the times the same code under the @Before and @After JUnit annotations is executed.

Now, we are going to Refactor the Selenium Automation Code by making it readable:

1. Lets view the current code containing few things that are not readable as shown below:

2. Now lets change the 'setUp( )' method to 'openChapterOnePageInFirefoxBrowserAndMaximize( )' to make it more readable as shown below:

3. Now lets change the 'testMethod1( )' to 'assertThatSeleniumBeginnersGuidePageHeadingIsPresent( )' to make it more readable as shown below:

4. In the similar manner lets change the method names of the remaining test methods as shown below:

5. Finally, lets change the 'tearDown( )' method to readable method name 'closeBrowser( )' as shown below:

6. Now have a look at the complete code and observe that the code is readable now as shown below:

7. Save and Run the '' file by selecting the 'JUnit Test' option

8. Observe that the Test got passed as shown below:

Download this Project:

Click here to download this project and import into Eclipse IDE  on your machine.

Thats it, we're done Refactoring the Selenium Automation code. 

Please comment below to feedback or ask questions.

Upgrading Selenium WebDriver will be explained in the next post.

No comments: