Handling Browser inwards Selenium WebDriver
• Selenium automates browsers. Primarily, it is for automating spider web applications for testing purposes, but non express to simply that, Web-based direction tasks tin laissez passer notice besides hold upward automated equally well.
• Selenium Supports all pop browsers (Google Chrome, IE, Mozilla Firefox, Opera, Safar etc...) to practise together with execute Test cases.
• Test Cases / Test Scripts are same for all browsers, but Browser driver varies from 1 browser to another,
• If yous desire to practise together with execute a Test illustration using Firefox browser together with thence practise Frefox browser, if desire to work Google Chrome browser together with thence practise Chrome browser.
• You practise Test cases using whatever 1 the browsers(ex: Firefox) together with execute them using all browsers(Ex: IE, Chrome, Firefox etc...).
Note: Mozilla Firefox is default browser inwards Selenium,
• By default, Firefox driver comes alongside selenium-serverstanalone.jar library added.
• For Chrome, IE, Safari, Opera, at that topographic point are libraries that demand to hold upward instantiated externally.
Creating Mozill Firefox Browser Object
WebDriver driver = novel FirefoxDriver();
Create Google Chrome Browser
System.setproperty("webdriver.chrome.driver", "driver .exe file path");
WebDriver driverName = novel ChromeDriver();
Create Internet Explorer Browser
System.setproperty("webdriver.ie.driver", "driver .exe file path");
WebDriver driverName = novel InternetExplorerDriver();
Handling Browser
Operations on Browser
• Launch Browser
• Navigate to specified URL
• Return Current URL
• Return Page Title
• Return Window Handle
• Close focused Browser
• Close all browsers that opened past times WebDriver during execution
-----------------------
• Navigate to roughly other URL
• Navigate dorsum to previous URL
• Navigate forward
• Refresh the Browser
• Maximize the Browser window
--------------
• minimize the Browser Window
Selenium WebDrivers Test Steps:
// Launch Browser
WebDriver driver = novel FirefoxDriver();
// Navigate to specified URL
driver.get("https://www.google.co.in");
//Return Current Page Title
String PageTitle = driver.getTitle();
System.out.println(PageTitle);
//Return Current URL
String URL = driver.getCurrentUrl();
System.out.println(URL);
// Return Page Source
String PageSource = driver.getPageSource();
System.out.println(PageSource);
//Return Browser Window Handle
String WindowHandle = driver.getWindowHandle();
System.out.println(WindowHandle);
// Navigate to specified URL
driver.navigate().to("https://login.yahoo.com/");
// Navigate dorsum to previous URL
driver.navigate().back();
// Navigate 1 exceptional forwards inwards the Browser History
driver.navigate().forward();
//Miximize the Browser Window
driver.manage().window().maximize();
// Browser Full Screen
driver.manage().window().fullscreen();
// Refresh the Browser
driver.navigate().refresh();
// Close the Focused Browser
driver.close();
// Close all Browsers that opened past times Selenium WebDriver during Execution
driver.quit();
// Working alongside multiple Browsers
WebDriver driver = novel FirefoxDriver();
driver.get("file:///E:/HTMLExamples/LoginPage.html");
String raise = driver.getWindowHandle();
//System.out.println(parent);
driver.findElement(By.linkText("Sign In")).click();
Set <String> Handles = driver.getWindowHandles();
int BrowserCount = Handles.size();
System.out.println(BrowserCount);
for (String s1:Handles){
if (! s1.equals(parent)){
driver.switchTo().window(s1);
System.out.println(driver.getCurrentUrl());
}
}
driver.switchTo().window(parent);
System.out.println(driver.getCurrentUrl());
}
}
-----------------------------------------------------------------
Sumber http://www.gcreddy.com/
• Selenium automates browsers. Primarily, it is for automating spider web applications for testing purposes, but non express to simply that, Web-based direction tasks tin laissez passer notice besides hold upward automated equally well.
• Selenium Supports all pop browsers (Google Chrome, IE, Mozilla Firefox, Opera, Safar etc...) to practise together with execute Test cases.
• Test Cases / Test Scripts are same for all browsers, but Browser driver varies from 1 browser to another,
• If yous desire to practise together with execute a Test illustration using Firefox browser together with thence practise Frefox browser, if desire to work Google Chrome browser together with thence practise Chrome browser.
• You practise Test cases using whatever 1 the browsers(ex: Firefox) together with execute them using all browsers(Ex: IE, Chrome, Firefox etc...).
Note: Mozilla Firefox is default browser inwards Selenium,
• By default, Firefox driver comes alongside selenium-serverstanalone.jar library added.
• For Chrome, IE, Safari, Opera, at that topographic point are libraries that demand to hold upward instantiated externally.
Creating Mozill Firefox Browser Object
WebDriver driver = novel FirefoxDriver();
Create Google Chrome Browser
System.setproperty("webdriver.chrome.driver", "driver .exe file path");
WebDriver driverName = novel ChromeDriver();
Create Internet Explorer Browser
System.setproperty("webdriver.ie.driver", "driver .exe file path");
WebDriver driverName = novel InternetExplorerDriver();
Handling Browser
Operations on Browser
• Launch Browser
• Navigate to specified URL
• Return Current URL
• Return Page Title
• Return Window Handle
• Close focused Browser
• Close all browsers that opened past times WebDriver during execution
-----------------------
• Navigate to roughly other URL
• Navigate dorsum to previous URL
• Navigate forward
• Refresh the Browser
• Maximize the Browser window
--------------
• minimize the Browser Window
Selenium WebDrivers Test Steps:
// Launch Browser
WebDriver driver = novel FirefoxDriver();
// Navigate to specified URL
driver.get("https://www.google.co.in");
//Return Current Page Title
String PageTitle = driver.getTitle();
System.out.println(PageTitle);
//Return Current URL
String URL = driver.getCurrentUrl();
System.out.println(URL);
// Return Page Source
String PageSource = driver.getPageSource();
System.out.println(PageSource);
//Return Browser Window Handle
String WindowHandle = driver.getWindowHandle();
System.out.println(WindowHandle);
// Navigate to specified URL
driver.navigate().to("https://login.yahoo.com/");
// Navigate dorsum to previous URL
driver.navigate().back();
// Navigate 1 exceptional forwards inwards the Browser History
driver.navigate().forward();
//Miximize the Browser Window
driver.manage().window().maximize();
// Browser Full Screen
driver.manage().window().fullscreen();
// Refresh the Browser
driver.navigate().refresh();
// Close the Focused Browser
driver.close();
// Close all Browsers that opened past times Selenium WebDriver during Execution
driver.quit();
// Working alongside multiple Browsers
WebDriver driver = novel FirefoxDriver();
driver.get("file:///E:/HTMLExamples/LoginPage.html");
String raise = driver.getWindowHandle();
//System.out.println(parent);
driver.findElement(By.linkText("Sign In")).click();
Set <String> Handles = driver.getWindowHandles();
int BrowserCount = Handles.size();
System.out.println(BrowserCount);
for (String s1:Handles){
if (! s1.equals(parent)){
driver.switchTo().window(s1);
System.out.println(driver.getCurrentUrl());
}
}
driver.switchTo().window(parent);
System.out.println(driver.getCurrentUrl());
}
}
-----------------------------------------------------------------