By Arun Motoori
We’ve already discussed about this method in our earlier post Post # 41 Using getTitle( ) method. Go through the Post #41 and observe that we’ve used the JUnit method assertTrue( ) JUnit method to verify whether the the Selenium RC method getTitle( ) has retrieved the correct page Title. But now lets use the same getTitle( ) Selenium RC method with assertEquals( ) JUnit method to verify whether the the Selenium RC method getTitle( ) has retrieved the correct page Title.First lets find out what a Page Title is by following the below steps:1. Open http://www.Selenium143.blogspot.com2. View the title of the page as shown below:
3. So in the above screenshot, ‘Selenium143’ text displayed on the browser tab is the page title.Now lets use the Selenium RC method getTitle( ) to retrieve the title of the page.Syntax to be used:assertEquals(“Retrieved title is not the same “,”Selenium143”, selenium.getTitle( ));Test Description:Now lets use getTitle( ) method to retrieve the label of the page that is shown in the below screenshot:Lets Implement the Test on Eclipse IDE:Pre-requisites:1. Create a new Project say ‘RC-Project56’ in Eclipse IDE2. Configure the Project to work with Selenium RC3. Configure the Selenium Standalone Server to run from Eclipse IDE4. Create a package say ‘package56’ under the newly created project.5. Create a Java Class file say ‘Class56’ under the newly created package as shown below:
Actual Steps:1. Write the following code into the newly created Java Class file as shown below and make sure that you resolve all the errors before going to next step:
2. Create a test method ‘getTitleDemo()’ as shown below:
3. Use Selenium RC method getTitle( ) for retrieving the title of the website and use assertEquals( ) JUnit method for verifying whether the title retrieved using the getTitle( ) method is equal to the specified title as shown below:
4. Start the Selenium Standalone Server5. Save and Run the ‘Class56.java’ file by selecting the ‘JUnit Test’ option and ensure that our Automation Test has passed to confirm that the title of the page is equal to the title that is retrieved using the getTitle( ) Selenium RC method as shown in the below video:Watch the below video:Click here to watch the video.Download this Project:
Click here to download this project and import into Eclipse IDE on your machine. Please comment below to feedback or ask questions.
Using getText command will be explained in the next post.
Category: aafj. 140. Using getTitle Method