java -cp "./bin;./lib/*" org.testng.TestNG testng1.xml testng2.xml testng3.xml
java -cp "./bin;./lib/*" org.testng.TestNG -testnames "SampleTest1" testng1.xml
"cp" above is setting classpath
driver.get("http://the-internet.herokuapp.com/basic_auth");
Thread.sleep(3000);
driver.switchTo().alert().sendKeys("admin" + Keys.TAB + "admin");
Thread.sleep(3000);
driver.switchTo().alert().accept();
Runtime.getRuntime().exec("Path to EXE File");
System.setProperty("webdriver.gecko.driver","C:\\Users\\Admin\\Documents\\Software\\geckodriver-v0.16.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https:## mail.google.com/mail/");
WebElement element = driver.findElement(By.id("identifierId"));
element.sendKeys("stavan2003");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
element = driver.findElement(By.id("identifierNext"));
element.click();
Thread.sleep(5000);
WebElement myDynamicElement = (new WebDriverWait(driver, 150)).until(ExpectedConditions.presenceOfElementLocated(By.name("password")));
element = driver.findElement(By.xpath(".## *[@id='password']/div[1]/div/div[1]/input"));
element.sendKeys("****");
element = driver.findElement(By.id("passwordNext"));
element.click();
driver.quit();
driver.get("http://the-internet.herokuapp.com/login");
driver.findElement(By.id("username")).sendKeys("tomsmith");
driver.findElement(By.id("password")).sendKeys("SuperSecretPassword!");
driver.findElement(By.xpath(".## *[@id='login']/button")).submit();
WebElement myDy = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".button.secondary.radius")));
System.out.println("Logout Located");
driver.findElement(By.cssSelector(".button.secondary.radius")).click();
driver.get("http://the-internet.herokuapp.com");
driver.findElement(By.linkText("Form Authentication")).click();
public static boolean isElementExisting(WebDriver driver, By by) {
boolean isExists = true;
try {
driver.findElement(by);
} catch (Exception e) {
isExists = false;
}
return isExists;
}
driver.get("http://the-internet.herokuapp.com");
List<WebElement> listofLinks = driver.findElements(By.tagName("a"));
for (WebElement link : listofLinks ){
System.out.println(link + " " + link.getAttribute("href") + " " + link.getText());
}
public static boolean isLinkWorking(WebDriver driver, String hrefString) throws Exception{
boolean isWorking = true;
URL url = new URL(hrefString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
String response = "";
try {
connection.connect();
response = connection.getResponseMessage();
System.out.println(response);
connection.disconnect();
} catch (Exception e){
isWorking = false;
}
return isWorking;
}
driver.get("http://the-internet.herokuapp.com/javascript_alerts");
driver.findElement(By.xpath("## button[@onclick='jsConfirm()']")).click();
driver.switchTo().alert().accept();
driver.switchTo().alert().dismiss();
driver.get("http://the-internet.herokuapp.com/javascript_alerts");
driver.findElement(By.xpath("## button[@onclick='jsPrompt()']")).click();
Alert prompt = driver.switchTo().alert();
prompt.sendKeys("This is Stavan");
prompt.accept();
driver.get("http://the-internet.herokuapp.com/windows");
String parentWindowHandler = driver.getWindowHandle();
driver.findElement(By.linkText("Click Here")).click();
driver.switchTo().window(parentWindowHandler).findElement(By.linkText("Click Here")).click();
driver.switchTo().window(parentWindowHandler).findElement(By.linkText("Click Here")).click();
System.out.println("No. of handles :"+ driver.getWindowHandles().size());
for(String handle : driver.getWindowHandles()){
System.out.println(handle);
driver.switchTo().window(handle);
driver.close();
}
driver.get("http://jqueryui.com/resources/demos/droppable/default.html");
WebElement drag = driver.findElement(By.id("draggable"));
WebElement drop = driver.findElement(By.id("droppable"));
Actions worker = new Actions(driver);
worker.dragAndDrop(drag, drop);
worker.perform();
driver.get("http://toolsqa.com/automation-practice-form/");
List<WebElement> checkboxes = driver.findElements(By.name("profession"));
for (WebElement checkbox : checkboxes) {
System.out.println("CheckBox :" + checkbox.getAttribute("value"));
System.out.println("Original State isSelected :" + checkbox.isSelected());
checkbox.click();
System.out.println("After click State isSelected :" + checkbox.isSelected());
}
driver.get("http://toolsqa.com/automation-practice-form/");
WebElement mySelectElement = driver.findElement(By.id("continents"));
Select dropdown = new Select(mySelectElement);
System.out.println("Is multiple Select Allowed : " + dropdown.isMultiple());
System.out.println("No. of elements in Drop Down :" + dropdown.getOptions().size());
dropdown.selectByVisibleText("South America");
for (WebElement menuItem : dropdown.getOptions()) {
System.out.println("Menu Item :" + menuItem.getText());
menuItem.click();
System.out.println("------------");
}
driver.get("http://toolsqa.com/automation-practice-form/");
List<WebElement> selectOptions = driver.findElements(By.cssSelector("#selenium_commands > option"));
for (WebElement ele : selectOptions){
System.out.println(ele.getText());
}
driver.quit();
driver.get("http://toolsqa.com/automation-practice-form/");
driver.findElement(By.linkText("Link Test")).click();
driver.navigate().back();
driver.navigate().forward();
driver.get("http://the-internet.herokuapp.com/infinite_scroll");
JavascriptExecutor jsx = (JavascriptExecutor)driver;
jsx.executeScript("window.scrollBy(0, 100)", "");
jsx.executeScript("alert('Hiiii')", "");
driver.get("http://toolsqa.com/automation-practice-form/");
driver.findElement(By.linkText("Link Test")).click();
WebDriverWait waiter = new WebDriverWait(driver, 10);
waiter.until(ExpectedConditions.titleContains("Demo Table for practicing"));
System.out.println(driver.getCurrentUrl());
driver.get("http://toolsqa.com/automation-practice-form/");
TakesScreenshot shot = (TakesScreenshot) driver;
byte[] output = shot.getScreenshotAs(OutputType.BYTES);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("error.jpg"));
out.write(output);
out.close();