public static void main(String[] args) { String baseUrl = "http://newtours.demoaut.com/"; WebDriver driver = new FirefoxDriver(); String underConsTitle = "Under Construction: Mercury Tours"; // Creates result string driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get(baseUrl); List<WebElement> linkElements = driver.findElements(By.tagName("a")); // Creates lists from <a> tags String[] linkTexts = new String[linkElements.size()]; int i = 0; // extract the link texts of each link element for (WebElement e : linkElements) { linkTexts[i] = e.getText(); i++; } // test each link by looping over them for (String t : linkTexts) { driver.findElement(By.linkText(t)).click(); if (driver.getTitle().equals(underConsTitle)) { System.out.println("\"" + t + "\"" + " is under construction."); } else { System.out.println( "\"" + t + "\"" // print results to console + " is working."); } driver.navigate().back(); } driver.quit(); }
@Parameters({"useCloudEnv", "userName", "key", "os", "browser", "browserVersion", "url"}) @BeforeMethod public void setUp( @Optional("false") Boolean useCloudEnv, @Optional("rashed1") String userName, @Optional("2601a7b6-4b39-4712-992a-59ddcd85694c") String key, @Optional("Windows 10") String OS, @Optional("firefox") String browser, @Optional("43.0.1") String browserVersion, @Optional("http://www.cigna.com") String url) throws IOException { if (useCloudEnv == true) { // run on cloud logger.setLevel(Level.INFO); logger.info("Test is running on cloud env"); getCloudDriver(userName, key, OS, browser, browserVersion); System.out.println("Tests is running on Saucelabs, please wait for result"); } else { // run on local getLocalDriver(OS, browser, browserVersion); } driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.navigate().to(url); driver.manage().window().maximize(); }
private void login(String user, String passwd) { String loginLink = "http://www.orange-scene.dk/typo3"; System.out.println("Opening: " + loginLink); driver.navigate().to(loginLink); waitForElementFound(new By.ById("username")).sendKeys(user); driver.findElement(new By.ById("password")).sendKeys(passwd); driver.findElement(new By.ByName("loginform")).submit(); selenium.waitForPageToLoad("30000"); captureScreenshot(); }
public static void main(String args[]) throws InterruptedException { ProfilesIni profile = new ProfilesIni(); FirefoxProfile ffprofile = profile.getProfile("default"); WebDriver driver = new FirefoxDriver(ffprofile); driver.get("http://csgorage.com/free-raffles/current"); List<WebElement> raffleDivs = driver.findElements(By.cssSelector("" + ".raffle_box_lg")); for (int i = 0; i < raffleDivs.size(); i++) { raffleDivs.get(i).findElement(By.cssSelector("a")).click(); int timer = 20; int currentTime = 0; JavascriptExecutor js = (JavascriptExecutor) driver; do { js.executeScript("window.scrollBy(0,250)", ""); Thread.sleep(5000); currentTime++; } while (currentTime < timer); itemEntry(driver); driver.navigate().back(); raffleDivs = driver.findElements(By.cssSelector("" + ".raffle_box_lg")); } }
@Parameters({"useSauceLab", "userName", "key", "appUrl", "os", "browserName", "browserVersion"}) @BeforeMethod public void setUp( boolean useSauceLab, String userName, String key, String appUrl, String os, String browserName, String browserVersion) throws IOException { if (useSauceLab == true) { getSauceLabDriver(userName, key, os, browserName, browserVersion); } else { getLocalDriver(os, browserName); } driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.navigate().to(appUrl); driver.manage().window().maximize(); }
public void navigateForward() { driver.navigate().forward(); }
public void navigateBack() { driver.navigate().back(); }
@Parameters("browser") @BeforeTest public void launchapp(String browser) throws MalformedURLException { String URL = "http://social.ravabe.com/"; if (browser.equalsIgnoreCase("firefox")) { System.out.println(" Executing on FireFox"); String Node = "http://localhost:5555/wd/hub"; // String Node1="http://192.168.137.172:5556/wd/hub"; DesiredCapabilities cap = DesiredCapabilities.firefox(); cap.setBrowserName("firefox"); driver = new RemoteWebDriver(new URL(Node), cap); // driver1=new RemoteWebDriver(new URL(Node1), cap); // Puts an Implicit wait, Will wait for 10 seconds before throwing exception driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // driver1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Launch website driver.navigate().to(URL); // driver1.navigate().to(URL); driver.manage().window().maximize(); // driver1.manage().window().maximize(); } /* else if(browser.equalsIgnoreCase("firefox1")) { System.out.println(" Executing on FireFox"); String Node1 = "http://localhost:5556/wd/hub"; DesiredCapabilities cap1 = DesiredCapabilities.firefox(); cap1.setBrowserName("firefox"); driver1 = new RemoteWebDriver(new URL(Node1), cap1); driver1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver1.navigate().to(URL); driver1.manage().window().maximize(); }*/ else if (browser.equalsIgnoreCase("chrome")) { System.out.println(" Executing on CHROME"); DesiredCapabilities cap = DesiredCapabilities.chrome(); cap.setBrowserName("chrome"); String Node = "http://localhost:5557/wd/hub"; // String Node1="http://192.168.137.172:5560/wd/hub"; driver = new RemoteWebDriver(new URL(Node), cap); // driver1 = new RemoteWebDriver(new URL(Node1), cap); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // driver1.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Launch website driver.navigate().to(URL); // driver1.navigate().to(URL); driver.manage().window().maximize(); // driver1.manage().window().maximize(); } /* else if (browser.equalsIgnoreCase("ie")) { System.out.println(" Executing on IE"); DesiredCapabilities cap = DesiredCapabilities.chrome(); cap.setBrowserName("ie"); String Node = "http://localhost:5558/wd/hub"; driver = new RemoteWebDriver(new URL(Node), cap); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); // Launch website driver.navigate().to(URL); driver.manage().window().maximize(); }*/ else { throw new IllegalArgumentException("The Browser Type is Undefined"); } }