Created
December 1, 2013 02:13
-
-
Save vmi/7727779 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package firefoxtest; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebDriverCommandProcessor; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
public class FirefoxTest { | |
public void testNative(String url, String path, By by) { | |
System.out.println("###Native: " + url + path); | |
WebDriver driver = new FirefoxDriver(); | |
try { | |
driver.get(url + path); | |
Thread.sleep(1000); | |
WebElement e = driver.findElement(by); | |
e.click(); | |
Thread.sleep(1000); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} finally { | |
driver.quit(); | |
} | |
} | |
public void testWDCP(String url, String path, String locator) { | |
System.out.println("###WDCP: " + url + path); | |
WebDriver driver = new FirefoxDriver(); | |
try { | |
WebDriverCommandProcessor proc = new WebDriverCommandProcessor(url, driver); | |
proc.doCommand("open", new String[] { path }); | |
Thread.sleep(1000); | |
proc.doCommand("click", new String[] { locator }); | |
Thread.sleep(1000); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} finally { | |
driver.quit(); | |
} | |
} | |
public static void main(String[] args) { | |
FirefoxTest ft = new FirefoxTest(); | |
String url = "https://github.com"; | |
String path = "/"; | |
ft.testNative(url, path, By.linkText("Explore")); | |
ft.testWDCP(url, path, "link=Explore"); | |
String url2 = "https://www.google.com"; | |
String path2 = "/search?q=selenium&hl=en"; | |
ft.testNative(url2, path2, By.linkText("Images")); | |
ft.testWDCP(url2, path2, "link=Images"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment