How to use getZIndex method in Cypress

Best JavaScript code snippet using cypress

ZIndexManager.js

Source:ZIndexManager.js Github

copy

Full Screen

...48            c3.show();49            // onMousedown quits if there is a pending focus task.50            cancelFocus();51            // Order bottom up should be c1, c2, c352            expect(c3.el.getZIndex()).toBeGreaterThan(c2.el.getZIndex());53            expect(c2.el.getZIndex()).toBeGreaterThan(c1.el.getZIndex());54        });55        it("should re-order the windows on mousedown", function() {56            c1.showAt(0, 0);57            c2.showAt(50, 0);58            c3.showAt(100, 0);59            // onMousedown quits if there is a pending focus task.60            cancelFocus();61            // Fake mousedown because sythetic events won't work with capture which is what Floating's listener uses62            c1.onMouseDown({63                target: c1.el.dom64            });65            66            // Mousedown moves to top67            // Order bottom up should be c2, c3, c168            expect(c1.el.getZIndex()).toBeGreaterThan(c3.el.getZIndex());69            expect(c3.el.getZIndex()).toBeGreaterThan(c2.el.getZIndex());70        });71        it("should honour alwaysOnTop", function() {72            c1.setAlwaysOnTop(true);73            c1.showAt(0, 0);74            c2.showAt(50, 0);75            c3.showAt(100, 0);76            // onMousedown quits if there is a pending focus task.77            cancelFocus();78            // c1 should be glued to the top79            // Order bottom up should be c2, c3, c180            expect(c1.el.getZIndex()).toBeGreaterThan(c3.el.getZIndex());81            expect(c3.el.getZIndex()).toBeGreaterThan(c2.el.getZIndex());82            // Fake mousedown because sythetic events won't work with capture which is what Floating's listener uses83            c2.onMouseDown({84                target: c2.el.dom85            });86            // c2 should have gone up as far as it can to just below the alwaysOnTop c187            // Order bottom up should now be c3, c2, c188            expect(c1.el.getZIndex()).toBeGreaterThan(c2.el.getZIndex());89            expect(c2.el.getZIndex()).toBeGreaterThan(c3.el.getZIndex());90        });91        it("should sort to the bottom of the ZIndexStack if alwaysOnTop === -1", function() {92            c3.setAlwaysOnTop(-1);93            c1.showAt(0, 0);94            c2.showAt(50, 0);95            c3.showAt(100, 0);96            // onMousedown quits if there is a pending focus task97            cancelFocus();98            // c3 should be glued to the bottom99            // Order bottom up should be c3, c1, c2100            expect(c2.el.getZIndex()).toBeGreaterThan(c1.el.getZIndex());101            expect(c1.el.getZIndex()).toBeGreaterThan(c3.el.getZIndex());102        });103        it("should move to the front as far as possible while respecting other alwaysOnTop components", function() {104            c4.setAlwaysOnTop(1); // This will always be second from top105            c4.modal = false;106            c3.setAlwaysOnTop(2); // This will always be topmost107            c1.show();108            c2.show();109            c3.show();110            c4.show();111            // onMousedown quits if there is a pending focus task112            cancelFocus();113            // It cannot go all the way to front because there are two alwaysOnTop114            // Windows which should be above it.115            c1.toFront();116            // Order bottom up should c2, c1, c4, c3117            expect(c1.el.getZIndex()).toBeGreaterThan(c2.el.getZIndex());118            expect(c4.el.getZIndex()).toBeGreaterThan(c1.el.getZIndex());119            expect(c3.el.getZIndex()).toBeGreaterThan(c4.el.getZIndex());120        });121        it("should order parents", function() {122            // c2's ZIndexManager now manages C3's zIndex123            c2.add(c3);124            c1.showAt(0, 0);125            c2.showAt(50, 0);126            c3.showAt(25, 25);127            // onMousedown quits if there is a pending focus task.128            cancelFocus();129            // Fake mousedown because sythetic events won't work with capture which is what Floating's listener uses130            c1.onMouseDown({131                target: c1.el.dom132            });133            // c1 moved to top134            // Order bottom up should be c2, c3, c1135            expect(c1.el.getZIndex()).toBeGreaterThan(c3.el.getZIndex());136            expect(c3.el.getZIndex()).toBeGreaterThan(c2.el.getZIndex());137            // Fake mousedown because sythetic events won't work with capture which is what Floating's listener uses138            c2.onMouseDown({139                target: c2.el.dom140            });141            // onMousedown quits if there is a pending focus task.142            cancelFocus();143            // Mousedown on c2 should bring both c2 and c2 above c1 because c3 is a child of c2144            // Order bottom up should be c1, c2, c3145            expect(c3.el.getZIndex()).toBeGreaterThan(c2.el.getZIndex());146            expect(c2.el.getZIndex()).toBeGreaterThan(c1.el.getZIndex());147        });148        it("should assign a z-index to a floater that is rendered visible", function() {149            var c = new Ext.Component({150                renderTo: Ext.getBody(),151                floating: true,152                html: 'Foo'153            });154            c.show();155            expect(c.getEl().getZIndex()).toBe(Ext.WindowManager.zseed);156            c.destroy();157        });158        it("should always keep modal maks behind the window", function() {159            c1.show();160            c4.show();161            c1.destroy();162            expect(c4.zIndexManager.mask.getZIndex()).toBeLessThan(c4.el.getZIndex());163        });164    });165    describe("modal masking", function() {166        var w, mask;167        afterEach(function() {168            Ext.destroy(w);169            mask = w = null;170        });171        function makeWindow(config) {172            w = new Ext.window.Window(Ext.applyIf(config || {}, {173                width: 200,174                height: 200,175                title: 'Foo',176                autoShow: true,177                modal: true178            }));179        }180        describe("mask visibility", function() {181            beforeEach(function() {182                makeWindow();183                mask = w.zIndexManager.mask;184            });185            function getMaskIndex() {186                return parseInt(w.zIndexManager.mask.getStyle('z-index'), 10);187            }188            it("should show the mask below the floater when open", function() {189                expect(mask.isVisible()).toBe(true);190                expect(getMaskIndex()).toBeLessThan(w.getEl().getZIndex());191            });192            it("should re-show the mask after hiding then showing", function() {193                w.hide();194                w.show();195                expect(mask.isVisible()).toBe(true);196            });197            it("should hide the modal mask when hiding the last floater", function() {198                w.hide();199                expect(mask.isVisible()).toBe(false);200            });201            it("should hide the modal mask when destroying the last floater", function() {202                w.destroy();203                expect(mask.isVisible()).toBe(false);204            });205        });206        207        describe("element tabbability", function() {208            var btn, tabbables;209            210            beforeEach(function() {211                btn = new Ext.button.Button({212                    renderTo: Ext.getBody(),213                    text: 'foo'214                });215            });216            217            afterEach(function() {218                Ext.destroy(btn);219                btn = null;220            });221            222            describe("components below mask", function() {223                beforeEach(function() {224                    makeWindow();225                });226                227                it("button should become untabbable on mask show", function() {228                    // skipSelf = true, skipChildren = false, excludeRoot = w.el229                    tabbables = Ext.getBody().findTabbableElements({230                        skipSelf: true,231                        excludeRoot: w.el232                    });233                    234                    expect(tabbables.length).toBe(0);235                });236                237                it("button should become tabbable on mask hide", function() {238                    w.hide();239                    240                    // skipSelf = true, skipChildren = false, excludeRoot = w.el241                    tabbables = Ext.getBody().findTabbableElements({242                        skipSelf: true,243                        excludeRoot: w.el244                    });245                    246                    expect(tabbables).toEqual([ btn.getFocusEl().dom ]);247                });248                249                it("button should become untabbable on mask show/hide/show", function() {250                    w.hide();251                    w.show();252                    253                    // skipSelf = true, skipChildren = false, excludeRoot = w.el254                    tabbables = Ext.getBody().findTabbableElements({255                        skipSelf: true,256                        excludeRoot: w.el257                    });258                    259                    expect(tabbables.length).toBe(0);260                });261            });262            263            describe("components above mask", function() {264                beforeEach(function() {265                    makeWindow({266                        items: [267                            { xtype: 'textfield', fieldLabel: 'Login' },268                            { xtype: 'textfield', fieldLabel: 'Password' }269                        ],270                        271                        buttons: [272                            { text: 'OK' }273                        ]274                    });275                });276                277                it("should keep items above the mask tabbable", function() {278                    tabbables = w.getEl().findTabbableElements({279                        skipSelf: true280                    });281                    282                    // 6 tababbles:283                    // - Top focus trap284                    // - textfield 1285                    // - textfield 2286                    // - Button287                    // - Bottom focus trap288                    expect(tabbables.length).toBe(5);289                });290            });291        });292        describe("mask size", function() {293            // Not sure how to simulate a body resize here294            it("should size the mask to the body if the manager is global", function() {295                makeWindow();296                mask = w.zIndexManager.mask;297                expect(mask.getSize()).toEqual(Ext.Element.getViewSize());298                expect(mask).toHaveCls(Ext.Component.prototype.borderBoxCls);299            });300            it("should set the mask to the size of the container", function() {301                var ct = new Ext.container.Container({302                    renderTo: Ext.getBody(),303                    width: 400,304                    height: 400305                });306                w = ct.add({307                    xtype: 'window',308                    width: 100,309                    height: 100,310                    modal: true,311                    title: 'Foo'312                });313                w.show();314                mask = w.zIndexManager.mask;315                expect(mask.getSize()).toEqual({316                    width: 400,317                    height: 400318                });319                ct.destroy();320            });321            // This currently doesn't work, but probably should322            xit("should resize the mask when the container resizes", function() {323                var ct = new Ext.container.Container({324                    renderTo: Ext.getBody(),325                    width: 400,326                    height: 400327                });328                w = ct.add({329                    xtype: 'panel',330                    floating: true,331                    width: 100,332                    height: 100,333                    modal: true,334                    title: 'Foo'335                });336                w.show();337                mask = w.zIndexManager.mask;338                ct.setSize(200, 200);339                expect(mask.getSize()).toEqual({340                    width: 200,341                    height: 200342                });343                ct.destroy();344            });345        });346    });347    describe("hide/show", function() {348        it("should restore just visible items", function() {349            var a = new Ext.window.Window({350                width: 100,351                height: 100,352                autoShow: true353            });354            var b = new Ext.window.Window({355                width: 100,356                height: 100,357                autoShow: true358            });359            var c = new Ext.window.Window({360                width: 100,361                height: 100,362                autoShow: true363            });364            a.hide();365            expect(a.isVisible()).toBe(false);366            expect(b.isVisible()).toBe(true);367            expect(c.isVisible()).toBe(true);368            Ext.WindowManager.hide();369            expect(a.isVisible()).toBe(false);370            expect(b.isVisible()).toBe(false);371            expect(c.isVisible()).toBe(false);372            Ext.WindowManager.show();373            expect(a.isVisible()).toBe(false);374            expect(b.isVisible()).toBe(true);375            expect(c.isVisible()).toBe(true);376            Ext.destroy(a, b, c);377        });378    });379    describe("hideAll", function() {380        it("should hide all visible items", function() {381            var a = new Ext.window.Window({382                width: 100,383                height: 100,384                autoShow: true385            });386            var b = new Ext.window.Window({387                width: 100,388                height: 100,389                autoShow: true390            });391            var c = new Ext.window.Window({392                width: 100,393                height: 100,394                autoShow: true395            });396            Ext.WindowManager.hideAll();397            expect(a.isVisible()).toBe(false);398            expect(b.isVisible()).toBe(false);399            expect(c.isVisible()).toBe(false);400            Ext.destroy(a, b, c);401        });402        it("should hide the mask", function() {403            var a = new Ext.window.Window({404                width: 100,405                height: 100,406                autoShow: true407            });408            var b = new Ext.window.Window({409                width: 100,410                height: 100,411                autoShow: true412            });413            var c = new Ext.window.Window({414                width: 100,415                height: 100,416                autoShow: true,417                modal: true418            });419            expect(Ext.WindowManager.mask.isVisible()).toBe(true);420            Ext.WindowManager.hideAll();421            expect(Ext.WindowManager.mask.isVisible()).toBe(false);422            Ext.destroy(a, b, c);423        });424        it("should be able to show/hide the modal mask after a hideAll call", function() {425            var a = new Ext.window.Window({426                width: 100,427                height: 100,428                autoShow: true429            });430            var b = new Ext.window.Window({431                width: 100,432                height: 100,433                autoShow: true434            });435            var c = new Ext.window.Window({436                width: 100,437                height: 100,438                autoShow: true439            });440            Ext.WindowManager.hideAll();441            expect(a.isVisible()).toBe(false);442            expect(b.isVisible()).toBe(false);443            expect(c.isVisible()).toBe(false);444            var mask = a.zIndexManager.mask;445            expect(mask.isVisible()).toBe(false);446            var d = new Ext.window.Window({447                width: 100,448                height: 100,449                modal: true,450                autoShow: true451            });452            expect(mask.isVisible()).toBe(true);453            d.hide();454            expect(mask.isVisible()).toBe(false);455            Ext.destroy(a, b, c, d);456        });457    });458    // testcase for grid in a modal windows showing MessageBox on edit459    describe("Grid with modal windows and MessageBox", function() {460        var win, grid, cell, plugin;461        beforeEach(function() {462            win = new Ext.window.Window({463                items : [{464                    xtype   : 'grid',465                    columns : [{466                        dataIndex : 'f1',467                        editor    : {}468                    }],469                    store   : {470                        data   : [{ 471                            f1 : 'edit me' 472                        }]473                    },474                    plugins : {475                        ptype : 'cellediting'476                    }477                }],478                width  : 400,479                height : 130,480                modal  : true481            }).show();482            grid = win.down('grid');483            plugin = grid.findPlugin('cellediting');484        });485        afterEach(function() {486            win.close();487            Ext.MessageBox.hide();488            win.destroy();489            win = grid = cell = null;490        });491        it("should display the MessageBox on top", function() {492            grid.on('edit', function() {493                Ext.Msg.confirm('Foo', 'Bar');494            });495            cell = grid.getView().getCellInclusive({496                row: 0,497                column: 0498            }, true);499            jasmine.fireMouseEvent(cell, 'dblclick');500            waitsForFocus(plugin.activeEditor.field, 'plugin to edit');501            runs(function(){502                jasmine.fireKeyEvent(Ext.Element.getActiveElement(), 'keydown', Ext.event.Event.ENTER);503            });504            waitsFor(function() {505                return Ext.MessageBox.isVisible();506            }, 'message box to become visible');507            runs(function() {508                expect(Ext.MessageBox.el.getZIndex()).toBeGreaterThan(win.el.getZIndex());509            });510        });511    });512    // testcase for https://sencha.jira.com/browse/EXTJS-14046513    describe("picker field's pickers should stick to back if alwaysOnTop is set to -1", function() {514        it("should keep pickers below all other floating components", function() {515            var windowCombo,516                combo = new Ext.form.ComboBox({517                    store: ['A', 'b', 'C'],518                    editable: false,519                    fieldLabel: 'Combo',520                    renderTo: Ext.getBody(),521                    listConfig: {522                        alwaysOnTop: -1523                    }524                }),525                dateField = new Ext.form.Date({526                    editable: false,527                    fieldLabel: 'Date',528                    renderTo: Ext.getBody()529                }),530                window = new Ext.window.Window({531                    autoShow: true,532                    title: 'Test',533                    x:200,534                    y:0,535                    width: 400,536                    height: 400,537                    items: [538                        windowCombo = new Ext.form.ComboBox({539                            store: ['A', 'b', 'C'],540                            editable: false,541                            listCOnfig: {542                                alwaysOnTop: -1543                            }544                        })545                    ]546                });547            dateField.getPicker().setAlwaysOnTop(-1);548            // The combo dropdown should be below the window549            combo.expand();550            expect(combo.getPicker().el.getZIndex()).toBeLessThan(window.el.getZIndex());551            combo.collapse();552            // The combo dropdown should be below the window553            dateField.expand();554            expect(dateField.getPicker().el.getZIndex()).toBeLessThan(window.el.getZIndex());555            dateField.collapse();556            // The combo dropdown in the window is realtive to the window's ZIndexManager.557            // It should go above the window558            windowCombo.expand();559            expect(windowCombo.getPicker().el.getZIndex()).toBeGreaterThan(window.el.getZIndex());560            windowCombo.collapse();561            // The combo dropdown should be below the window562            combo.expand();563            expect(combo.getPicker().el.getZIndex()).toBeLessThan(window.el.getZIndex());564            565            Ext.destroy(combo, dateField, window);566        });567    });568    describe("bringToFront", function() {569        it("should return false when bringing to front a non-rendered window, when passing id", function() {570            var win = new Ext.window.Window({571                title: 'Win',572                id: 'theWin',573                width: 100,574                height: 100,575                autoShow: true576            });577            expect(Ext.WindowManager.bringToFront('theWin')).toBe(false);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.getZIndex("#elementId").then((zIndex) => {2  console.log(zIndex);3});4Cypress.Commands.add("getZIndex", (selector) => {5    .get(selector)6    .invoke("css", "zIndex")7    .then((zIndex) => {8      return zIndex;9    });10});

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.get('#element').then(($el) => {2    const zIndex = $el.getZIndex();3    expect(zIndex).to.equal(10);4});5Cypress.Commands.add('getZIndex', { prevSubject: 'element' }, (subject) => {6    const style = window.getComputedStyle(subject[0]);7    return style.getPropertyValue('z-index');8});9import './commands';10describe('Test', () => {11    it('Test', () => {12        cy.get('body').then(($el) => {13            const zIndex = $el.getZIndex();14            expect(zIndex).to.equal('auto');15        });16    });17});18{19}20module.exports = (on, config) => {21};22{

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.getZIndex('div')2  .then((zIndex) => {3    console.log(zIndex);4  });5Cypress.Commands.add('getZIndex', (selector) => {6  return cy.get(selector)7    .then((element) => {8      return element.css('z-index');9    });10});11Cypress.Commands.add('getZIndex', (selector) => {12  return cy.get(selector)13    .then((element) => {14      return element.css('z-index');15    });16});17Cypress.Commands.add('getZIndex', (selector) => {18  return cy.get(selector)19    .then((element) => {20      return element.css('z-index');21    });22});23Cypress.Commands.add('getZIndex', (selector) => {24  return cy.get(selector)25    .then((element) => {26      return element.css('z-index');27    });28});29Cypress.Commands.add('getZIndex', (selector) => {30  return cy.get(selector)31    .then((element) => {32      return element.css('z-index');33    });34});35Cypress.Commands.add('getZIndex', (selector) => {36  return cy.get(selector)37    .then((element) => {38      return element.css('z-index');39    });40});41Cypress.Commands.add('getZIndex', (selector) => {42  return cy.get(selector)43    .then((element) => {44      return element.css('z-index');45    });46});47Cypress.Commands.add('getZIndex', (selector) => {48  return cy.get(selector)49    .then((element) => {50      return element.css('z-index');51    });52});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe("Test Z-Index of an element", () => {2  it("Z-Index of an element", () => {3    cy.get(".navbar").then(($navbar) => {4      cy.log("Z-Index of the navbar is: " + $navbar.getZIndex());5    });6  });7});8Cypress.Commands.add("getZIndex", { prevSubject: "element" }, ($element) => {9  const zIndex = $element.css("z-index");10  return parseInt(zIndex);11});

Full Screen

Using AI Code Generation

copy

Full Screen

1context('Z-Index', () => {2  beforeEach(() => {3  })4  it('Get Z-Index', () => {5    cy.get('#nav').then(($nav) => {6      const zIndex = Cypress.dom.getElementZIndex($nav)7      cy.log('Index: ' + zIndex)8    })9  })10})11{12}13describe('Z-Index', () => {14  beforeEach(() => {15  })16  it('Get Z-Index', () => {17    cy.get('#nav').then(($nav) => {18      const zIndex = Cypress.dom.getElementZIndex($nav)19      cy.log('Index: ' + zIndex)20    })21  })22})23{24}25describe('Z-Index', () => {26  beforeEach(() => {27  })28  it('Get Z-Index', () => {29    cy.get('#nav').then(($nav) => {30      const zIndex = Cypress.dom.getElementZIndex($nav)31      cy.log('Index: ' + zIndex)32    })33  })34})35{36}37describe('Z-Index', () => {38  beforeEach(() => {39  })40  it('Get Z-Index', () => {41    cy.get('#nav').then(($nav) => {42      const zIndex = Cypress.dom.getElementZIndex($nav)43      cy.log('Index: ' + zIndex)44    })45  })46})47{

Full Screen

Using AI Code Generation

copy

Full Screen

1cy.getZIndex('div')2cy.getZIndex('#div1')3cy.getZIndex('.div1')4cy.getZIndex('div')5cy.getZIndex('div.div1')6cy.getZIndex('div#div1')7cy.getZIndex('div#div1.div1')8MIT © [Anshul Singh](

Full Screen

Using AI Code Generation

copy

Full Screen

1import { getZIndex } from 'cypress-visual-regression/dist/command';2const zIndex = getZIndex('button', 'buttonText');3cy.log(zIndex);4import { addMatchImageSnapshotCommand } from 'cypress-visual-regression/dist/command';5addMatchImageSnapshotCommand();6import { getZIndex } from 'cypress-visual-regression/dist/command';7Cypress.Commands.add('getZIndex', getZIndex);8Cypress.Commands.add('getZIndex', getZIndex);9import './commands';

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Z-index', function() {2  it('Z-index of the element', function() {3    cy.get('.navbar').then(($navbar) => {4      const zIndex = Cypress.dom.getZIndex($navbar)5      expect(zIndex).to.equal(100)6    })7  })8})9describe('Z-index', function() {10  it('Z-index of the element', function() {11    cy.get('.navbar').then(($navbar) => {12      const zIndex = Cypress.dom.getZIndex($navbar)13      expect(zIndex).to.equal(100)14    })15  })16})

Full Screen

Cypress Tutorial

Cypress is a renowned Javascript-based open-source, easy-to-use end-to-end testing framework primarily used for testing web applications. Cypress is a relatively new player in the automation testing space and has been gaining much traction lately, as evidenced by the number of Forks (2.7K) and Stars (42.1K) for the project. LambdaTest’s Cypress Tutorial covers step-by-step guides that will help you learn from the basics till you run automation tests on LambdaTest.

Chapters:

  1. What is Cypress? -
  2. Why Cypress? - Learn why Cypress might be a good choice for testing your web applications.
  3. Features of Cypress Testing - Learn about features that make Cypress a powerful and flexible tool for testing web applications.
  4. Cypress Drawbacks - Although Cypress has many strengths, it has a few limitations that you should be aware of.
  5. Cypress Architecture - Learn more about Cypress architecture and how it is designed to be run directly in the browser, i.e., it does not have any additional servers.
  6. Browsers Supported by Cypress - Cypress is built on top of the Electron browser, supporting all modern web browsers. Learn browsers that support Cypress.
  7. Selenium vs Cypress: A Detailed Comparison - Compare and explore some key differences in terms of their design and features.
  8. Cypress Learning: Best Practices - Take a deep dive into some of the best practices you should use to avoid anti-patterns in your automation tests.
  9. How To Run Cypress Tests on LambdaTest? - Set up a LambdaTest account, and now you are all set to learn how to run Cypress tests.

Certification

You can elevate your expertise with end-to-end testing using the Cypress automation framework and stay one step ahead in your career by earning a Cypress certification. Check out our Cypress 101 Certification.

YouTube

Watch this 3 hours of complete tutorial to learn the basics of Cypress and various Cypress commands with the Cypress testing at LambdaTest.

Run Cypress automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful