Skip to content

Instantly share code, notes, and snippets.

@damondouglas
Created July 11, 2013 05:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damondouglas/5972747 to your computer and use it in GitHub Desktop.
Save damondouglas/5972747 to your computer and use it in GitHub Desktop.
Trying Headless Testing in Dart with Content Shell
PASS
1 PASS Expectation: text says Click Me!.
All 1 tests passed
open "/Applications/dart/chromium/Content Shell.app" --args --dump-render-tree web/headless.html
import 'dart:html';
void main() {
query("#sample_text_id")
..text = "Click me!"
..onClick.listen(reverseText);
}
void reverseText(MouseEvent event) {
var text = query("#sample_text_id").text;
var buffer = new StringBuffer();
for (int i = text.length - 1; i >= 0; i--) {
buffer.write(text[i]);
}
query("#sample_text_id").text = buffer.toString();
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Headless</title>
<link rel="stylesheet" href="headless.css">
</head>
<body>
<h1>Headless</h1>
<p>Hello world from Dart!</p>
<div id="sample_container_id">
<p id="sample_text_id"></p>
</div>
<script type="application/dart" src="headlesstest.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';
import 'dart:html';
import 'headless.dart' as app;
void main() {
useHtmlConfiguration();
app.main();
var sample_text = query("#sample_text_id");
test('text says Click Me!', (){
expect(sample_text.text, equals('Click me!'));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment