Quality Testing

Quality is delighting customers

Scenario: Google

1. Google website should get load

2. Print this URL---> Expected Result: www.google.com

3. Click on the Gmail link in a new tab

4. Print this URL---> Expected Result: www.gmail.com

Note:

Using without Arrays

Views: 581

Reply to This

Replies to This Discussion

@Test
public void openbrowser() throws InterruptedException {
WebDriver driver = new FirefoxDriver();

driver.manage().window().maximize();

driver.get("http://www.google.com");

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
//Go to URL
driver.get("http://gmail.com");

System.out.println(driver.getCurrentUrl());
//Set new tab timeout
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// Switch first tab
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "\t");
System.out.println(driver.getCurrentUrl());
driver.switchTo().defaultContent();
Thread.sleep(2000);

driver.close();
driver.quit();

}

}

Hi Ashish

Thanks for your reply ! But the thing is;

driver.get("http://gmail.com");

You are making the webdriver to open by passing gmail URL as a parameter. 

My scenario is from google page, webdriver needs to click on the gmail link in a new tab.

And then to print the Current URL of the new tab.

 

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class cURL {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.google.com");
System.out.println(driver.getCurrentUrl());

driver.manage().timeouts().implicitlyWait(600, TimeUnit.SECONDS);
driver.findElement(By.linkText("Gmail")).click();
System.out.println(driver.getCurrentUrl());

}
}

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;

import org.openqa.selenium.Keys;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.interactions.Actions;

public class OpenNewTab {

public static void main(String[] args) throws InterruptedException {

// TODO Auto-generated method stub

WebDriver driver = new FirefoxDriver();

driver.manage().window().maximize();

driver.get("http://www.google.com");

System.out.println(driver.getCurrentUrl());

driver.manage().timeouts().implicitlyWait(600, TimeUnit.SECONDS);

WebElement link = driver.findElement(By.linkText("Gmail"));

Actions newTab = new Actions(driver);

newTab.keyDown(Keys.COMMAND).keyDown(Keys.SHIFT).click(link).keyUp(Keys.COMMAND).keyUp(Keys.SHIFT).build().perform();

//ABOVE LINE IS FOR MAC-> AS THERE IS COMMAND USE FOR MAC AND CONTROL FOR WINDOWS-> REFER BELOW LINE CODE FOR WINDOWS OS USE

//newTab.keyDown(Keys.CONTROL).keyDown(Keys.SHIFT).click(link).keyUp(Keys.CONTROL).keyUp(Keys.SHIFT).build().perform();

Thread.sleep(10000);

//Using this locator we can directly click on gmail. if any confusion please let me know

System.out.println(driver.getCurrentUrl());

driver.close();

}

}

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2019   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service