The navigate
interface exposes the ability to move backwards and forwards in the browser’s
history.
Following
are the Browser Navigation Commands:
- Navigate To Command
- Forward Command
- Back Command
- 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:
Post a Comment