PAGE 6 : BROWSER NAVIGATION COMMANDS IN SELENIUM WEBDRIVER


The navigate interface exposes the ability to move backwards and forwards in the browser’s history.

Following are the Browser Navigation Commands:

  1. Navigate To Command
  2. Forward Command
  3. Back Command
  4. Refresh Command

package nc.com;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class NavigationCommands {
       WebDriver driver;

       @Test
       public void navigationCommand() {
              driver = new FirefoxDriver();

              String Url = "http://www.gmail.com";
              driver.get(Url);

/*navigate().forward() : Takes you forward by one page on the
browser’s history.driver.navigate().to(arg0): works same as driver.get();*/
              driver.navigate().forward();

              String Url2 = "http://facebook.com";
              driver.navigate().to(Url2);

// Go back to Home Page
              driver.navigate().back();

// Refresh browser
              driver.navigate().refresh();

// Close browser
              driver.close();

       }

}


Executing tests via TestNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Navigation Test Suite">
       <test name="navigation Test">
              <classes>
                     <class name="nc.com.NavigationCommands" />
              </classes>
       </test>
</suite>



Output:
===============================================
Navigation Test Suite
Total tests run: 1, Failures: 0, Skips: 0

===============================================

No comments:

About Me

My photo
Pune, Maharastra, India
You can reach me out at : jimmiamrit@gmail.com