Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/headissue/Sahi
Browse files Browse the repository at this point in the history
  • Loading branch information
globalworming committed Sep 9, 2014
2 parents 7f08bc1 + c88c315 commit 5ec6b03
Show file tree
Hide file tree
Showing 21 changed files with 200 additions and 146 deletions.
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: java
jdk:
- oraclejdk8
- oraclejdk7
- openjdk7
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sahi
# Sahi [![Build Status](https://travis-ci.org/headissue/Sahi.svg?branch=master)](https://travis-ci.org/headissue/Sahi)

## Requirements

Expand All @@ -11,8 +11,7 @@ sahi-core:

sahi-test-webapp:

- Firefox
- [certutil](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/tools/NSS_Tools_certutil#__Availability_)
- [phantomjs](http://phantomjs.org)

## Setting up the workspace

Expand Down
2 changes: 1 addition & 1 deletion sahi-core/bin/dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ US=`dirname $0`;
US=`(cd $US; pwd)`;

if [ ! $SAHI_HOME ]; then
export SAHI_HOME=..
export SAHI_HOME=$US/..
fi

if [ ! $SAHI_USERDATA_DIR ]
Expand Down
3 changes: 1 addition & 2 deletions sahi-core/bin/sahi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
US=`dirname $0`;
US=`(cd $US; pwd)`;


if [ ! $SAHI_HOME ]
then
# working directory $SAHI_HOME/bin expected
export SAHI_HOME=..
export SAHI_HOME=$US/..
fi
if [ ! $SAHI_USERDATA_DIR ]
then
Expand Down
2 changes: 1 addition & 1 deletion sahi-core/bin/testrunner.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ esac
US=`dirname $0`;
US=`(cd $US; pwd)`;

java -cp ../lib/sahi-test-runner-4.4-jar-with-dependencies.jar \
java -cp $US/../lib/sahi-test-runner-4.4-jar-with-dependencies.jar \
net.sf.sahi.test.TestRunner \
-test $script -browserType phantomjs \
-baseURL http://sahi.example.com/_s_/dyn/Driver_initialized \
Expand Down
Empty file modified sahi-core/bin/web.sh
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions sahi-core/src/main/java/net/sf/sahi/command/Suite.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import net.sf.sahi.config.Configuration;
import net.sf.sahi.issue.JiraIssueCreator;
import net.sf.sahi.report.ConsoleReporter;
import net.sf.sahi.report.HtmlReporter;
import net.sf.sahi.report.JunitReporter;
import net.sf.sahi.report.TM6Reporter;
Expand Down Expand Up @@ -177,6 +178,9 @@ private void setReporters(final SahiTestSuite suite, final HttpRequest request)
suite.setHtmlLogDir(logDir);
suite.addReporter(new HtmlReporter(logDir));
}
if (request.getParameter("console") != null) {
suite.addReporter(new ConsoleReporter());
}
logDir = request.getParameter("tm6");
if (logDir != null) {
logDir = getLogDir(defaultLogDir, logDir);
Expand Down
100 changes: 100 additions & 0 deletions sahi-core/src/main/java/net/sf/sahi/report/ConsoleFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package net.sf.sahi.report;

import java.text.DateFormat;
import java.util.List;

public class ConsoleFormatter implements Formatter {

public String getFileName(String scriptName) {
return "";
}

public String getHeader() {
return "";
}

public String getResultData(List<TestResult> listResult) {
StringBuffer sb = new StringBuffer();
if (listResult != null && listResult.size() > 0) {
for (int i = 0; i < listResult.size(); i++) {
TestResult result = listResult.get(i);
String res = getStringResult(result);
if (!res.isEmpty()) {
sb.append(res).append("\n");
}
}
}

return sb.toString();
}

public String getStringResult(final TestResult result) {
if (result.type.equals(ResultType.RAW)) {
return result.message;
}
if (!(ResultType.FAILURE.equals(result.type) || ResultType.ERROR.equals(result.type))) {
return "";
}

StringBuffer sb = new StringBuffer();
sb.append("[").append(result.type.getName()).append(
"] ");
if (result.debugInfo != null) {
sb.append(result.debugInfo);
}
sb.append("\t").append(DateFormat.getDateTimeInstance().format(result.time));
if (result.message != null && !result.message.isEmpty()) {
sb.append("\n\t").append(result.message.trim().replace("\n", "\n\t"));
}
if (result.failureMsg != null && !result.failureMsg.isEmpty()) {
sb.append("\n\t").append(result.failureMsg.trim().replace("\n", "\n\t"));
}
return sb.toString();
}

public String getSummaryHeader() {
return "";
}

public String getSummaryData(TestSummary summary) {
StringBuffer sb = new StringBuffer();
int successRate = summary.getSteps() != 0 ? ((summary.getSteps() - (summary.getFailures() + summary.getErrors())) * 100) / summary.getSteps()
: 100;
sb.append("[")
.append(summary.hasFailed() ? ResultType.FAILURE.getName() : ResultType.SUCCESS.getName())
.append("] ")
.append(summary.getScriptName())
.append("\nSahi Tests run: ").append(summary.getSteps())
.append(", Failures: ").append(summary.getFailures())
.append(", Errors: ").append(summary.getErrors())
/*
.append(" -> Rate: ").append(successRate)
.append("%")
*/
.append(", Time Elapsed: ")
.append(new Double(summary.getTimeTaken()) / 1000)
.append(" sec")
.append("\n");
return sb.toString();
}

public String getSummaryFooter() {
return "";
}

public String getStartScript() {
return "";
}

public String getStopScript() {
return "";
}

public String getFooter() {
return "";
}

public String getSuiteLogFileName() {
return "";
}
}
35 changes: 35 additions & 0 deletions sahi-core/src/main/java/net/sf/sahi/report/ConsoleReporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.sf.sahi.report;

import net.sf.sahi.test.TestLauncher;

import java.io.*;
import java.util.List;

public class ConsoleReporter extends SahiReporter {

BufferedWriter outWriter = new BufferedWriter(new OutputStreamWriter(System.out)) {
@Override
public void close() throws IOException {
// we won't close System.out
}
};

public ConsoleReporter() {
super(new ConsoleFormatter());
}

@Override
public boolean createSuiteLogFolder() {
return true;
}

@Override
public void generateSuiteReport(List<TestLauncher> tests) {
// disabled
}

@Override
protected Writer createWriter(String file) throws IOException {
return outWriter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ public boolean isPartOfSuite() {
}

public void stop() {
if (this.stopped) return;
super.stop();
try {
report.stopTimer();
Expand Down
1 change: 0 additions & 1 deletion sahi-core/src/main/java/net/sf/sahi/test/TestLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ private void launchBrowser() throws Exception {
}

public void kill() {
System.out.println("Killing " + scriptName);
logger.fine("Killing " + scriptName);
if (!isSingleSession) browserLauncher.kill();
}
Expand Down
11 changes: 2 additions & 9 deletions sahi-core/src/main/java/net/sf/sahi/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -507,15 +507,8 @@ public static String executeCommand(String[] command) throws Exception {
}

public static Process executeAndGetProcess(String[] command) throws Exception {
Process p = Runtime.getRuntime().exec(command);
InputStream stdInput = p.getInputStream();
InputStream stdError = p.getErrorStream();
StringBuffer inBuffer = new StringBuffer();
StringBuffer errBuffer = new StringBuffer();
Thread inThread = new Thread(new StreamReader(stdInput, inBuffer));
inThread.start();
Thread errThread = new Thread(new StreamReader(stdError, errBuffer));
errThread.start();
// use inheritIO to see the output of the browser and other tools on console
Process p = new ProcessBuilder().inheritIO().command(command).start();
return p;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<displayName>PhantomJS</displayName>
<icon>safari.png</icon>
<path>phantomjs</path>
<options>--proxy=localhost:9999 $userDir/phantomscript/phantom.js</options>
<options>--proxy=localhost:9999 --ssl-certificates-path=$userDir/certs $userDir/phantomscript/phantom.js</options>
<processName>phantomjs</processName>
<capacity>100</capacity>
<useSystemProxy>false</useSystemProxy>
Expand Down
4 changes: 0 additions & 4 deletions sahi-core/src/main/resources/net/sf/sahi/workspace/phantom.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ if (phantom.args.length === 0) {
page.open(address, function(status) {
if (status === 'success') {
page.viewportSize = { width: 1000, height: 1000 };
var title = page.evaluate(function() {
return document.title;
});
console.log('Page title is ' + title);
} else {
console.log('FAIL to load the address');
}
Expand Down
18 changes: 12 additions & 6 deletions sahi-test-runner/src/main/java/net/sf/sahi/test/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,16 @@ public static boolean mainCLIParams(String[] args) throws IOException, Interrupt
String port2 = map.get("port");
if (host == null) host = "localhost";
if (port2 == null) port2 = "9999";
String threads = map.get("threads");
if (threads == null) threads = "1";
final String browserType2 = map.get("browserType");
final TestRunner testRunner;
if (browserType2 != null){
testRunner = new TestRunner(testName, browserType2, map.get("baseURL"),
host, port2, map.get("threads"));
host, port2, threads);
} else {
testRunner = new TestRunner(testName, map.get("browser"), map.get("baseURL"),
host, port2, map.get("threads"), map.get("browserOption"), map.get("browserProcessName"));
host, port2, threads, map.get("browserOption"), map.get("browserProcessName"));
}
if ("true".equals(map.get("htmlLog"))) {
String logDir = map.get("htmlLogDir");
Expand All @@ -154,6 +156,9 @@ public static boolean mainCLIParams(String[] args) throws IOException, Interrupt
if (logDir == null || "default".equals(logDir)) logDir = "";
testRunner.addReport(new Report("junit", logDir));
}
if ("true".equals(map.get("consoleLog"))) {
testRunner.addReport(new Report("console", "true"));
}
if (map.get("initJS") != null) {
testRunner.setInitJS(map.get("initJS"));
}
Expand Down Expand Up @@ -188,11 +193,11 @@ private static String guessBrowserProcessName(String browser2) {

protected static void help() {
System.out.println("------------------------");
System.out.println("New Usage 1: java -cp /path/to/ant-sahi.jar net.sf.sahi.test.TestRunner -test <test_or_suite_name> -browserType <browser_type> -baseURL <start_url> -threads <number_of_threads>");
System.out.println("Usage: java -cp /path/to/sahi-test-runner.jar net.sf.sahi.test.TestRunner -test <test_or_suite_name> -browserType <browser_type> -baseURL <start_url>");
System.out.println("--- More options ---");
System.out.println(" -test \t\t\tpath to test or suite");
System.out.println(" -baseURL \t\tbaseURL for all tests");
System.out.println(" -threads \t\tno. of browser instances to run in parallel");
System.out.println(" -threads \t\tno. of browser instances to run in parallel. Default is 1");
System.out.println(" -browserType \t\tbrowserType as specified in sahi/userdata/config/browser_types.xml");
System.out.println(" -browser \t\tfull browser to browser. Ignored if browserType specified.");
System.out.println(" -browserProcessName \tbrowser process name used to find the pid when using ps or tasklist commands. Ignored if browserType specified.");
Expand All @@ -201,12 +206,13 @@ protected static void help() {
System.out.println(" -junitLogDir \t\tpath to junit log dir. If not specified, uses default location in userdata/logs");
System.out.println(" -htmlLog \t\ttrue or false. Enable or disable html logs");
System.out.println(" -htmlLogDir \t\tpath to html log dir. If not specified, uses default location in userdata/logs");
System.out.println(" -consoleLog \t\ttrue or false. Enable or disable console logs");
System.out.println(" -initJS \t\tAny javascript which would be executed before every script");
System.out.println(" -useSingSession \t\ttrue or false. Execute all scripts sequentially in a single browser session. Default is false.");
System.out.println(" -useSingleSession \ttrue or false. Execute all scripts sequentially in a single browser session. Default is false.");
System.out.println(" -extraInfo \t\tAny extra info that may be accessed using _extraInfo()");

System.out.println("--- OR ---");
System.out.println("Usage: java -cp /path/to/ant-sahi.jar net.sf.sahi.test.TestRunner <test_or_suite_name> <browser_executable> <start_url> <log_dir> <sahi_host> <sahi_port> <number_of_threads> <browser_executable> [<browser_option>]");
System.out.println("Usage: java -cp /path/to/sahi-test-runner.jar net.sf.sahi.test.TestRunner <test_or_suite_name> <browser_executable> <start_url> <log_dir> <sahi_host> <sahi_port> <number_of_threads> <browser_executable> [<browser_option>]");
System.out.println("Set log_dir to \"default\" to log to the default log dir");
System.out.println("Set number_of_threads to a number which is compatible with your machine CPU and RAM.");
System.out.println("Look at http://sahi.co.in/w/Running+multiple+tests+in+batch+mode for details on browser options for various browsers.");
Expand Down
4 changes: 2 additions & 2 deletions sahi-test-webapp/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Integration Tests

This package is meant to provide a set of sample .html files and test suites to make sure the API works.
This package is meant to provide a set of sample .html files and test suites to make sure the Sahi API works.

Just run the TestApiItegration unittest.
Just run the TestApiIntegration unit test.


Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package com.headissue.demopages;

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;

/**
* Provides the demopages for the integration tests
*/
public class DemoPageServer implements Runnable {
public Server server;
public int port;

@Override
public void run() {
server = new Server(7733);
server = new Server();
SocketConnector _socketConnector = new SocketConnector();
_socketConnector.setHost("127.0.1.1");
_socketConnector.setPort(0); // finds automagically a free port
server.setConnectors(new Connector[]{_socketConnector});
WebAppContext context = new WebAppContext();
context.setDescriptor(WebAppContext.WEB_DEFAULTS_XML);
context.setResourceBase("./src/main/webapp");
Expand All @@ -20,6 +27,10 @@ public void run() {
server.setHandler(context);
try {
server.start();
port = _socketConnector.getLocalPort();
synchronized (this) {
notifyAll();
}
server.join();
} catch (InterruptedException e) {
try {
Expand Down
Loading

0 comments on commit 5ec6b03

Please sign in to comment.