List of usage examples for org.openqa.selenium WebDriver getWindowHandle
String getWindowHandle();
From source file:edu.umd.cs.guitar.model.WebWindowCreator.java
License:Open Source License
/** * Creates a new window for given web driver * @param parent WebDriver instance//from w w w.j a v a 2 s. co m * @param url Initial url to load * @return new WebWindow */ public WebWindowCreator(WebDriver parent, String url) { this.driver = parent; parentHandle = parent.getWindowHandle(); name = createUniqueName(); handle = createWindow(url); switchToWindow().get(url); }
From source file:edu.umd.cs.guitar.replayer2.WebReplayerMonitor2.java
License:Open Source License
/** * Get component using their GUI identification properties * <p>//from w w w .j a v a 2s . c om * * @return the component if found and null if not found */ @Override public GComponent getComponent(GApplication application, ComponentType window, ComponentType component) { if (!(application instanceof WebApplication)) throw new ReplayerConstructionException(); WebApplication webApplication = (WebApplication) application; WebDriver driver = webApplication.getDriver(); String xpathExpression = getXpathFromComponent(component); GUITARLog.log.debug("xPath Expression: " + xpathExpression); String currentHandler = driver.getWindowHandle(); driver.manage().timeouts().implicitlyWait(2000, TimeUnit.MILLISECONDS); // Scan all open window for the desired element for (String windowHandler : driver.getWindowHandles()) { try { driver.switchTo().window(windowHandler); if (isSearchWithinWindow) { ComponentType windowComponent = window; ComponentTypeWrapper windowComponentWrapper = new ComponentTypeWrapper(windowComponent); String windowTitle = windowComponentWrapper.getFirstValueByName(GUITARConstants.TITLE_TAG_NAME); windowTitle = normalizeURL(windowTitle); String url = driver.getCurrentUrl(); url = normalizeURL(url); if (!windowTitle.equals(url)) { continue; } } WebElement element = driver.findElement(By.xpath(xpathExpression)); GComponent webComponent = new WebComponent(element, null, null, null); GUITARLog.log.debug("Elemement FOUND in: " + driver.getCurrentUrl()); return webComponent; } catch (org.openqa.selenium.NoSuchElementException e) { GUITARLog.log.debug("Elemement NOT found in: " + driver.getCurrentUrl()); } } driver.switchTo().window(currentHandler); return null; }
From source file:edu.umd.cs.guitar.WebWindowManagerTest.java
License:Open Source License
@Test @Ignore//from www . j a va 2 s. co m public void testCreateWindow() { System.out.println("testCreateWindow"); WebDriver driver = new FirefoxDriver(); // driver.get("http://www.google.com/analytics/"); WebWindowManager wwh = WebWindowManager.getInstance(driver); System.out.println(driver.getWindowHandle()); wwh.createNewWindow("http://www.goolge.com"); wwh.createNewWindow("http://www.goolge.com/analytics"); System.out.println(driver.getWindowHandle()); }
From source file:fll.web.WebWindow.java
License:Open Source License
/** * Creates a new window for given web driver * /*from w w w .j av a2 s .co m*/ * @param parent WebDriver instance * @param url Initial url to load * @return new WebWindow */ public WebWindow(final WebDriver parent, final String url) { this.driver = parent; parentHandle = parent.getWindowHandle(); name = createUniqueName(); // sometimes this fails in tests, let's try a couple of times before we // error final int maxAttempts = 5; int attempt = 0; boolean done = false; while (!done) { try { handle = createWindow(url); // Switch to that window and load the url to wait switchToWindow().get(url); done = true; } catch (final WebDriverException e) { done = false; if (attempt >= maxAttempts) { throw e; } else { LOGGER.warn("Error creating web window, trying again. Attempt: " + attempt, e); } } ++attempt; } }
From source file:IWDmainsiteProject.PageObjects.Verify_Pages.java
public static void Verify_guides_button_b2b(WebDriver driver) { driver.findElement(By.cssSelector("div[class='demos-guides-link'] button[class='demos-guides-button']")) .click();/*w w w .jav a2 s . c om*/ String user_guide = driver.findElement(By.cssSelector( "li[class='link-button user-guide'] a[href='https://www.iwdagency.com/help/m2-b2b-suite/b2b-suite-2-settings']")) .getText(); System.out.println(user_guide); String expected_user_guide = "User Guide"; assertEquals(user_guide, expected_user_guide); System.out.println("user_guide is correct"); String installation_guide = driver.findElement(By.cssSelector( "li[class='link-button install-guide'] a[href='https://www.iwdagency.com/help/general-information/installing-iwd-extensions']")) .getText(); System.out.println(installation_guide); String expected_installation_guide = "Installation Guide"; assertEquals(installation_guide, expected_installation_guide); System.out.println("installation_guide is correct"); String homePage = driver.getWindowHandle(); driver.findElement(By.cssSelector( "li[class='link-button user-guide'] a[href='https://www.iwdagency.com/help/m2-b2b-suite/b2b-suite-2-settings']")) .click(); Set<String> windows = driver.getWindowHandles(); //System.out.println(windows.size()); Iterator iterator = windows.iterator(); String currentWindowId; while (iterator.hasNext()) { currentWindowId = iterator.next().toString(); //System.out.println(currentWindowId); if (!currentWindowId.equals(homePage)) { driver.switchTo().window(currentWindowId); String actualTitle = driver.getTitle(); System.out.println(actualTitle); String expectedTitle = "[M2] B2B Suite Settings - IWD Agency Support Center"; assertEquals(actualTitle, expectedTitle); System.out.println("Title of page is correct"); String b2b_suite_settings = driver.findElement(By.cssSelector(".header-title")).getText(); System.out.println(b2b_suite_settings); String expected_b2b_suite_settings = "[M2] B2B Suite Settings"; assertEquals(b2b_suite_settings, expected_b2b_suite_settings); System.out.println("[M2] B2B Suite Settings is correct"); driver.findElement(By.cssSelector("a[href='#DefaultSettings']")); driver.findElement(By.cssSelector("a[href='#Access']")); driver.findElement(By.cssSelector("a[href='#Registration']")); driver.findElement(By.cssSelector("a[href='#Requester']")); driver.findElement(By.cssSelector("a[href='#Notifications']")); driver.findElement(By.cssSelector("a[href='#Tables']")); driver.findElement(By.cssSelector("a[href='#Download']")); driver.findElement(By.cssSelector("a[href='#Order']")); driver.findElement(By.cssSelector("a[href='#Account']")); driver.findElement(By.cssSelector("a[href='#Credit']")); driver.findElement(By.cssSelector("a[href='#Guest']")); driver.findElement(By.cssSelector("a[href='#Matrix']")); driver.close(); driver.switchTo().window(homePage); driver.findElement(By.cssSelector("div[class=\"md-content es-wrapper\"] a[class=\"close\"]")) .click(); System.out.println("Test Verify_guides_button_b2b is done"); } } }
From source file:IWDmainsiteProject.PageObjects.Verify_Pages.java
public static void Verify_installation_guide_button_b2b(WebDriver driver) { String homePage2 = driver.getWindowHandle(); driver.findElement(By.cssSelector("div[class='demos-guides-link'] button[class='demos-guides-button']")) .click();//from ww w. ja v a 2 s.co m driver.findElement(By.cssSelector( "li[class='link-button install-guide'] a[href='https://www.iwdagency.com/help/general-information/installing-iwd-extensions']")) .click(); Set<String> windows2 = driver.getWindowHandles(); //System.out.println(windows.size()); Iterator iterator2 = windows2.iterator(); String currentWindowId2; while (iterator2.hasNext()) { currentWindowId2 = iterator2.next().toString(); //System.out.println(currentWindowId); if (!currentWindowId2.equals(homePage2)) { driver.switchTo().window(currentWindowId2); String actualtitle_Installing = driver.getTitle(); System.out.println(actualtitle_Installing); String expectedtitle_Installing = "Installing IWD Extensions - IWD Agency Support Center"; assertEquals(actualtitle_Installing, expectedtitle_Installing); System.out.println("Title of page Installing is correct"); String installing_iwd_extensions = driver.findElement(By.cssSelector(".header-title")).getText(); System.out.println(installing_iwd_extensions); String expected_installing_iwd_extensions = "Installing IWD Extensions"; assertEquals(installing_iwd_extensions, expected_installing_iwd_extensions); System.out.println("Installing IWD Extensions is correct"); driver.findElement(By.cssSelector("a[href='#MAGENTO 1 INSTALLATION']")); driver.findElement(By.cssSelector("a[href='#MAGENTO 2 INSTALLATION']")); driver.findElement(By.cssSelector("a[href='#ACTIVATING LICENSES']")); driver.findElement(By.cssSelector("a[href='/extensions/media/modules/m2/iwd_all.zip']")); driver.findElement(By.cssSelector("a[href='/extensions/downloadable/customer/products']")); driver.findElement(By .cssSelector("a[href='https://iwdagency.com/help/general-information/installing-iwd-all")); driver.close(); driver.switchTo().window(homePage2); driver.findElement(By.cssSelector("div[class=\"md-content es-wrapper\"] a[class=\"close\"]")) .click(); } } }
From source file:IWDmainsiteProject.PageObjects.Verify_Pages.java
public static void Verify_partner_program(WebDriver driver) { String homePage = driver.getWindowHandle(); footer.Click_on_partner_program(driver); System.out.println("click on partner_program is done"); Set<String> windows = driver.getWindowHandles(); Iterator iterator = windows.iterator(); String currentWindowId;//w w w .j a v a 2 s . com while (iterator.hasNext()) { currentWindowId = iterator.next().toString(); if (!currentWindowId.equals(homePage)) { driver.switchTo().window(currentWindowId); } } String actualTitle = driver.getTitle(); System.out.println(actualTitle); String expectedTitle = "IWD_Partner_Program.pdf"; assertEquals(expectedTitle, actualTitle); System.out.println("Title is correct"); String currentURL = driver.getCurrentUrl(); System.out.println(currentURL); String expectedcurrentURL = "https://www.iwdagency.com/extensions/IWD_Partner_Program.pdf"; assertEquals(currentURL, expectedcurrentURL); System.out.println("Link is correct https://www.iwdagency.com/extensions/IWD_Partner_Program.pdf"); driver.findElement(By.cssSelector(".textLayer")); System.out.println("PDF was found"); driver.close(); driver.switchTo().window(homePage); }
From source file:IWDmainsiteProject.PageObjects.Verify_Pages.java
public static void Verify_facebook(WebDriver driver) { String homePage = driver.getWindowHandle(); footer.Click_on_facebook(driver);/*from www . j ava 2 s . co m*/ Set<String> windows = driver.getWindowHandles(); Iterator iterator = windows.iterator(); String currentWindowId; while (iterator.hasNext()) { currentWindowId = iterator.next().toString(); if (!currentWindowId.equals(homePage)) { driver.switchTo().window(currentWindowId); } } String actualTitle = driver.getTitle(); System.out.println(actualTitle); String expectedTitle = "IWD Agency | Facebook"; assertEquals(expectedTitle, actualTitle); System.out.println("Title is correct"); String currentURL = driver.getCurrentUrl(); System.out.println(currentURL); String expectedcurrentURL = "https://www.facebook.com/iwdagency"; assertEquals(currentURL, expectedcurrentURL); System.out.println("Link is correct https://www.facebook.com/iwdagency"); driver.close(); driver.switchTo().window(homePage); }
From source file:IWDmainsiteProject.PageObjects.Verify_Pages.java
public static void Verify_google(WebDriver driver) { String homePage = driver.getWindowHandle(); footer.Click_on_google(driver);//from w w w . j av a 2 s . c o m Set<String> windows = driver.getWindowHandles(); Iterator iterator = windows.iterator(); String currentWindowId; while (iterator.hasNext()) { currentWindowId = iterator.next().toString(); if (!currentWindowId.equals(homePage)) { driver.switchTo().window(currentWindowId); } } String actualTitle = driver.getTitle(); System.out.println(actualTitle); String expectedTitle = "IWD Agency - Google+"; assertEquals(expectedTitle, actualTitle); System.out.println("Title is correct"); String currentURL = driver.getCurrentUrl(); System.out.println(currentURL); String expectedcurrentURL = "https://plus.google.com/+Interiorwebdesign"; assertEquals(currentURL, expectedcurrentURL); System.out.println("Link is correct https://plus.google.com/+Interiorwebdesign"); driver.close(); driver.switchTo().window(homePage); }
From source file:IWDmainsiteProject.PageObjects.Verify_Pages.java
public static void Verify_reviews(WebDriver driver) { String homePage = driver.getWindowHandle(); footer.Click_on_reviews(driver);/*from ww w. java 2 s. co m*/ Set<String> windows = driver.getWindowHandles(); Iterator iterator = windows.iterator(); String currentWindowId; while (iterator.hasNext()) { currentWindowId = iterator.next().toString(); if (!currentWindowId.equals(homePage)) { driver.switchTo().window(currentWindowId); } } String actualTitle = driver.getTitle(); System.out.println(actualTitle); String expectedTitle = "Customer Reviews"; assertEquals(expectedTitle, actualTitle); System.out.println("Title is correct"); String currentURL = driver.getCurrentUrl(); System.out.println(currentURL); String expectedcurrentURL = "https://www.iwdagency.com/reviews/"; assertEquals(currentURL, expectedcurrentURL); System.out.println("Link is correct https://www.iwdagency.com/reviews/"); driver.findElement(By.xpath("//p[contains(.,'IWD Agency Customer Reviews:')]")); driver.findElement(By.xpath("//span[contains(.,'Nothing but amazing!')]")); driver.findElement(By.xpath("//span[contains(.,'Stephanie Moody')]")); //Leave a review driver.findElement( By.cssSelector(".vc_general.vc_btn3.vc_btn3-size-lg.vc_btn3-shape-square.vc_btn3-style-custom")) .click(); String actual_leave_a_review = driver.findElement(By.cssSelector(".rwp-ratings-form-label")).getText(); System.out.println(actual_leave_a_review); String expected_leave_a_reviewe = "LEAVE A REVIEW"; assertEquals(expected_leave_a_reviewe, actual_leave_a_review); System.out.println("Leave a Review title is correct"); driver.findElement( By.cssSelector("div[class=\"rwp-rating-form-content rwp-no-avatar\"] input[placeholder=\"Name\"]")) .sendKeys("IWD Test Name"); driver.findElement(By.cssSelector( "div[class=\"rwp-rating-form-content rwp-no-avatar\"] input[placeholder=\"Review Title\"]")) .sendKeys("IWD Test Review Title"); driver.findElement(By.cssSelector( "div[class=\"rwp-rating-form-content rwp-no-avatar\"] textarea[placeholder=\"Write your review\"]")) .sendKeys("IWD Test Write your review"); String actual_rating = driver.findElement(By.cssSelector(".rwp-lab")).getText(); System.out.println(actual_rating); String expected_rating = "Rating:"; assertEquals(expected_rating, actual_rating); System.out.println("Rating: is correct"); driver.findElement(By.cssSelector( "div[class=\"rwp-stars\"] label[for=\"rwp-rating-1961-4b35bc789a120e0b49c7fcfba6d71488-9-141470591\"]")) .click(); //Make click for submit driver.findElement(By.cssSelector(".rwp-submit-wrap>input")); }