Permalink
Browse files

Add basic selenium test example

  • Loading branch information...
samccone committed Mar 17, 2015
1 parent 53fe56d commit 1a1f9da35fba80e60fa2485564bdba0ce4d9313d
Showing with 44 additions and 6 deletions.
  1. +3 −0 .travis.yml
  2. +3 −2 package.json
  3. +12 −0 page/index.html
  4. +26 −4 test/basic.js
View
@@ -1,3 +1,6 @@
language: node_js
+before_script:
+ - python -m SimpleHTTPServer &
+ - sleep 2
node_js:
- "0.12"
View
@@ -1,8 +1,9 @@
{
"scripts": {
- "test": "mocha"
+ "test": "mocha --timeout 10000"
},
"devDependencies": {
- "mocha": "^2.2.1"
+ "mocha": "^2.2.1",
+ "selenium-webdriver": "^2.45.1"
}
}
View
@@ -0,0 +1,12 @@
+<html>
+ <head>
+ <script>
+ function onHeadlineClick(e) {
+ document.querySelector('h1').innerHTML='awesome';
+ }
+ </script>
+ </head>
+ <body>
+ <h1 onClick='onHeadlineClick()'> click me </h1>
+ </body>
+</html>
View
@@ -1,6 +1,28 @@
-var assert = require('assert');
-describe("a basic test", function() {
- it("should be ok", function() {
- assert.equal(1, 1);
+var assert = require("assert");
+var webdriver = require("selenium-webdriver");
+
+describe("testing javascript in the browser", function() {
+ beforeEach(function() {
+ this.browser = new webdriver.Builder()
+ .withCapabilities({
+ browserName: "chrome"
+ }).build();
+
+ return this.browser.get("http://localhost:8000/page/index.html");
+ });
+
+ afterEach(function() {
+ return this.browser.quit();
+ });
+
+ it("should handle clicking on a headline", function(done) {
+ var headline = this.browser.findElement(webdriver.By.css('h1'));
+
+ headline.click();
+
+ headline.getText().then(function(txt) {
+ assert.equal(txt, "awesome");
+ done();
+ });
});
});

0 comments on commit 1a1f9da

Please sign in to comment.