don kon
don kon

Reputation: 39

syntax for verifying if the element is present for protractor serenity

What is the syntax for checking if the element is present? I need to check if the element is present in order to go further in my test. If the element is not present i want to perform some other action.

This is what I am trying but the syntax does not work in serenity:

import {Click, PerformsTasks, Task, step, Wait, Is} from "serenity-js/lib/screenplay-protractor";
import {ProductDetailPageMap} from "../interactions/element-mappings/ProductDetailPageMap";
import { Interaction, UsesAbilities, AnswersQuestions } from "serenity-js/lib/screenplay-protractor";
import { Target, Attribute, BrowseTheWeb } from "serenity-js/lib/screenplay-protractor";
import { ElementArrayFinder, ElementFinder, $$, browser } from "protractor";


export class AddItemToWishlist implements Task {
    static called(): AddItemToWishlist {
        return new AddItemToWishlist();
    }

    private parseSizeList(elements: ElementArrayFinder): any {
        if (elements.isPresent()) {
            Click.on(ProductDetailPageMap.addToWishlist)
        } else {
            Click.on(ProductDetailPageMap.removeFromWishlist)
            browser.sleep(2000);
            Click.on(ProductDetailPageMap.addToWishlist)
            }
    }

    @step('{0} Add Item to the Wishlist')
    performAs(actor: PerformsTasks): PromiseLike<void> {
        return actor.attemptsTo(
            //return 
        );
    }
}

I am not sure what to add in the return though??

Upvotes: 1

Views: 1588

Answers (1)

Sandy_22
Sandy_22

Reputation: 117

var logoutButton =  element("//button[@type='submit']/span[.='Add to wishlist']");
logoutButton.isPresent().then(function (result) {
        if (result) {
              // Element IS PRESENT...DO SOMETHING
        } else {
            // Element IS NOT PRESENT...DO SOMETHING
        };
    });

Upvotes: 0

Related Questions