Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Selenium WebDriver tests are meant to be run after a new stack has been built or code has been updated to run sanity tests against a development or production environment. These tests are meant to check for main site functionality such as particular parts of the site loading/being reachable (My Account, Workspaces, DMDII Member Portal and Projects, My Organization, etc). The code for this can be found in the QA Repository in BitBucket.

Prerequisites (Downloads and Installing)

It is recomended to create and run your tests on a linux operating system or in a VirtualBox linux environment. in order to be able to run Java, Selenium WebDriver Tests the following will need to be installed on your computer:

  • Java 8 JDK
    • Can be found:
  • Eclipse Mars 1
    • Can be found:
  • Selenium WebDriver Server .jar files
    • Can be found:
  • Google Chrome Web Browser
    • Can be found:
  • Selenium ChromeDriver
    • Can Be found:
  • Firefox Web Browser
    • Can be found:
  • Selenium FirefoxDriver (i.e: geckoDriver )
    • Can be found:

Recommended: Install the Firebug add-onĀ  for Firefox as it can help to find Ids, css, and xpaths that will need to include in your code.

Configuration

In order to begin writing Selenium/Selenese Code, you will need to configure your Eclipse Properties to allow running of Selenium Functions and methods. The following are the steps that need to be taken when creating new

Example Code

Setting System Environment Variables

To help anonymize our testing accounts and not expose these in our code base, we set our gmail username and password as environment variables on local machines. In a terminal window run: sudo nano /etc/profile. Add the following lines to the bottom of the file:

Selenium_User1=example@gmail.com
Selenium_Pass1=examplePa$$word

Opening a Web Browser

System.setProperty("webdriver.chrome.driver", "/home/<username>/file/path/to/chromedriver");

Maximizing Browser Window Size

driver.manage().window().maximize();

Visiting a Web Page

driver.get("http://beta.opendmc.org");

Clicking on Hyper-link or Button

driver.findElement(By.id("idOfElement")).click();
driver.findElement(By.cssSelector("cssToElementLocation")).click();
driver.findElement(By.xpath("actualXpathToElement")).click();

Writing into a text field

driver.findElement(By.if("idOfElement")).sendKeys("Text to add to Text field");
driver.findElement(By.cssSelector("cssToElementLocation")).sendKeys("Text to add to Text field");
driver.findElement(By.xpath("actualXpathToElement")).sendKeys("Text to add to Text field");

Using Keyboard Commands


Uploading a Document

Wait for Element to Load

WebDriverWait wait = new WebDriverWait(driver, 10);

  • The line of code above initializes wait

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("idOfElement")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("cssToElementLocation")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("actualXpathToElement")));

  • Example of calling wait to wait for a particular element

How to Grab Words on Web Page

WebElement workspaceNameCreated = driver.findElement(By.cssSelector("cssToElementLocation"));
String workspaceNameCreatedStr = "Workspace name Not Found";
workspaceNameCreatedStr = workspaceNameCreated.getText();
System.out.println(workspaceNameCreatedStr);

Running Tests


  • No labels