From 7423983065bfa6712987489de4bb16ffa3862da2 Mon Sep 17 00:00:00 2001 From: "Jalal.Fathi" Date: Fri, 3 May 2019 13:39:52 +0200 Subject: [PATCH] Fiz nth --- commands.js | 3 ++- daywalker-store-query.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/commands.js b/commands.js index 2158e76..2d93152 100644 --- a/commands.js +++ b/commands.js @@ -42,9 +42,10 @@ Cypress.Commands.overwrite('get', (originalFn, selector, options) => { return cy.window({log: false}).then((w) => new Cypress.Promise((resolve, reject) => { const walker = new Daywalker(w); + const result = options && options.all ? walker.querySelectorAll(selector) - : walker.querySelector(selector, (options && options.nth) || 0); + : walker.querySelector(selector, (options && options.nth) || 1); if (result != null) { resolve(result); return true; diff --git a/daywalker-store-query.js b/daywalker-store-query.js index f6dfd01..2889516 100644 --- a/daywalker-store-query.js +++ b/daywalker-store-query.js @@ -12,10 +12,10 @@ class DaywalkerStoreQuery { return result; } - querySelector(selector, nth = 0) { + querySelector(selector, nth = 1) { const result = this.queryStore(selector); if (Array.isArray(result)) { - return result.length > nth ? result[nth] : null; + return result.length >= nth ? result[nth - 1] : null; } return result; }