Kyle Coberly
www.kylecoberly.com
www.slides.com/kylecoberly/ember-test-selectors-page-objects
Explain why test selectors are preferable
var heading = find(".heading");
var heading = find("h1");
var heading = find("[data-test-heading]");
Semantic
Precise
Test Selector
var heading = find(testSelector("heading"));
Ember Test Selector
Use test selectors in an Ember app
<article>
<h1 data-test-post-title data-test-post-id="{{post.id}}">
{{post.title}}
</h1>
<p>{{post.body}}</p>
</article>
import testSelector from "ember-test-selectors";
// in Acceptance Tests
find(testSelector("post-id", "2"));
// in Component Integration Tests
this.$(testSelector("post-title")).click()
ember install ember-test-selectors
https://martinfowler.com/bliki/PageObject.html
Use page objects in tests
test("login shows an error when given bad credentials", function(assert) {
page
.visit()
.username("admin")
.password("invalid")
.submit();
andThen(() => {
assert.equal(page.error, "Invalid credentials");
});
});
ember install ember-cli-page-object
import PageObject, {
clickable,
fillable,
text,
visitable
} from "frontend/tests/page-object";
const page = PageObject.create({
visit: visitable("/"),
username: fillable("#username"),
password: fillable("#password"),
submit: clickable("button"),
error: text(".errors")
});
Use test selectors in page objects
<form>
<input type="text" data-test-username />
<input type="password" data-test-password />
<input type="submit" data-test-submit-button />
{{#if error}}
<p class="error" data-test-error-message>Invalid credentials</p>
{{/if}}
</form>
import PageObject, {
clickable,
fillable,
text,
visitable
} from "frontend/tests/page-object";
import testSelector from "ember-test-selector";
const page = PageObject.create({
visit: visitable("/"),
username: fillable(testSelector("username")),
password: fillable(testSelector("password")),
submit: clickable(testSelector("submit-button")),
error: text(testSelector("error-message"))
});
www.kylecoberly.com
www.slides.com/kylecoberly/ember-test-selectors-page-objects