General samples (JavaScript SDK)

This topic includes samples that apply to all technologies.

waitUntil demonstration

The following example demonstrates the waitUntil behavior.

  • Demonstrates the waitUntil behavior when a condition is not met:

    1. Navigate to a certain URL that has a check box and make sure the check box is unchecked.
    2. Use waitUntil with a 3 second timeout to determine if the check box is checked. waitUntil is resolved to false after 3 seconds.
  • Demonstrates the waitUntil behavior when a condition is met:

    1. Set the check box to selected.
    2. Use waitUntil to demonstrate that it is immediately resolved to true.

var LFT = require("leanft");
var expect = require("leanft/expect");
var Web = LFT.Web;

jasmine.DEFAULT_TIMEOUT_INTERVAL = 400000;

describe("waitUntil samples", function () {
    var browser;
    beforeAll(function (done) {
        LFT.init();

        Web.Browser.launch(Web.BrowserType.Chrome).then(function (b) {
            browser = b;
        });

        LFT.whenDone(done);
    });

    afterAll(function(done){
        browser.close();
        LFT.cleanup();

        LFT.whenDone(done);
    });

    it("examples of waitUntil return code", function (done) {
        //navigate to a page with a checkbox
        browser.navigate("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox");

        //describe the checkboxvar checkBox = browser.$(Web.Frame({
                id:"frame_Basic_example",
                name:""
            }
        )).$(Web.CheckBox({
                type:"checkbox",
                tagName:"INPUT",
                name:""
            }
        ));

        checkBox.set(false);

        //condition function to check if the checkbox is setvar isChecked = checkBox.isChecked.bind(checkBox);

        LFT.SDK.waitUntil(isChecked, 3*1000).then(function (waitResult) {
            //after 3 seconds the waitUntil returns false, since condition is not met.
            expect(waitResult).toBeFalsy();
        });

        checkBox.set(true);

        LFT.SDK.waitUntil(isChecked, 3*1000).then(function (waitResult) {
            //waitUntil immediately returns true, since condition is met.
            expect(waitResult).toBeTruthy();
        });

        LFT.whenDone(done);
    });

});