Hi there,
I am working with Appium to test a web application. The test I want to write is to test whether a xhr requests is triggered when a button is clicked.
The source code of event listener is:
$('a').on('click', function(e) {
if (isLinkClick) {
var href, data;
if (e.preventDefault) {
e.preventDefault();
}
href = $(this).attr('href');
data = {
"data" : [ {
"dtk" : key,
"link" : href
} ]
};
$.ajax({
type : 'POST',
url : dtkUrlClick,
data : JSON.stringify(data),
success : function() {
updateLocation(href);
},
error : function() {
updateLocation(href);
}
});
//updateLocation(href);
}
});
And the test I am writing with wd is like below:
...
it('should send out xhr post', function() {
driver.get(consts.indexUrl)
.elementByClassName('relocate-button')
.click()
});
...
Then i have not hint to implement the test to check whether the xhr request is sent.
Though I understand that this kind of test is easy to implement in a unit test with angular and jasmine, but it is a lightweight project, we do not want to introduce angular and its unit test runner and framework to do the work. So I’d like to see whether there is a way to use mocha to test with appium.
Thanks.