1

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??

don kon
  • 29
  • 4
  • What element? Syntax for what, exactly? Please read [ask] and then [edit] your question to describe what you want to do, what you have tried, and what results you got. If this is a question about general syntax of a language or API, you will probably be asked to check the API docs as part of your research. –  Mar 08 '18 at 21:29

1 Answers1

0
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
        };
    });
Sandy_22
  • 117
  • 1
  • 1
  • 10