General samples (JavaScript SDK)

This topic includes samples that apply to all technologies.

waitUntil demonstration

The following example demonstrates the waitUntil behavior.

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 will return false, since condition is not met.
            expect(waitResult).toBeFalsy();
        });

        checkBox.set(true);

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

        LFT.whenDone(done);
    });

});