Skip to content

Instantly share code, notes, and snippets.

@nallachaitu
Created September 6, 2012 16:35
Show Gist options
  • Save nallachaitu/3658253 to your computer and use it in GitHub Desktop.
Save nallachaitu/3658253 to your computer and use it in GitHub Desktop.
function for reading the results
package org.jboss.arquillian.qunit.junit;
import java.util.HashMap;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
@RunWith(Arquillian.class)
public class TestHandler
{
static String location; // to be defined at an appropriate place later
HashMap<String,Integer> map; // to be defined at an appropriate place later
public void runQunitMethod(WebDriver browser,String className,String methodName) throws AssertionError
{
//String url = location + "?testNumber=" + map.get(methodName);
String url = "file:///C:/Users/nallacha/Desktop/DroneInitialTesting/webpage.html?testNumber=1";
browser.get(url);
//wait for the results.
(new WebDriverWait(browser, 10))
.until(new ExpectedCondition<WebElement>(){
public WebElement apply(WebDriver d) {
return d.findElement(By.id("qunit-testresult"));
}});
//read the results
String passed = browser.findElement(By.cssSelector("div#qunit p#qunit-testresult .passed")).getText().toString();
String failed = browser.findElement(By.cssSelector("div#qunit p#qunit-testresult .failed")).getText().toString();
int passedNum = Integer.parseInt(passed);
int failedNum = Integer.parseInt(failed);
String total = (passedNum + failedNum) + "";
if(failedNum != 0)
throw new AssertionError(failed + "Out of " + total +" are failed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment