Android apps to use in appium android test examples

Breaking

Friday, July 20, 2018

Handling Frames, Multiple Browsers, Mouse hover inward Selenium


Handling Frames, Multiple Browsers, Mouse hover inwards Selenium

Handling Frames

HTML Frames are used to dissever the Browser window into multiple sections, whenever nosotros access the page hence focus on the top window.

Operating Elements inwards Frames

1) Manual Testing:

You tin straight live elements inwards whatever frame of the Page.

2) Test Automation / Automated Testing:

Switch from Top window to especial frame hence live elements.
-------------------------------------
Example:

Launch Web Page (It has iii frames)

i) Click tertiary link inwards tertiary frame
ii) Click 2d Link inwards 1st Frame
iii) Click 1st Link inwards 2d frame
------------------------------------------
Test Automation:

a) Launch the spider web page
b) Switch to tertiary frame too live the element
c) Switch to Top window
d) Switch to 1st frame too live the element
e) Switch to Top window
f) Switch to 2d frame too live the element
-------------------------------------
Switch from Top window to a frame is done inwards 2 ways

i) Using Frame Index

Syntax:

driver.switchTo().frame(int index);

Example:

WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
driver.switchTo().frame(2);
driver.findElement(By.xpath("html/body/div[3]/table/tbody[2]/tr[5]/td[1]/a")).click();
-------------------------------------
ii) Using Frame Name

Syntax:
driver.switchTo().frame(String Name);



Example:

WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");
driver.switchTo().frame("classFrame");
driver.findElement(By.xpath("html/body/div[3]/table/tbody[2]/tr[5]/td[1]/a")).click();
--------------------------------------------------------
From a frame to Top window

Syntax:

driver.switchTo().defaultContent();
------------------------------------------
Handling Frames Example:
> Launch the Web Page
> Switch to tertiary Frame
> Operate an Element
> Back to Top Window
> Switch to 1st Frame
> Operate an Element
----------------------------------
a) Example using Frame Name

WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");

//Switch from Top window to tertiary Frame using Frame name
driver.switchTo().frame("classFrame");
driver.findElement(By.linkText("org.openqa.selenium")).click();
Thread.sleep(3000);
//Back to Top window
driver.switchTo().defaultContent();
Thread.sleep(3000);
//Switch from Top window to 1st Frame using Frame name
driver.switchTo().frame("packageListFrame");
driver.findElement(By.linkText("org.openqa.selenium.io")).click();
--------------------------------------------------------------
b) Example using Frame Index

WebDriver driver = novel FirefoxDriver();
driver.get("http://seleniumhq.github.io/selenium/docs/api/java/index.html");

//Switch from Top window to tertiary Frame using Frame name
driver.switchTo().frame(2);
driver.findElement(By.linkText("org.openqa.selenium")).click();
Thread.sleep(3000);
//Back to Top window
driver.switchTo().defaultContent();
Thread.sleep(3000);
//Switch from Top window to 1st Frame using Frame name
driver.switchTo().frame(0);
driver.findElement(By.linkText("org.openqa.selenium.io")).click();
driver.switchTo().defaultContent();
Thread.sleep(3000);
driver.navigate().back();
driver.switchTo().frame(1);
driver.findElement(By.linkText("Action")).click();
-------------------------------------
Handling Mouse hover
 

WebDriver driver = novel FirefoxDriver();
driver.get("https://www.carmax.com");

//Create Actions Instance past times Passing the driver reference
Actions builder = novel Actions(driver);

WebElement carte du jour = driver.findElement(By.linkText("FIND YOUR CAR"));

builder.moveToElement(menu).build().perform();
driver.findElement(By.linkText("Transfers")).click();
-------------------------------------
Handling Multiple Browsers
 

We handgrip multiple browsers using Browser Window handles.

Example 1:

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> Browsers = driver.getWindowHandles();   
System.out.println(Browsers.size());   
   
for (String i : Browsers){
if (! i.equals(parent)){
    driver.switchTo().window(i);
    System.out.println(driver.getCurrentUrl());
}
}
driver.switchTo().window(parent);
System.out.println(driver.getCurrentUrl());
-------------------------------------
Example 2:
 

> Launch the Web Page
> Click Sign In Link (It opens novel window)
> Enter to a greater extent than or less value into Login Username Edit box inwards 1st browser
> Enter to a greater extent than or less value into Enter Your details edit box inwards 2d browser
------------------------------------------------------

Selenium WebDriver Test Script/Program

WebDriver driver = novel FirefoxDriver();
driver.get("file:///E:/HTMLExamples/LoginPage.html");

driver.findElement(By.linkText("Sign In")).click();

driver.findElement(By.id("username")).sendKeys("India123");
Thread.sleep(3000);
String Browser1 = driver.getWindowHandle();

Set <String> Browsers = driver.getWindowHandles();

for (String windowHandle: Browsers){
if (!windowHandle.equals(Browser1)){
driver.switchTo().window(windowHandle);
driver.findElement(By.xpath(".//*[@id='signin']")).sendKeys("Selenium Testing");
}
}
Thread.sleep(3000);
driver.switchTo().window(Browser1);
driver.findElement(By.id("pass word")).sendKeys("abcd123");
}
}
-----------------------------------------------------------------

Sumber http://www.gcreddy.com/

No comments:

Post a Comment