Wednesday, April 20, 2016

UI Test Automation



Selenium
WebElement gmailLink = driver.findElement(By.linkText("GMail"));
WebElement username = driver.findElement(By.id("username"));

// Enter something to search for
element.sendKeys("Selenium testing tools cookbook");

// Now submit the form. WebDriver will find
// the form for us from the element
element.submit();

color.selectByVisibleText("Black");
color.deselectByVisibleText("Black");

double-click:
WebElement message = driver.findElement(By.id("message"));

// Verify color is Blue
assertEquals("rgba(0, 0, 255, 1)",
    message.getCssValue("background-color"));

Actions builder = new Actions(driver);
builder.doubleClick(message).perform();

// Get the search textbox
  WebElement searchField = driver.findElement(By.name("q"));
searchField.clear();

// Enter search keyword and submit
searchField.sendKeys("selenium webdriver");
searchField.submit();

browser navigation
WebElement resultLink = driver.findElement(By.linkText("Selenium WebDriver"));
resultLink.click();

new WebDriverWait(driver, 10).until(ExpectedConditions
    .titleIs("Selenium WebDriver"));

assertEquals("Selenium WebDriver", driver.getTitle());

driver.navigate().back();

new WebDriverWait(driver, 10).until(ExpectedConditions
    .titleIs("selenium webdriver - Google Search"));

assertEquals("selenium webdriver - Google Search", driver.getTitle());

driver.navigate().forward();

alert box:
driver.findElement(By.id("simple")).click();

// Optionally we can also wait for an Alert box using the WebDriverWait
new WebDriverWait(driver, 10)
    .until(ExpectedConditions.alertIsPresent());

// Get the Alert
Alert alert = driver.switchTo().alert();

// Get the text displayed on Alert
String textOnAlert = alert.getText();

// Check correct message is displayed to the user on Alert box
assertEquals("Hello! I am an alert box!", textOnAlert);

// Click OK button, by calling accept method
alert.accept();

// Enter some value on Prompt Alert box
alert.sendKeys("Foo");

// Click OK button, by calling accept method
alert.accept();

Pop-up window
// There is no name or title provided for Chat Page window
// We will iterate through all the open windows
// and check the contents to find out if it's Chat window
try {
  for (String windowId : driver.getWindowHandles()) {
    driver.switchTo().window(windowId);

    // We will use the page source to check the contents
    String pageSource = driver.getPageSource();

    if (pageSource.contains("Configuration - Online Chat")) {

      // Check the page for an element displaying a expected
      // message
      assertTrue(driver.findElement(By.tagName("p")).getText()
          .equals("Wait while we connect you to Chat..."));

      // Find the Close Button on Chat Window and close the window
      // by clicking Close Button
      driver.findElement(By.id("closebutton")).click();
      break;
    }
  }
} finally {
  // Switch back to the parent browser window
  driver.switchTo().window(currentWindowId);
}

https://sites.google.com/a/chromium.org/chromedriver/
WebDriver is an open source tool for automated testing of webapps across many browsers. It provides capabilities for navigating to web pages, user input, JavaScript execution, and more.  ChromeDriver is a standalone server which implements WebDriver's wire protocol for Chromium. ChromeDriver is available for Chrome on Android and Chrome on Desktop (Mac, Linux, Windows and ChromeOS).  

We can also specify a path externally through the –Dwebdriver.chrome.driver option using Maven command line options

https://www.simple-talk.com/dotnet/asp.net/getting-started-with-ui-test-automation/
https://www.ravellosystems.com/blog/review-5-modern-test-tools-ui/
public void test01() throws Exception, FindFailed {
driver.get("www.xyz.com");        
try{     
   sikuliObject.click("C:\\workspace\\project\\images\\1.png", 0); //Clicking an image
   sikuliObject.type("C:\\workspace\\project\\images\\search.png", "hello"); //Inserting values into a text field
} catch(FindFailed e) {
   e.printStackTrace();
}

Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts