Mamy mały problem z testem funkcjonalnym z casper.js.Casper JS waitForResource z restful API
Żądamy tego samego zasobu dwukrotnie, najpierw za pomocą metody GET, a następnie za pomocą metody POST. Teraz, podczas oczekiwania na drugi zasób (POST), dopasowuje pierwszy zasób i przechodzi bezpośrednio do funkcji "wtedy".
Chcielibyśmy, abyśmy mogli sprawdzić metodę HTTP w funkcji "test", w ten sposób możemy właściwie zidentyfikować zasób. Na razie używamy kodu statusu (res.status), ale to nie rozwiązuje całkowicie naszego problemu, naprawdę potrzebujemy metody http.
// create new email
this.click(xPath('//div[@id="tab-content"]//a[@class="button create"]'));
// GET
this.waitForResource('/some/resource',
function then() {
this.test.assertExists(xPath('//form[@id="email_edit_form"]'), 'Email edit form is there');
this.fill('form#email_edit_form', {
'email_entity[email]': '[email protected]',
'email_entity[isMain]': 1
}, true);
// POST
this.waitForResource(
function test(res) {
return res.url.search('/some/resource') !== -1 && res.status === 201;
},
function then() {
this.test.assert(true, 'Email creation worked.');
},
function timeout() {
this.test.fail('Email creation did not work.');
}
);
},
function timeout() {
this.test.fail('Email adress creation form has not been loaded');
});
A może jest lepszy sposób na przetestowanie tego scenariusza? Mimo że jest to test funkcjonalny, wszystkie te czynności należy wykonać w jednym teście.