Permalink
Browse files

host our own guinea pig

  • Loading branch information...
1 parent 5fb3dc5 commit 42dc1794fa3b16c8a6eed9e9e965804ac44b9f52 @jlipps committed Mar 21, 2013
View
@@ -5,6 +5,7 @@ var status = require('./uiauto/lib/status')
, logger = require('../logger.js').get('appium')
, _s = require("underscore.string")
, fs = require('fs')
+ , swig = require('swig')
, path = require('path')
, _ = require('underscore');
@@ -633,10 +634,18 @@ exports.crash = function() {
};
exports.guineaPig = function(req, res) {
- var file = path.resolve(__dirname, "test/guinea-pig.html");
- fs.readFile(file, function(err, data) {
- if (err) return res.send(500);
- res.set('Content-Type', 'text/html');
- res.send(data);
- });
+ var params = {
+ serverTime: parseInt(new Date().getTime() / 1000, 10)
+ , userAgent: req.headers['user-agent']
+ , comment: "None"
+ };
+ if (req.method === "POST") {
+ params.comment = req.body.comments || params.comment;
+ }
+ res.set('Content-Type', 'text/html');
+ res.send(exports.getTemplate('guinea-pig').render(params));
+};
+
+exports.getTemplate = function(templateName) {
+ return swig.compileFile(path.resolve(__dirname, "templates/" + templateName + ".html"));
};
View
@@ -68,7 +68,7 @@ module.exports = function(appium) {
// these are for testing purposes only
rest.post('/wd/hub/produce_error', controller.produceError);
rest.post('/wd/hub/crash', controller.crash);
- rest.get('/guinea-pig', controller.guineaPig);
+ rest.all('/test/guinea-pig', controller.guineaPig);
// appium-specific extensions to JSONWP
// these aren't part of JSONWP but we want them or something like them to be
Oops, something went wrong.
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>I am another page title</title>
+</head>
+<body>
+ I am some other page content
+ <div id="i_am_an_id">I am another div</div>
+</body>
+</html>
+
@@ -0,0 +1,65 @@
+
+<!DOCTYPE html>
+<html>
+<head>
+ <title>I am a page title</title>
+ <script type="text/javascript" src="/js/jquery.min.js"></script>
+</head>
+<body>
+
+<h1>This page is a Selenium sandbox</h1>
+
+I am some page content
+<div id="i_am_an_id" class="i_am_a_class">I am a div</div>
+<a href="/test/guinea-pig2.html" id="i am a link">i am a link</a><br/>
+<a href="/test/guinea-pig2.html" id="blanklink" target="_blank">i am a new window link</a>
+ <div>i appear 3 times</div>
+ <div>i appear 3 times</div>
+ <div>i appear 3 times</div>
+<div id="invisible div" style="display:none;">i am invisible</div>
+<form id="the_forms_id">
+<p>
+<input id="i_am_a_textbox" name="i_am_a_textbox" type="text" value="i has no focus" />
+</p>
+<input type="checkbox" id="unchecked_checkbox" name="unchecked_checkbox"/>
+<input type="checkbox" id="checked_checkbox" name="checked_checkbox" checked="checked"/>
+
+</form>
+<span id="your_comments">
+ Your comments: {{ comment }}<br/>
+</span>
+&#x00F1;&#x2603;
+<script type="text/javascript">
+ $(document).ready(function(){
+ $("#i_am_a_textbox").focus(function(){$(this).val("");})
+ .blur(function(){$(this).val("i has no focus");});
+ });
+</script>
+
+ <div class="border">
+
+ <form id="jumpContact" method="post">
+ <p>
+ <label for="fbemail">Email:</label><br>
+ <input id="fbemail" type="text" size="50" name="fbemail" placeholder="We would really like to follow up!"></input>
+ </p>
+ <p>
+ <label for="comments">Comments:</label><br>
+ <textarea id="comments" style="width:400px;height:100px" name="comments" placeholder="Thanks in advance, this is really helpful."></textarea>
+ </p>
+ <div style="float:right">
+ <input class="jumpButton" type="submit" name="submit" id="submit" value="send" />
+ </div>
+ </form>
+ </div>
+
+ <p>Server time: <span id="servertime">{{ serverTime }}</span></p>
+ <p>Client time: <span id="clienttime"></span></p>
+ <script type="text/javascript">
+ $("#clienttime").text(parseInt(new Date().getTime() / 1000))
+ </script>
+
+ <p id="useragent">{{ userAgent }}</p>
+
+</body>
+</html>
@@ -1,131 +0,0 @@
-
-<!DOCTYPE html>
-<html>
-<head>
- <title>I am a page title - Sauce Labs</title>
- <link href="/css/themes/cupertino/jquery-ui-1.8.5.custom.css" media="screen" rel="stylesheet" type="text/css" />
- <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
-</head>
-<body>
-
-<h1>This page is a Selenium sandbox</h1>
-
-I am some page content
-<div id="i_am_an_id" class="i_am_a_class">I am a div</div>
-<a href="/test-guinea-pig2.html" id="i am a link">i am a link</a><br/>
-<a href="http://google.com" id="googlelink" target="_blank">i am a google link</a>
- <div>i appear 3 times</div>
- <div>i appear 3 times</div>
- <div>i appear 3 times</div>
-<div id="invisible div" style="display:none;">i am invisible</div>
-<form id="the_forms_id">
-<p>
-<input id="i_am_a_textbox" name="i_am_a_textbox" type="text" value="i has no focus" />
-</p>
-<input type="checkbox" id="unchecked_checkbox" name="unchecked_checkbox"/>
-<input type="checkbox" id="checked_checkbox" name="checked_checkbox" checked="checked"/>
-
-</form>
-<span id="your_comments">
-Your comments: None<br/>
-</span>
-ñ☃
-<script type="text/javascript">
- $(document).ready(function(){
- $("#i_am_a_textbox").focus(function(){$(this).val("");})
- .blur(function(){$(this).val("i has no focus");});
- });
-</script>
-
- <div class="border">
-
- <script type="text/javascript">
- var resetFeedback = function() {
- $(".jumpOkButton").css("display", "none")
- $("form#jumpContact").css("display", "block");
- $(".formMessage").css("display", "none");
- $("#comments").attr("value", "");
- $("#email").attr("value", "");
- $("#email").trigger("focus");
- };
-
- var setupJumpFeedback = function() {
- $("#jumpContact input[type=submit]").button();
- var submitFunc = function() {
- var form = $(this);
- var data = form.serialize();
- $("#comments").trigger("focus");
-
- var successFunc = function(response) {
- if (response == "Message sent") {
- $(".formMessage")
- .text("Thanks for your feedback, we'll get back to you soon if needed.")
- .slideDown("normal");
-
- form.slideUp("normal");
- }
- else {
- $(".formMessage")
- .text("Oops! Looks like something went wrong, please try again.")
- .slideDown("normal");
-
- $("input[type=submit]", form).slideDown();
- }
-
- $(".jumpOkButton").css("display", "block");
- };
-
- var errorFunc = function() {
- $(".formMessage")
- .text("Oops! Looks like something went wrong, please try again.")
- .slideDown("normal");
-
- $("input[type=submit]", form).slideDown();
- };
-
- $.ajax({
- type: "POST",
- url: "/jumpstart-send",
- data: data,
- success: successFunc,
- error: errorFunc
- });
-
- return false;
- };
-
- $("form#jumpContact").submit(submitFunc);
- };
- </script>
-
- <form id="jumpContact" method="post">
- <p>
- <label for="fbemail">Email:</label><br>
- <input id="fbemail" type="text" size="50" name="fbemail" placeholder="We would really like to follow up!"></input>
- </p>
- <p>
- <label for="comments">Comments:</label><br>
- <textarea id="comments" style="width:400px;height:100px" name="comments" placeholder="Thanks in advance, this is really helpful."></textarea>
- </p>
- <div style="float:right">
- <input class="jumpButton" type="submit" name="submit" id="submit" value="send" />
- </div>
- </form>
- <div class="formMessage"></div><br><br>
- <center>
- <input style="display:none" class="jumpOkButton" type="button" value="OK" onclick="resetFeedback();"/>
- </center>
-
- </div>
-
- <p>Server time: <span id="servertime">1363807183</span></p>
- <p>Client time: <span id="clienttime"></span></p>
- <script type="text/javascript">
- $("#clienttime").text(parseInt(new Date().getTime() / 1000))
- </script>
-
- <p id="useragent">Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22</p>
-
-</body>
-</html>
View
@@ -1,6 +1,7 @@
"use strict";
var express = require('express')
+ , _s = require('underscore.string')
, bodyParser = express.bodyParser();
module.exports.parserWrap = function(req, res, next) {
@@ -10,9 +11,12 @@ module.exports.parserWrap = function(req, res, next) {
req.headers['content-length'] = 0;
next();
} else {
- // hack because python client library sux
- if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
- req.headers['content-type'] = 'application/json';
+ // allow guineapig
+ if (!_s.startsWith(req.path, "/test")) {
+ // hack because python client library sux
+ if (req.headers['content-type'] === 'application/x-www-form-urlencoded') {
+ req.headers['content-type'] = 'application/json';
+ }
}
bodyParser(req, res, next);
}
View
@@ -63,6 +63,7 @@
"prompt": "~0.2.9",
"ncp": "~0.4.2",
"grunt-contrib-jshint": "~0.1.1",
- "markdown": "~0.4.0"
+ "markdown": "~0.4.0",
+ "swig": "~0.13.5"
}
}
@@ -47,15 +47,15 @@ _.each(["iPhone", "iPad"], function(sim) {
describeWd('windows and frames', function(h) {
it("should automate a new window if one opens (" + sim + ")", function(done) {
loadWebView("safari", h.driver, function() {
- h.driver.elementById('googlelink', function(err, link) {
+ h.driver.elementById('blanklink', function(err, link) {
link.click(function() {
- spinTitle("Google", h.driver, function(err) {
+ spinTitle("I am another page title", h.driver, function(err) {
should.not.exist(err);
done();
});
});
});
- }, "http://localhost:4723/guinea-pig");
+ });
});
}, null, null, {device: sim + " Simulator"});
});
@@ -3,7 +3,7 @@
var driverBlock = require("./driverblock.js")
, describeSafari = driverBlock.describeForSafari()
- , guinea = 'http://saucelabs.com/test/guinea-pig'
+ , guinea = 'http://localhost:4723/test/guinea-pig'
, should = require('should')
, spinWait = require('./spin.js').spinWait;
@@ -22,13 +22,10 @@ module.exports.spinTitle = function (expTitle, driver, cb, timeout) {
});
};
-module.exports.loadWebView = function(webviewType, driver, cb, guineaOverride) {
- var title = 'I am a page title - Sauce Labs';
- if (typeof guineaOverride === "undefined") {
- guineaOverride = guinea;
- }
+module.exports.loadWebView = function(webviewType, driver, cb) {
+ var title = 'I am a page title';
if (webviewType === "safari") {
- driver.get(guineaOverride, function(err) {
+ driver.get(guinea, function(err) {
should.not.exist(err);
module.exports.spinTitle(title, driver, cb);
});
@@ -56,8 +53,8 @@ module.exports.buildTests = function(webviewType) {
desc = driverBlock.describeForApp(webviewType);
}
- var loadWebView = function(driver, cb, guineaOverride) {
- return module.exports.loadWebView(webviewType, driver, cb, guineaOverride);
+ var loadWebView = function(driver, cb) {
+ return module.exports.loadWebView(webviewType, driver, cb);
};
var spinTitle = module.exports.spinTitle;
@@ -68,7 +65,7 @@ module.exports.buildTests = function(webviewType) {
loadWebView(h.driver, function() {
h.driver.title(function(err, title) {
should.not.exist(err);
- title.should.eql("I am a page title - Sauce Labs");
+ title.should.eql("I am a page title");
h.driver.frame(null, function(err) {
should.not.exist(err);
h.driver.title(function(err, title) {
@@ -120,7 +117,7 @@ module.exports.buildTests = function(webviewType) {
should.not.exist(err);
el.click(function(err) {
should.not.exist(err);
- spinTitle('I am another page title - Sauce Labs', h.driver, done);
+ spinTitle('I am another page title', h.driver, done);
});
});
});
@@ -181,7 +178,7 @@ module.exports.buildTests = function(webviewType) {
loadWebView(h.driver, function() {
h.driver.url(function(err, url) {
should.not.exist(err);
- url.should.equal("http://saucelabs.com/test/guinea-pig");
+ url.should.equal(guinea);
done();
});
});
@@ -325,7 +322,7 @@ module.exports.buildTests = function(webviewType) {
el.getLocation(function(err, loc) {
should.not.exist(err);
loc.x.should.equal(10);
- loc.y.should.equal(450);
+ loc.y.should.equal(480);
done();
});
});
@@ -374,7 +371,7 @@ module.exports.buildTests = function(webviewType) {
should.not.exist(err);
h.driver.click(function(err) {
should.not.exist(err);
- spinTitle("I am another page title - Sauce Labs", h.driver, function(err) {
+ spinTitle("I am another page title", h.driver, function(err) {
should.not.exist(err);
done();
});
@@ -397,8 +394,8 @@ module.exports.buildTests = function(webviewType) {
h.driver.elementById('your_comments', function(err, element) {
should.not.exist(err);
element.text(function(err, text) {
- should.not.exist(err);
try {
+ should.not.exist(err);
text.should.eql('Your comments: This is a comment');
spinCb();
} catch (e) {

0 comments on commit 42dc179

Please sign in to comment.