Reputation: 375
How so I write test cases for carousel image slider in protractor. i.e. check if image is sliding automatically or on click of prev and next button check image should change.
Upvotes: 0
Views: 1203
Reputation: 591
Typically you would want to have locators for previous and next buttons and for the active image e.g.:
var prev = element(by.css('.prev'));
var next = element(by.css('.next'));
var activeImage = element(by.css('img.active'));
You could then test button clicks for a series of 2 images e.g.
var beforeImage = "apples.jpg";
var afterImage = "pears.jpg";
it('apples followed by pears', function() {
expect(activeImage.getAttribute('src')).toBe(beforeImage);
next.click();
expect(activeImage.getAttribute('src')).toBe(afterImage );
});
it('pears followed by apples', function() {
next.click();
expect(activeImage.getAttribute('src')).toBe(afterImage );
prev.click();
expect(activeImage.getAttribute('src')).toBe(beforeImage);
})
Upvotes: 1