As discussed in our previous post, the only difference between get( ) and navigate( ) commands is we can go backward and forward on our browser using navigate( ) command only.
In this post lets implement navigate( ).forward( ) command to navigate forward in our browser.
Syntax: _driver.navigate( ).forward( );
Test Description:
To move forward we have to move backward first.
So write automation code for moving backward first as shown below:
Automate all the below specified steps:
1. Open www.Selenium143.blogspot.com using get( ) or navigate( ).to( ) command
2. Click on 'What is Selenium?' link
3. When you are in the 'What is Selenium?' link page, use _driver.navigate( ).back( ) command to go back to your previous page i.e. www.Selenium143.blogspot.com page
4. Retrieve the page title using getTitle( ) to verify that you are in the www.Selenium143.blogspot.com page
Later write automation code for moving forward as shown below:
5. When you are in www.Selenium143.blogspot.com page , use _driver.navigate( ).forward( ) command for forward navigation in our browser
6. Retrieve the page title using getTitle( ) to verify that you are in the www.Selenium-by-arun.blogspot.com page
Lets Implement This:
Pre-requisites:
1. Create a new Java Project say 'WebDriver-Project55' in Eclipse IDE
2. Configure the Project to work with Selenium WebDriver
3. Create a package say 'package55' under the newly created project.
4. Create a Java Class file say 'Class55' 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. Write the test method 'navigateBack( )' to demonstrate how to use navigate( ).back( ) command as shown in the below screenshot:
3. Now write another test method 'navigateForward( )' to demonstrate how to use navigate( ).forward( ) command as shown in the below screenshot:
4. Save and Run the 'Class55.java' file by selecting the 'JUnit Test' option and ensure that our Automation Test has navigated backward and forward 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 sendKeys( ) command to browser a file will be explained in the next post.
No comments:
Post a Comment