From a4cd67880c7b66e1bb40a200fd7ff932452fae36 Mon Sep 17 00:00:00 2001 From: Arush Saxena Date: Thu, 12 Sep 2024 00:10:25 +0530 Subject: [PATCH 01/13] Adding smart ignore capability in SDK --- src/lib/constants.ts | 355 ++++++++++++++++++------------------ src/lib/ctx.ts | 9 +- src/lib/schemaValidation.ts | 60 +++--- src/types.ts | 9 +- 4 files changed, 220 insertions(+), 213 deletions(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index d9a8393..6699115 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -24,7 +24,8 @@ export default { }, waitForTimeout: 1000, enableJavaScript: false, - allowedHostnames: [] + allowedHostnames: [], + smartIgnore: false }, DEFAULT_WEB_STATIC_CONFIG: [ { @@ -83,188 +84,188 @@ export default { ], SUPPORTED_MOBILE_DEVICES: { - 'Blackberry KEY2 LE': { os: 'android', viewport: {width: 412, height: 618}}, - 'Galaxy A12': { os: 'android', viewport: {width: 360, height: 800}}, - 'Galaxy A21s': { os: 'android', viewport: {width: 412, height: 915}}, - 'Galaxy A22': { os: 'android', viewport: {width: 358, height: 857}}, - 'Galaxy A31': { os: 'android', viewport: {width: 412, height: 915}}, - 'Galaxy A32': { os: 'android', viewport: {width: 412, height: 915}}, - 'Galaxy A51': { os: 'android', viewport: {width: 412, height: 915}}, - 'Galaxy A7': { os: 'android', viewport: {width: 412, height: 846}}, - 'Galaxy A70': { os: 'android', viewport: {width: 412, height: 915}}, - 'Galaxy A8': { os: 'android', viewport: {width: 360, height: 740}}, - 'Galaxy A8 Plus': { os: 'android', viewport: {width: 412, height: 846}}, - 'Galaxy J7 Prime': { os: 'android', viewport: {width: 360, height: 640}}, - 'Galaxy M12': { os: 'android', viewport: {width: 412, height: 915}}, - 'Galaxy M31': { os: 'android', viewport: {width: 412, height: 892}}, - 'Galaxy Note10': { os: 'android', viewport: {width: 412, height: 869}}, - 'Galaxy Note10 Plus': { os: 'android', viewport: {width: 412, height: 869}}, - 'Galaxy Note20': { os: 'android', viewport: {width: 412, height: 915}}, - 'Galaxy Note20 Ultra': { os: 'android', viewport: {width: 412, height: 869}}, - 'Galaxy S10': { os: 'android', viewport: {width: 360, height: 760}}, - 'Galaxy S10 Plus': { os: 'android', viewport: {width: 412, height: 869}}, - 'Galaxy S10e': { os: 'android', viewport: {width: 412, height: 740}}, - 'Galaxy S20': { os: 'android', viewport: {width: 360, height: 800}}, - 'Galaxy S20 FE': { os: 'android', viewport: {width: 412, height: 914}}, - 'Galaxy S20 Ultra': { os: 'android', viewport: {width: 412, height: 915}}, - 'Galaxy S20 Plus': { os: 'android', viewport: {width: 384, height: 854}}, - 'Galaxy S21': { os: 'android', viewport: {width: 360, height: 800}}, - 'Galaxy S21 FE': { os: 'android', viewport: {width: 360, height: 780}}, - 'Galaxy S21 Ultra': { os: 'android', viewport: {width: 384, height: 854}}, - 'Galaxy S21 Plus': { os: 'android', viewport: {width: 360, height: 800}}, - 'Galaxy S22': { os: 'android', viewport: {width: 360, height: 780}}, - 'Galaxy S22 Ultra': { os: 'android', viewport: {width: 384, height: 854}}, - 'Galaxy S23': { os: 'android', viewport: {width: 360, height: 645}}, - 'Galaxy S23 Plus': { os: 'android', viewport: {width: 360, height: 648}}, - 'Galaxy S23 Ultra': { os: 'android', viewport: {width: 384, height: 689}}, - 'Galaxy S24': { os: 'android', viewport: {width: 360, height: 780}}, - 'Galaxy S24 Plus': { os: 'android', viewport: {width: 384, height: 832}}, - 'Galaxy S24 Ultra': { os: 'android', viewport: {width: 384, height: 832}}, - 'Galaxy S7': { os: 'android', viewport: {width: 360, height: 640}}, - 'Galaxy S7 Edge': { os: 'android', viewport: {width: 360, height: 640}}, - 'Galaxy S8': { os: 'android', viewport: {width: 360, height: 740}}, - 'Galaxy S8 Plus': { os: 'android', viewport: {width: 360, height: 740}}, - 'Galaxy S9': { os: 'android', viewport: {width: 360, height: 740}}, - 'Galaxy S9 Plus': { os: 'android', viewport: {width: 360, height: 740}}, - 'Galaxy Tab A7 Lite': { os: 'android', viewport: {width: 534, height: 894}}, - 'Galaxy Tab A8': { os: 'android', viewport: {width: 800, height: 1280}}, - 'Galaxy Tab S3': { os: 'android', viewport: {width: 1024, height: 768}}, - 'Galaxy Tab S4': { os: 'android', viewport: {width: 712, height: 1138}}, - 'Galaxy Tab S7': { os: 'android', viewport: {width: 800, height: 1192}}, - 'Galaxy Tab S8': { os: 'android', viewport: {width: 753, height: 1205}}, - 'Galaxy Tab S8 Plus': { os: 'android', viewport: {width: 825, height: 1318}}, - 'Huawei Mate 20 Pro': { os: 'android', viewport: {width: 360, height: 780}}, - 'Huawei P20 Pro': { os: 'android', viewport: {width: 360, height: 747}}, - 'Huawei P30': { os: 'android', viewport: {width: 360, height: 780}}, - 'Huawei P30 Pro': { os: 'android', viewport: {width: 360, height: 780}}, - 'Microsoft Surface Duo': { os: 'android', viewport: {width: 1114, height: 705}}, - 'Moto G7 Play': { os: 'android', viewport: {width: 360, height: 760}}, - 'Moto G9 Play': { os: 'android', viewport: {width: 393, height: 786}}, - 'Moto G Stylus (2022)': { os: 'android', viewport: {width: 432, height: 984}}, - 'Nexus 5': { os: 'android', viewport: {width: 360, height: 640}}, - 'Nexus 5X': { os: 'android', viewport: {width: 412, height: 732}}, - 'Nokia 5': { os: 'android', viewport: {width: 360, height: 640}}, - 'Nothing Phone (1)': { os: 'android', viewport: {width: 412, height: 915}}, - 'OnePlus 10 Pro': { os: 'android', viewport: {width: 412, height: 919}}, - 'OnePlus 11': { os: 'android', viewport: {width: 360, height: 804}}, - 'OnePlus 6': { os: 'android', viewport: {width: 412, height: 869}}, - 'OnePlus 6T': { os: 'android', viewport: {width: 412, height: 892}}, - 'OnePlus 7': { os: 'android', viewport: {width: 412, height: 892}}, - 'OnePlus 7T': { os: 'android', viewport: {width: 412, height: 914}}, - 'OnePlus 8': { os: 'android', viewport: {width: 412, height: 915}}, - 'OnePlus 9': { os: 'android', viewport: {width: 411, height: 915}}, - 'OnePlus 9 Pro': { os: 'android', viewport: {width: 412, height: 919}}, - 'OnePlus Nord': { os: 'android', viewport: {width: 412, height: 914}}, - 'OnePlus Nord 2': { os: 'android', viewport: {width: 412, height: 915}}, - 'OnePlus Nord CE': { os: 'android', viewport: {width: 412, height: 915}}, - 'Oppo A12': { os: 'android', viewport: {width: 360, height: 760}}, - 'Oppo A15': { os: 'android', viewport: {width: 360, height: 800}}, - 'Oppo A54': { os: 'android', viewport: {width: 360, height: 800}}, - 'Oppo A5s': { os: 'android', viewport: {width: 360, height: 760}}, - 'Oppo F17': { os: 'android', viewport: {width: 360, height: 800}}, - 'Oppo K10': { os: 'android', viewport: {width: 360, height: 804}}, - 'Pixel 3': { os: 'android', viewport: {width: 412, height: 823}}, - 'Pixel 3 XL': { os: 'android', viewport: {width: 412, height: 846}}, - 'Pixel 3a': { os: 'android', viewport: {width: 412, height: 823}}, - 'Pixel 4': { os: 'android', viewport: {width: 392, height: 830}}, - 'Pixel 4 XL': { os: 'android', viewport: {width: 412, height: 823}}, - 'Pixel 4a': { os: 'android', viewport: {width: 393, height: 851}}, - 'Pixel 5': { os: 'android', viewport: {width: 393, height: 851}}, - 'Pixel 6': { os: 'android', viewport: {width: 393, height: 786}}, - 'Pixel 6 Pro': { os: 'android', viewport: {width: 412, height: 892}}, - 'Pixel 7': { os: 'android', viewport: {width: 412, height: 915}}, - 'Pixel 7 Pro': { os: 'android', viewport: {width: 412, height: 892}}, - 'Pixel 8': { os: 'android', viewport: {width: 412, height: 915}}, - 'Pixel 8 Pro': { os: 'android', viewport: {width: 448, height: 998}}, - 'Poco M2 Pro': { os: 'android', viewport: {width: 393, height: 873}}, - 'POCO X3 Pro': { os: 'android', viewport: {width: 393, height: 873}}, - 'Realme 5i': { os: 'android', viewport: {width: 360, height: 800}}, - 'Realme 7i': { os: 'android', viewport: {width: 360, height: 800}}, - 'Realme 8i': { os: 'android', viewport: {width: 360, height: 804}}, - 'Realme C21Y': { os: 'android', viewport: {width: 360, height: 800}}, - 'Realme C21': { os: 'android', viewport: {width: 360, height: 800}}, - 'Realme GT2 Pro': { os: 'android', viewport: {width: 360, height: 804}}, - 'Redmi 8': { os: 'android', viewport: {width: 360, height: 760}}, - 'Redmi 9': { os: 'android', viewport: {width: 360, height: 800}}, - 'Redmi 9C': { os: 'android', viewport: {width: 360, height: 800}}, - 'Redmi Note 10 Pro': { os: 'android', viewport: {width: 393, height: 873}}, - 'Redmi Note 8': { os: 'android', viewport: {width: 393, height: 851}}, - 'Redmi Note 8 Pro': { os: 'android', viewport: {width: 393, height: 851}}, - 'Redmi Note 9': { os: 'android', viewport: {width: 393, height: 851}}, - 'Redmi Note 9 Pro Max': { os: 'android', viewport: {width: 393, height: 873}}, - 'Redmi Y2': { os: 'android', viewport: {width: 360, height: 720}}, - 'Tecno Spark 7': { os: 'android', viewport: {width: 360, height: 800}}, - 'Vivo Y22': { os: 'android', viewport: {width: 385, height: 860}}, - 'Vivo T1': { os: 'android', viewport: {width: 393, height: 873}}, - 'Vivo V7': { os: 'android', viewport: {width: 360, height: 720}}, - 'Vivo Y11': { os: 'android', viewport: {width: 360, height: 722}}, - 'Vivo Y12': { os: 'android', viewport: {width: 360, height: 722}}, - 'Vivo Y20g': { os: 'android', viewport: {width: 385, height: 854}}, - 'Vivo Y50': { os: 'android', viewport: {width: 393, height: 786}}, - 'Xiaomi 12 Pro': { os: 'android', viewport: {width: 412, height: 915}}, - 'Xperia Z5': { os: 'android', viewport: {width: 360, height: 640}}, - 'Xperia Z5 Dual': { os: 'android', viewport: {width: 360, height: 640}}, - 'Zenfone 6': { os: 'android', viewport: {width: 412, height: 892}}, - 'iPad 10.2 (2019)': { os: 'ios', viewport: {width: 810, height: 1080}}, - 'iPad 10.2 (2020)': { os: 'ios', viewport: {width: 834, height: 1194}}, - 'iPad 10.2 (2021)': { os: 'ios', viewport: {width: 810, height: 1080}}, - 'iPad 9.7 (2017)': { os: 'ios', viewport: {width: 768, height: 1024}}, - 'iPad Air (2019)': { os: 'ios', viewport: {width: 834, height: 1112}}, - 'iPad Air (2020)': { os: 'ios', viewport: {width: 820, height: 1180}}, - 'iPad Air (2022)': { os: 'ios', viewport: {width: 820, height: 1180}}, - 'iPad mini (2019)': { os: 'ios', viewport: {width: 768, height: 1024}}, - 'iPad mini (2021)': { os: 'ios', viewport: {width: 744, height: 1133}}, - 'iPad Pro 11 (2021)': { os: 'ios', viewport: {width: 834, height: 1194}}, - 'iPad Pro 11 (2022)': { os: 'ios', viewport: {width: 834, height: 1194}}, - 'iPad Pro 12.9 (2018)': { os: 'ios', viewport: {width: 1024, height: 1366}}, - 'iPad Pro 12.9 (2020)': { os: 'ios', viewport: {width: 1024, height: 1366}}, - 'iPad Pro 12.9 (2021)': { os: 'ios', viewport: {width: 1024, height: 1366}}, - 'iPad Pro 12.9 (2022)': { os: 'ios', viewport: {width: 1024, height: 1366}}, - 'iPhone 11': { os: 'ios', viewport: {width: 375, height: 812}}, - 'iPhone 11 Pro': { os: 'ios', viewport: {width: 375, height: 812}}, - 'iPhone 11 Pro Max': { os: 'ios', viewport: {width: 414, height: 896}}, - 'iPhone 12': { os: 'ios', viewport: {width: 390, height: 844}}, - 'iPhone 12 Mini': { os: 'ios', viewport: {width: 375, height: 812}}, - 'iPhone 12 Pro': { os: 'ios', viewport: {width: 390, height: 844}}, - 'iPhone 12 Pro Max': { os: 'ios', viewport: {width: 428, height: 926}}, - 'iPhone 13': { os: 'ios', viewport: {width: 390, height: 844}}, - 'iPhone 13 Mini': { os: 'ios', viewport: {width: 390, height: 844}}, - 'iPhone 13 Pro': { os: 'ios', viewport: {width: 390, height: 844}}, - 'iPhone 13 Pro Max': { os: 'ios', viewport: {width: 428, height: 926}}, - 'iPhone 14': { os: 'ios', viewport: {width: 390, height: 844}}, - 'iPhone 14 Plus': { os: 'ios', viewport: {width: 428, height: 926}}, - 'iPhone 14 Pro': { os: 'ios', viewport: {width: 390, height: 844}}, - 'iPhone 14 Pro Max': { os: 'ios', viewport: {width: 428, height: 928}}, - 'iPhone 15': { os: 'ios', viewport: {width: 393, height: 852}}, - 'iPhone 15 Plus': { os: 'ios', viewport: {width: 430, height: 932}}, - 'iPhone 15 Pro': { os: 'ios', viewport: {width: 393, height: 852}}, - 'iPhone 15 Pro Max': { os: 'ios', viewport: {width: 430, height: 932}}, - 'iPhone 6': { os: 'ios', viewport: {width: 375, height: 667}}, - 'iPhone 6s': { os: 'ios', viewport: {width: 375, height: 667}}, - 'iPhone 6s Plus': { os: 'ios', viewport: {width: 414, height: 736}}, - 'iPhone 7': { os: 'ios', viewport: {width: 375, height: 667}}, - 'iPhone 7 Plus': { os: 'ios', viewport: {width: 414, height: 736}}, - 'iPhone 8': { os: 'ios', viewport: {width: 375, height: 667}}, - 'iPhone 8 Plus': { os: 'ios', viewport: {width: 414, height: 736}}, - 'iPhone SE (2016)': { os: 'ios', viewport: {width: 320, height: 568}}, - 'iPhone SE (2020)': { os: 'ios', viewport: {width: 375, height: 667}}, - 'iPhone SE (2022)': { os: 'ios', viewport: {width: 375, height: 667}}, - 'iPhone X': { os: 'ios', viewport: {width: 375, height: 812}}, - 'iPhone XR': { os: 'ios', viewport: {width: 414, height: 896}}, - 'iPhone XS': { os: 'ios', viewport: {width: 375, height: 812}}, - 'iPhone XS Max': { os: 'ios', viewport: {width: 414, height: 896}}, + 'Blackberry KEY2 LE': { os: 'android', viewport: { width: 412, height: 618 } }, + 'Galaxy A12': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Galaxy A21s': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Galaxy A22': { os: 'android', viewport: { width: 358, height: 857 } }, + 'Galaxy A31': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Galaxy A32': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Galaxy A51': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Galaxy A7': { os: 'android', viewport: { width: 412, height: 846 } }, + 'Galaxy A70': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Galaxy A8': { os: 'android', viewport: { width: 360, height: 740 } }, + 'Galaxy A8 Plus': { os: 'android', viewport: { width: 412, height: 846 } }, + 'Galaxy J7 Prime': { os: 'android', viewport: { width: 360, height: 640 } }, + 'Galaxy M12': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Galaxy M31': { os: 'android', viewport: { width: 412, height: 892 } }, + 'Galaxy Note10': { os: 'android', viewport: { width: 412, height: 869 } }, + 'Galaxy Note10 Plus': { os: 'android', viewport: { width: 412, height: 869 } }, + 'Galaxy Note20': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Galaxy Note20 Ultra': { os: 'android', viewport: { width: 412, height: 869 } }, + 'Galaxy S10': { os: 'android', viewport: { width: 360, height: 760 } }, + 'Galaxy S10 Plus': { os: 'android', viewport: { width: 412, height: 869 } }, + 'Galaxy S10e': { os: 'android', viewport: { width: 412, height: 740 } }, + 'Galaxy S20': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Galaxy S20 FE': { os: 'android', viewport: { width: 412, height: 914 } }, + 'Galaxy S20 Ultra': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Galaxy S20 Plus': { os: 'android', viewport: { width: 384, height: 854 } }, + 'Galaxy S21': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Galaxy S21 FE': { os: 'android', viewport: { width: 360, height: 780 } }, + 'Galaxy S21 Ultra': { os: 'android', viewport: { width: 384, height: 854 } }, + 'Galaxy S21 Plus': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Galaxy S22': { os: 'android', viewport: { width: 360, height: 780 } }, + 'Galaxy S22 Ultra': { os: 'android', viewport: { width: 384, height: 854 } }, + 'Galaxy S23': { os: 'android', viewport: { width: 360, height: 645 } }, + 'Galaxy S23 Plus': { os: 'android', viewport: { width: 360, height: 648 } }, + 'Galaxy S23 Ultra': { os: 'android', viewport: { width: 384, height: 689 } }, + 'Galaxy S24': { os: 'android', viewport: { width: 360, height: 780 } }, + 'Galaxy S24 Plus': { os: 'android', viewport: { width: 384, height: 832 } }, + 'Galaxy S24 Ultra': { os: 'android', viewport: { width: 384, height: 832 } }, + 'Galaxy S7': { os: 'android', viewport: { width: 360, height: 640 } }, + 'Galaxy S7 Edge': { os: 'android', viewport: { width: 360, height: 640 } }, + 'Galaxy S8': { os: 'android', viewport: { width: 360, height: 740 } }, + 'Galaxy S8 Plus': { os: 'android', viewport: { width: 360, height: 740 } }, + 'Galaxy S9': { os: 'android', viewport: { width: 360, height: 740 } }, + 'Galaxy S9 Plus': { os: 'android', viewport: { width: 360, height: 740 } }, + 'Galaxy Tab A7 Lite': { os: 'android', viewport: { width: 534, height: 894 } }, + 'Galaxy Tab A8': { os: 'android', viewport: { width: 800, height: 1280 } }, + 'Galaxy Tab S3': { os: 'android', viewport: { width: 1024, height: 768 } }, + 'Galaxy Tab S4': { os: 'android', viewport: { width: 712, height: 1138 } }, + 'Galaxy Tab S7': { os: 'android', viewport: { width: 800, height: 1192 } }, + 'Galaxy Tab S8': { os: 'android', viewport: { width: 753, height: 1205 } }, + 'Galaxy Tab S8 Plus': { os: 'android', viewport: { width: 825, height: 1318 } }, + 'Huawei Mate 20 Pro': { os: 'android', viewport: { width: 360, height: 780 } }, + 'Huawei P20 Pro': { os: 'android', viewport: { width: 360, height: 747 } }, + 'Huawei P30': { os: 'android', viewport: { width: 360, height: 780 } }, + 'Huawei P30 Pro': { os: 'android', viewport: { width: 360, height: 780 } }, + 'Microsoft Surface Duo': { os: 'android', viewport: { width: 1114, height: 705 } }, + 'Moto G7 Play': { os: 'android', viewport: { width: 360, height: 760 } }, + 'Moto G9 Play': { os: 'android', viewport: { width: 393, height: 786 } }, + 'Moto G Stylus (2022)': { os: 'android', viewport: { width: 432, height: 984 } }, + 'Nexus 5': { os: 'android', viewport: { width: 360, height: 640 } }, + 'Nexus 5X': { os: 'android', viewport: { width: 412, height: 732 } }, + 'Nokia 5': { os: 'android', viewport: { width: 360, height: 640 } }, + 'Nothing Phone (1)': { os: 'android', viewport: { width: 412, height: 915 } }, + 'OnePlus 10 Pro': { os: 'android', viewport: { width: 412, height: 919 } }, + 'OnePlus 11': { os: 'android', viewport: { width: 360, height: 804 } }, + 'OnePlus 6': { os: 'android', viewport: { width: 412, height: 869 } }, + 'OnePlus 6T': { os: 'android', viewport: { width: 412, height: 892 } }, + 'OnePlus 7': { os: 'android', viewport: { width: 412, height: 892 } }, + 'OnePlus 7T': { os: 'android', viewport: { width: 412, height: 914 } }, + 'OnePlus 8': { os: 'android', viewport: { width: 412, height: 915 } }, + 'OnePlus 9': { os: 'android', viewport: { width: 411, height: 915 } }, + 'OnePlus 9 Pro': { os: 'android', viewport: { width: 412, height: 919 } }, + 'OnePlus Nord': { os: 'android', viewport: { width: 412, height: 914 } }, + 'OnePlus Nord 2': { os: 'android', viewport: { width: 412, height: 915 } }, + 'OnePlus Nord CE': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Oppo A12': { os: 'android', viewport: { width: 360, height: 760 } }, + 'Oppo A15': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Oppo A54': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Oppo A5s': { os: 'android', viewport: { width: 360, height: 760 } }, + 'Oppo F17': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Oppo K10': { os: 'android', viewport: { width: 360, height: 804 } }, + 'Pixel 3': { os: 'android', viewport: { width: 412, height: 823 } }, + 'Pixel 3 XL': { os: 'android', viewport: { width: 412, height: 846 } }, + 'Pixel 3a': { os: 'android', viewport: { width: 412, height: 823 } }, + 'Pixel 4': { os: 'android', viewport: { width: 392, height: 830 } }, + 'Pixel 4 XL': { os: 'android', viewport: { width: 412, height: 823 } }, + 'Pixel 4a': { os: 'android', viewport: { width: 393, height: 851 } }, + 'Pixel 5': { os: 'android', viewport: { width: 393, height: 851 } }, + 'Pixel 6': { os: 'android', viewport: { width: 393, height: 786 } }, + 'Pixel 6 Pro': { os: 'android', viewport: { width: 412, height: 892 } }, + 'Pixel 7': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Pixel 7 Pro': { os: 'android', viewport: { width: 412, height: 892 } }, + 'Pixel 8': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Pixel 8 Pro': { os: 'android', viewport: { width: 448, height: 998 } }, + 'Poco M2 Pro': { os: 'android', viewport: { width: 393, height: 873 } }, + 'POCO X3 Pro': { os: 'android', viewport: { width: 393, height: 873 } }, + 'Realme 5i': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Realme 7i': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Realme 8i': { os: 'android', viewport: { width: 360, height: 804 } }, + 'Realme C21Y': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Realme C21': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Realme GT2 Pro': { os: 'android', viewport: { width: 360, height: 804 } }, + 'Redmi 8': { os: 'android', viewport: { width: 360, height: 760 } }, + 'Redmi 9': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Redmi 9C': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Redmi Note 10 Pro': { os: 'android', viewport: { width: 393, height: 873 } }, + 'Redmi Note 8': { os: 'android', viewport: { width: 393, height: 851 } }, + 'Redmi Note 8 Pro': { os: 'android', viewport: { width: 393, height: 851 } }, + 'Redmi Note 9': { os: 'android', viewport: { width: 393, height: 851 } }, + 'Redmi Note 9 Pro Max': { os: 'android', viewport: { width: 393, height: 873 } }, + 'Redmi Y2': { os: 'android', viewport: { width: 360, height: 720 } }, + 'Tecno Spark 7': { os: 'android', viewport: { width: 360, height: 800 } }, + 'Vivo Y22': { os: 'android', viewport: { width: 385, height: 860 } }, + 'Vivo T1': { os: 'android', viewport: { width: 393, height: 873 } }, + 'Vivo V7': { os: 'android', viewport: { width: 360, height: 720 } }, + 'Vivo Y11': { os: 'android', viewport: { width: 360, height: 722 } }, + 'Vivo Y12': { os: 'android', viewport: { width: 360, height: 722 } }, + 'Vivo Y20g': { os: 'android', viewport: { width: 385, height: 854 } }, + 'Vivo Y50': { os: 'android', viewport: { width: 393, height: 786 } }, + 'Xiaomi 12 Pro': { os: 'android', viewport: { width: 412, height: 915 } }, + 'Xperia Z5': { os: 'android', viewport: { width: 360, height: 640 } }, + 'Xperia Z5 Dual': { os: 'android', viewport: { width: 360, height: 640 } }, + 'Zenfone 6': { os: 'android', viewport: { width: 412, height: 892 } }, + 'iPad 10.2 (2019)': { os: 'ios', viewport: { width: 810, height: 1080 } }, + 'iPad 10.2 (2020)': { os: 'ios', viewport: { width: 834, height: 1194 } }, + 'iPad 10.2 (2021)': { os: 'ios', viewport: { width: 810, height: 1080 } }, + 'iPad 9.7 (2017)': { os: 'ios', viewport: { width: 768, height: 1024 } }, + 'iPad Air (2019)': { os: 'ios', viewport: { width: 834, height: 1112 } }, + 'iPad Air (2020)': { os: 'ios', viewport: { width: 820, height: 1180 } }, + 'iPad Air (2022)': { os: 'ios', viewport: { width: 820, height: 1180 } }, + 'iPad mini (2019)': { os: 'ios', viewport: { width: 768, height: 1024 } }, + 'iPad mini (2021)': { os: 'ios', viewport: { width: 744, height: 1133 } }, + 'iPad Pro 11 (2021)': { os: 'ios', viewport: { width: 834, height: 1194 } }, + 'iPad Pro 11 (2022)': { os: 'ios', viewport: { width: 834, height: 1194 } }, + 'iPad Pro 12.9 (2018)': { os: 'ios', viewport: { width: 1024, height: 1366 } }, + 'iPad Pro 12.9 (2020)': { os: 'ios', viewport: { width: 1024, height: 1366 } }, + 'iPad Pro 12.9 (2021)': { os: 'ios', viewport: { width: 1024, height: 1366 } }, + 'iPad Pro 12.9 (2022)': { os: 'ios', viewport: { width: 1024, height: 1366 } }, + 'iPhone 11': { os: 'ios', viewport: { width: 375, height: 812 } }, + 'iPhone 11 Pro': { os: 'ios', viewport: { width: 375, height: 812 } }, + 'iPhone 11 Pro Max': { os: 'ios', viewport: { width: 414, height: 896 } }, + 'iPhone 12': { os: 'ios', viewport: { width: 390, height: 844 } }, + 'iPhone 12 Mini': { os: 'ios', viewport: { width: 375, height: 812 } }, + 'iPhone 12 Pro': { os: 'ios', viewport: { width: 390, height: 844 } }, + 'iPhone 12 Pro Max': { os: 'ios', viewport: { width: 428, height: 926 } }, + 'iPhone 13': { os: 'ios', viewport: { width: 390, height: 844 } }, + 'iPhone 13 Mini': { os: 'ios', viewport: { width: 390, height: 844 } }, + 'iPhone 13 Pro': { os: 'ios', viewport: { width: 390, height: 844 } }, + 'iPhone 13 Pro Max': { os: 'ios', viewport: { width: 428, height: 926 } }, + 'iPhone 14': { os: 'ios', viewport: { width: 390, height: 844 } }, + 'iPhone 14 Plus': { os: 'ios', viewport: { width: 428, height: 926 } }, + 'iPhone 14 Pro': { os: 'ios', viewport: { width: 390, height: 844 } }, + 'iPhone 14 Pro Max': { os: 'ios', viewport: { width: 428, height: 928 } }, + 'iPhone 15': { os: 'ios', viewport: { width: 393, height: 852 } }, + 'iPhone 15 Plus': { os: 'ios', viewport: { width: 430, height: 932 } }, + 'iPhone 15 Pro': { os: 'ios', viewport: { width: 393, height: 852 } }, + 'iPhone 15 Pro Max': { os: 'ios', viewport: { width: 430, height: 932 } }, + 'iPhone 6': { os: 'ios', viewport: { width: 375, height: 667 } }, + 'iPhone 6s': { os: 'ios', viewport: { width: 375, height: 667 } }, + 'iPhone 6s Plus': { os: 'ios', viewport: { width: 414, height: 736 } }, + 'iPhone 7': { os: 'ios', viewport: { width: 375, height: 667 } }, + 'iPhone 7 Plus': { os: 'ios', viewport: { width: 414, height: 736 } }, + 'iPhone 8': { os: 'ios', viewport: { width: 375, height: 667 } }, + 'iPhone 8 Plus': { os: 'ios', viewport: { width: 414, height: 736 } }, + 'iPhone SE (2016)': { os: 'ios', viewport: { width: 320, height: 568 } }, + 'iPhone SE (2020)': { os: 'ios', viewport: { width: 375, height: 667 } }, + 'iPhone SE (2022)': { os: 'ios', viewport: { width: 375, height: 667 } }, + 'iPhone X': { os: 'ios', viewport: { width: 375, height: 812 } }, + 'iPhone XR': { os: 'ios', viewport: { width: 414, height: 896 } }, + 'iPhone XS': { os: 'ios', viewport: { width: 375, height: 812 } }, + 'iPhone XS Max': { os: 'ios', viewport: { width: 414, height: 896 } }, }, - FIGMA_API : 'https://api.figma.com/v1/', + FIGMA_API: 'https://api.figma.com/v1/', DEFAULT_FIGMA_CONFIG: { "depth": 2, "figma_config": [ { - "figma_file_token": "token_for_first_figma_file", - "figma_ids": [ - "id1", - "id2" - ] + "figma_file_token": "token_for_first_figma_file", + "figma_ids": [ + "id1", + "id2" + ] } ] } diff --git a/src/lib/ctx.ts b/src/lib/ctx.ts index 49d328e..7857435 100644 --- a/src/lib/ctx.ts +++ b/src/lib/ctx.ts @@ -47,8 +47,8 @@ export default (options: Record): Context => { } if (config.web) { - webConfig = {browsers: config.web.browsers, viewports: []}; - for (let viewport of config.web?.viewports) webConfig.viewports.push({ width: viewport[0], height: viewport[1] || 0}); + webConfig = { browsers: config.web.browsers, viewports: [] }; + for (let viewport of config.web?.viewports) webConfig.viewports.push({ width: viewport[0], height: viewport[1] || 0 }); } if (config.mobile) { mobileConfig = { @@ -57,7 +57,7 @@ export default (options: Record): Context => { orientation: config.mobile.orientation || constants.MOBILE_ORIENTATION_PORTRAIT, } } - if (config.basicAuthorization){ + if (config.basicAuthorization) { basicAuthObj = config.basicAuthorization } @@ -74,7 +74,8 @@ export default (options: Record): Context => { cliEnableJavaScript: config.cliEnableJavaScript || true, scrollTime: config.scrollTime || constants.DEFAULT_SCROLL_TIME, allowedHostnames: config.allowedHostnames || [], - basicAuthorization: basicAuthObj + basicAuthorization: basicAuthObj, + smartIgnore: config.smartIgnore ?? false }, uploadFilePath: '', webStaticConfig: [], diff --git a/src/lib/schemaValidation.ts b/src/lib/schemaValidation.ts index 0241ea4..521c4b0 100644 --- a/src/lib/schemaValidation.ts +++ b/src/lib/schemaValidation.ts @@ -21,19 +21,19 @@ const ConfigSchema = { type: "object", properties: { web: { - type: "object", - properties: { - browsers: { - type: "array", - items: { type: "string", enum: [constants.CHROME, constants.FIREFOX, constants.SAFARI, constants.EDGE] }, - uniqueItems: true, - maxItems: 4, + type: "object", + properties: { + browsers: { + type: "array", + items: { type: "string", enum: [constants.CHROME, constants.FIREFOX, constants.SAFARI, constants.EDGE] }, + uniqueItems: true, + maxItems: 4, errorMessage: `Invalid config; allowed browsers - ${constants.CHROME}, ${constants.FIREFOX}, ${constants.SAFARI}, ${constants.EDGE}` - }, - viewports: { - type: "array", - items: { - type: "array", + }, + viewports: { + type: "array", + items: { + type: "array", oneOf: [ { items: [{ type: "number", minimum: 320, maximum: 7680 }], @@ -43,22 +43,22 @@ const ConfigSchema = { { items: [ { type: "number", minimum: 320, maximum: 7680 }, - { type: "number", minimum: 320, maximum: 7680 } + { type: "number", minimum: 320, maximum: 7680 } ], minItems: 2, maxItems: 2 } ], errorMessage: "Invalid config; width/height must be >= 320 and <= 7680" - }, - uniqueItems: true, - maxItems: 5, + }, + uniqueItems: true, + maxItems: 5, errorMessage: "Invalid config; max unique viewports allowed - 5" - } - }, - required: ["browsers", "viewports"], - additionalProperties: false - }, + } + }, + required: ["browsers", "viewports"], + additionalProperties: false + }, mobile: { type: "object", properties: { @@ -74,7 +74,7 @@ const ConfigSchema = { } }, uniqueItems: true, - maxItems: 20, + maxItems: 20, errorMessage: { uniqueItems: "Invalid config; duplicate mobile devices", maxItems: "Invalid config; max mobile devices allowed - 20" @@ -113,6 +113,10 @@ const ConfigSchema = { type: "boolean", errorMessage: "Invalid config; cliEnableJavaScript must be true/false" }, + smartIgnore: { + type: "boolean", + errorMessage: "Invalid config; smartIgnore must be true/false" + }, scrollTime: { type: "number", minimum: 1, @@ -142,7 +146,7 @@ const ConfigSchema = { errorMessage: "Invalid config; username is mandatory" }, password: { - type: "string", + type: "string", errorMessage: "Invalid config; password is mandatory" }, } @@ -166,7 +170,7 @@ const WebStaticConfigSchema: JSONSchemaType = { errorMessage: "name is mandatory and cannot be empty" }, url: { - type: "string", + type: "string", format: "web-url", errorMessage: "url is mandatory and must be a valid web URL" }, @@ -179,7 +183,7 @@ const WebStaticConfigSchema: JSONSchemaType = { }, }, required: ["name", "url"], - additionalProperties: false + additionalProperties: false }, uniqueItems: true } @@ -193,7 +197,7 @@ const SnapshotSchema: JSONSchemaType = { errorMessage: "Invalid snapshot; name is mandatory and cannot be empty" }, url: { - type: "string", + type: "string", format: "web-url", errorMessage: "Invalid snapshot; url is mandatory and must be a valid web URL" }, @@ -254,7 +258,7 @@ const SnapshotSchema: JSONSchemaType = { items: { type: "string", minLength: 1 }, uniqueItems: true, errorMessage: "Invalid snapshot options; ignoreDOM xpath array must have unique and non-empty items" - }, + }, } }, selectDOM: { @@ -283,7 +287,7 @@ const SnapshotSchema: JSONSchemaType = { items: { type: "string", minLength: 1 }, uniqueItems: true, errorMessage: "Invalid snapshot options; selectDOM xpath array must have unique and non-empty items" - }, + }, } } }, diff --git a/src/types.ts b/src/types.ts index acf048c..5f12883 100644 --- a/src/types.ts +++ b/src/types.ts @@ -23,7 +23,8 @@ export interface Context { cliEnableJavaScript: boolean; scrollTime: number; allowedHostnames: Array; - basicAuthorization: basicAuth | undefined + basicAuthorization: basicAuth | undefined; + smartIgnore: boolean; }; uploadFilePath: string; webStaticConfig: WebStaticConfig; @@ -57,8 +58,8 @@ export interface Env { HTTPS_PROXY: string | undefined; GITHUB_ACTIONS: string | undefined; FIGMA_TOKEN: string | undefined; - LT_USERNAME : string | undefined; - LT_ACCESS_KEY : string | undefined; + LT_USERNAME: string | undefined; + LT_ACCESS_KEY: string | undefined; BASELINE_BRANCH: string | undefined; CURRENT_BRANCH: string | undefined; } @@ -118,7 +119,7 @@ export interface Build { export interface WebConfig { browsers: Array; - viewports: Array<{width: number, height: number}>; + viewports: Array<{ width: number, height: number }>; } export interface MobileConfig { From e3d304bcb88256ebb3990b68190cd2bd83a6f0d2 Mon Sep 17 00:00:00 2001 From: parthlambdatest Date: Thu, 26 Sep 2024 20:46:04 +0530 Subject: [PATCH 02/13] add support for web and mobile in options --- src/lib/processSnapshot.ts | 40 +++++++++++++++++++++++++ src/lib/schemaValidation.ts | 58 +++++++++++++++++++++++++++++++++++++ src/types.ts | 9 ++++++ 3 files changed, 107 insertions(+) diff --git a/src/lib/processSnapshot.ts b/src/lib/processSnapshot.ts index b7ba433..9dacd66 100644 --- a/src/lib/processSnapshot.ts +++ b/src/lib/processSnapshot.ts @@ -225,6 +225,45 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise 0) { + processedOptions.web.viewports = options.web.viewports.filter(viewport => + Array.isArray(viewport) && viewport.length > 0 + ); + } + + // Check and process browsers in web + if (options.web.browsers && Array.isArray(options.web.browsers) && options.web.browsers.length > 0) { + processedOptions.web.browsers = options.web.browsers; + } + } + + if (options.mobile && Object.keys(options.mobile).length) { + processedOptions.mobile = {}; + + // Check and process devices in mobile + if (options.mobile.devices && Array.isArray(options.mobile.devices) && options.mobile.devices.length > 0) { + processedOptions.mobile.devices = options.mobile.devices; + } + + // Check if 'fullPage' is provided and is a boolean, otherwise set default to true + if ('fullPage' in options.mobile && typeof options.mobile.fullPage === 'boolean') { + processedOptions.mobile.fullPage = options.mobile.fullPage; + } else { + processedOptions.mobile.fullPage = true; // Default value for fullPage + } + + // Check if 'orientation' is provided and is valid, otherwise set default to 'portrait' + if ('orientation' in options.mobile && (options.mobile.orientation === 'portrait' || options.mobile.orientation === 'landscape')) { + processedOptions.mobile.orientation = options.mobile.orientation; + } else { + processedOptions.mobile.orientation = 'portrait'; // Default value for orientation + } + } + if (options.element && Object.keys(options.element).length) { if (options.element.id) processedOptions.element = '#' + options.element.id; else if (options.element.class) processedOptions.element = '.' + options.element.class; @@ -334,6 +373,7 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise = { errorMessage: "Invalid snapshot options; selectDOM xpath array must have unique and non-empty items" }, } + }, + web: { + type: "object", + properties: { + browsers: { + type: "array", + items: { + type: "string", + enum: [constants.CHROME, constants.FIREFOX, constants.SAFARI, constants.EDGE], + minLength: 1 + }, + uniqueItems: true, + errorMessage: `Invalid snapshot options; allowed browsers - ${constants.CHROME}, ${constants.FIREFOX}, ${constants.SAFARI}, ${constants.EDGE}` + }, + viewports: { + type: "array", + items: { + type: "array", + items: { + type: "number", + minimum: 1 + }, + minItems: 1, + maxItems: 2, + errorMessage: "Invalid snapshot options; each viewport array must contain either a single width or a width and height tuple with positive values." + }, + uniqueItems: true, + errorMessage: "Invalid snapshot options; viewports must be an array of unique arrays." + } + }, + required: ["browsers", "viewports"], + errorMessage: "Invalid snapshot options; web must include both browsers and viewports properties." + }, + mobile: { + type: "object", + properties: { + devices: { + type: "array", + items: { + type: "string", + enum: Object.keys(constants.SUPPORTED_MOBILE_DEVICES), + minLength: 1 + }, + uniqueItems: true, + errorMessage: "Invalid snapshot options; devices must be an array of unique supported mobile devices." + }, + fullPage: { + type: "boolean", + errorMessage: "Invalid snapshot options; fullPage must be a boolean." + }, + orientation: { + type: "string", + enum: [constants.MOBILE_ORIENTATION_PORTRAIT, constants.MOBILE_ORIENTATION_LANDSCAPE], + errorMessage: "Invalid snapshot options; orientation must be either 'portrait' or 'landscape'." + } + }, + required: ["devices"], + errorMessage: "Invalid snapshot options; mobile must include devices property." } }, additionalProperties: false diff --git a/src/types.ts b/src/types.ts index acf048c..65b4145 100644 --- a/src/types.ts +++ b/src/types.ts @@ -85,6 +85,15 @@ export interface Snapshot { class?: string, cssSelector?: string, xpath?: string + }, + web?: { + browsers: string[], + viewports: ([number] | [number, number])[] + }, + mobile?: { + devices: string[], + fullPage?: boolean, + orientation?: string } } } From 947ed56741b7557ea2b0fc5ac386c01b02ca5ebc Mon Sep 17 00:00:00 2001 From: parthlambdatest Date: Fri, 27 Sep 2024 13:23:59 +0530 Subject: [PATCH 03/13] make browsers in web as optional argument --- src/lib/schemaValidation.ts | 4 ++-- src/types.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/schemaValidation.ts b/src/lib/schemaValidation.ts index a743692..b1b88da 100644 --- a/src/lib/schemaValidation.ts +++ b/src/lib/schemaValidation.ts @@ -315,8 +315,8 @@ const SnapshotSchema: JSONSchemaType = { errorMessage: "Invalid snapshot options; viewports must be an array of unique arrays." } }, - required: ["browsers", "viewports"], - errorMessage: "Invalid snapshot options; web must include both browsers and viewports properties." + required: ["viewports"], + errorMessage: "Invalid snapshot options; web must include viewports property." }, mobile: { type: "object", diff --git a/src/types.ts b/src/types.ts index 65b4145..5102b68 100644 --- a/src/types.ts +++ b/src/types.ts @@ -87,7 +87,7 @@ export interface Snapshot { xpath?: string }, web?: { - browsers: string[], + browsers?: string[], viewports: ([number] | [number, number])[] }, mobile?: { From 9e295438dcd3d3f332bb1b85bbb5399f9120be70 Mon Sep 17 00:00:00 2001 From: parthlambdatest Date: Fri, 27 Sep 2024 15:36:51 +0530 Subject: [PATCH 04/13] used hasownproperty instead of in --- src/lib/processSnapshot.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/processSnapshot.ts b/src/lib/processSnapshot.ts index 9dacd66..fac929b 100644 --- a/src/lib/processSnapshot.ts +++ b/src/lib/processSnapshot.ts @@ -229,14 +229,14 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise 0) { + if (options.web.viewports && options.web.viewports.length > 0) { processedOptions.web.viewports = options.web.viewports.filter(viewport => Array.isArray(viewport) && viewport.length > 0 ); } // Check and process browsers in web - if (options.web.browsers && Array.isArray(options.web.browsers) && options.web.browsers.length > 0) { + if (options.web.browsers && options.web.browsers.length > 0) { processedOptions.web.browsers = options.web.browsers; } } @@ -245,19 +245,19 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise 0) { + if (options.mobile.devices && options.mobile.devices.length > 0) { processedOptions.mobile.devices = options.mobile.devices; } // Check if 'fullPage' is provided and is a boolean, otherwise set default to true - if ('fullPage' in options.mobile && typeof options.mobile.fullPage === 'boolean') { + if (options.mobile.hasOwnProperty('fullPage') && typeof options.mobile.fullPage === 'boolean') { processedOptions.mobile.fullPage = options.mobile.fullPage; } else { processedOptions.mobile.fullPage = true; // Default value for fullPage } // Check if 'orientation' is provided and is valid, otherwise set default to 'portrait' - if ('orientation' in options.mobile && (options.mobile.orientation === 'portrait' || options.mobile.orientation === 'landscape')) { + if (options.mobile.hasOwnProperty('orientation') && (options.mobile.orientation === 'portrait' || options.mobile.orientation === 'landscape')) { processedOptions.mobile.orientation = options.mobile.orientation; } else { processedOptions.mobile.orientation = 'portrait'; // Default value for orientation From 28febed26162dc8704df82515c09b0d5c26e3c8d Mon Sep 17 00:00:00 2001 From: JeeveshJ7 Date: Tue, 1 Oct 2024 20:08:37 +0530 Subject: [PATCH 05/13] Added Readme --- packages/cli/README.md | 78 ++++++++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/packages/cli/README.md b/packages/cli/README.md index 53e3230..19a6500 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -1,47 +1,65 @@ -# SmartUI CLI -[![SmartUI-Testing](https://smartui.lambdatest.com/static/media/LTBadge.64a05e73.svg)](https://smartui.lambdatest.com) +# SmartUI-CLI -The SmartUI CLI is used to create configs, take screenshots and upload to [SmartUI Dashboard](https://smartui.lambdatest.com/) via -the command line. + + +

+ Blog +   ⋅   + Docs +   ⋅   + Learning Hub +   ⋅   + Newsletter +   ⋅   + Certifications +   ⋅   + YouTube +

+  +  +  + + + +[](https://accounts.lambdatest.com/register?utm_source=github&utm_medium=repo&utm_campaign=playwright-sample) + + +The **SmartUI-CLI** allows you to capture visual snapshots of your web applications, upload images, and run visual regression tests using [LambdaTest's SmartUI](https://www.lambdatest.com/visual-regression-testing) platform directly from the command line. - [Installation](#installation) -- [Start using CLI](#start-using-cli) +- [Commands](#commands) +- [Documentation](#documentation) +- [Issues](#issues) ## Installation ```sh-session -$ npm install -g @lambdatest/smartui-cli --force +$ npm install smartui-cli ``` -## Start using CLI +## Commands +- `npx smartui exec` - Capture DOM assets for visual testing across multiple browsers and resolutions. +- `npx smartui capture` - Bulk capture static URLs for visual testing. +- `npx smartui upload` - Upload custom images or screenshots for visual comparison. +- `npx smartui upload-figma` - Upload Figma design images for visual comparison. +- `npx smartui config` - Creates configuration file according to the usecase. -#### Create URL Json file -```sh-session -$ smartui config:web-static urls.json -``` +### Documentation -#### Create custom Web Config file -```sh-session -$ smartui config:create-web smartui-web.json -``` +In addition to its core functionalities, the SmartUI CLI leverages LambdaTest's cloud infrastructure for robust, scalable visual regression testing across various browsers and devices. -#### Configure your Project Token +- [SmartUI Selenium SDK](https://www.lambdatest.com/support/docs/smartui-selenium-java-sdk) - A complete SDK to capture DOM assets for visual tests. +- [LambdaTest Documentation](https://www.lambdatest.com/support/docs/) - Official LambdaTest documentation for SmartUI and other integrations. +- [Bulk capturing static URLs with SmartUI](https://www.lambdatest.com/support/docs/smartui-cli/) - Documentation for capturing satatic urls in bulk with SmartUI +- [Bring your own screenshots](https://www.lambdatest.com/support/docs/smartui-cli-upload/) - Documentation for capturing satatic urls in bulk +- [Figma CLI](https://www.lambdatest.com/support/docs/smartui-cli-figma/) - Documentation for uploading figma components to SmartUI -Create a new web project from [SmartUI Dashboard](https://smartui.lambdatest.com/) and copy the project token and set on CLI via command +### Issues -For Linux/macOS: +If you encounter problems with SmartUI-CLI, [add an issue on GitHub](https://github.com/LambdaTest/smartui-cli/issues/new). -``` - export PROJECT_TOKEN="****-****-****-************" -``` +For other support issues, reach out via [LambdaTest Support](https://www.lambdatest.com/support). -For Windows: +------ -``` - set PROJECT_TOKEN="****-****-****-************" -``` - -#### Capture Screenshots -```sh-session -$ smartui capture urls.json --config smartui-web.json -``` +[Know more](https://www.lambdatest.com/visual-regression-testing) about SmartUI and it's AI enabled comparison engines. From ce76fc09441196d5ddee4ee288051ce5451430b8 Mon Sep 17 00:00:00 2001 From: JeeveshJ7 Date: Wed, 2 Oct 2024 11:12:52 +0530 Subject: [PATCH 06/13] Readme updated with node version note --- packages/cli/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/cli/README.md b/packages/cli/README.md index 19a6500..af08465 100644 --- a/packages/cli/README.md +++ b/packages/cli/README.md @@ -37,6 +37,9 @@ The **SmartUI-CLI** allows you to capture visual snapshots of your web applicati $ npm install smartui-cli ``` +**Note:** +If you face any problems executing tests with SmartUI-CLI `versions >= v4.x.x`, upgrade your Node.js version to `v20.3` or above. + ## Commands - `npx smartui exec` - Capture DOM assets for visual testing across multiple browsers and resolutions. - `npx smartui capture` - Bulk capture static URLs for visual testing. From 174d5a4e8930fa32ec466fd569d150cc02d3dd2d Mon Sep 17 00:00:00 2001 From: Pinank Solanki Date: Mon, 7 Oct 2024 17:04:08 +0530 Subject: [PATCH 07/13] Add env variable SMARTUI_DO_NOT_USE_CAPTURED_COOKIES --- src/lib/env.ts | 6 ++++-- src/lib/logger.ts | 2 +- src/types.ts | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib/env.ts b/src/lib/env.ts index 6fbe377..f12d558 100644 --- a/src/lib/env.ts +++ b/src/lib/env.ts @@ -4,14 +4,15 @@ export default (): Env => { const { PROJECT_TOKEN = '', SMARTUI_CLIENT_API_URL = 'https://api.lambdatest.com/visualui/1.0', - LT_SDK_DEBUG, SMARTUI_GIT_INFO_FILEPATH, + SMARTUI_DO_NOT_USE_CAPTURED_COOKIES, HTTP_PROXY, HTTPS_PROXY, GITHUB_ACTIONS, FIGMA_TOKEN, LT_USERNAME, LT_ACCESS_KEY, + LT_SDK_DEBUG, BASELINE_BRANCH, CURRENT_BRANCH } = process.env @@ -19,7 +20,6 @@ export default (): Env => { return { PROJECT_TOKEN, SMARTUI_CLIENT_API_URL, - LT_SDK_DEBUG, SMARTUI_GIT_INFO_FILEPATH, HTTP_PROXY, HTTPS_PROXY, @@ -29,5 +29,7 @@ export default (): Env => { LT_ACCESS_KEY, BASELINE_BRANCH, CURRENT_BRANCH, + LT_SDK_DEBUG: LT_SDK_DEBUG === 'true', + SMARTUI_DO_NOT_USE_CAPTURED_COOKIES: SMARTUI_DO_NOT_USE_CAPTURED_COOKIES === 'true' } } diff --git a/src/lib/logger.ts b/src/lib/logger.ts index a55d54b..b3d109a 100644 --- a/src/lib/logger.ts +++ b/src/lib/logger.ts @@ -17,7 +17,7 @@ export function updateLogContext(newContext: LogContext) { const logLevel = (): string => { let env: Env = getEnv(); - return (env.LT_SDK_DEBUG === 'true') ? 'debug' : 'info'; + return (env.LT_SDK_DEBUG) ? 'debug' : 'info'; } // Create a Winston logger diff --git a/src/types.ts b/src/types.ts index acf048c..f8598b9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -51,7 +51,7 @@ export interface Context { export interface Env { PROJECT_TOKEN: string; SMARTUI_CLIENT_API_URL: string; - LT_SDK_DEBUG: string | undefined; + SMARTUI_DO_NOT_USE_CAPTURED_COOKIES: boolean; SMARTUI_GIT_INFO_FILEPATH: string | undefined; HTTP_PROXY: string | undefined; HTTPS_PROXY: string | undefined; @@ -59,6 +59,7 @@ export interface Env { FIGMA_TOKEN: string | undefined; LT_USERNAME : string | undefined; LT_ACCESS_KEY : string | undefined; + LT_SDK_DEBUG: boolean; BASELINE_BRANCH: string | undefined; CURRENT_BRANCH: string | undefined; } From d59732584364eb6c5b5dc66d3b969713522459b3 Mon Sep 17 00:00:00 2001 From: Pinank Solanki Date: Mon, 7 Oct 2024 17:05:05 +0530 Subject: [PATCH 08/13] Add launch arguments and requests headers in discovery browser --- src/lib/constants.ts | 60 ++++++++++++++++++++++++++++++++++++++ src/lib/processSnapshot.ts | 22 +++++++++----- 2 files changed, 74 insertions(+), 8 deletions(-) diff --git a/src/lib/constants.ts b/src/lib/constants.ts index d9a8393..a522e11 100644 --- a/src/lib/constants.ts +++ b/src/lib/constants.ts @@ -46,6 +46,66 @@ export default { EDGE_CHANNEL: 'msedge', WEBKIT: 'webkit', + // discovery browser launch arguments + LAUNCH_ARGS: [ + // disable the translate popup and optimization downloads + '--disable-features=Translate,OptimizationGuideModelDownloading', + // disable several subsystems which run network requests in the background + '--disable-background-networking', + // disable task throttling of timer tasks from background pages + '--disable-background-timer-throttling', + // disable backgrounding renderer processes + '--disable-renderer-backgrounding', + // disable backgrounding renderers for occluded windows (reduce nondeterminism) + '--disable-backgrounding-occluded-windows', + // disable crash reporting + '--disable-breakpad', + // disable client side phishing detection + '--disable-client-side-phishing-detection', + // disable default component extensions with background pages for performance + '--disable-component-extensions-with-background-pages', + // disable installation of default apps on first run + '--disable-default-apps', + // work-around for environments where a small /dev/shm partition causes crashes + '--disable-dev-shm-usage', + // disable extensions + '--disable-extensions', + // disable hang monitor dialogs in renderer processes + '--disable-hang-monitor', + // disable inter-process communication flooding protection for javascript + '--disable-ipc-flooding-protection', + // disable web notifications and the push API + '--disable-notifications', + // disable the prompt when a POST request causes page navigation + '--disable-prompt-on-repost', + // disable syncing browser data with google accounts + '--disable-sync', + // disable site-isolation to make network requests easier to intercept + '--disable-site-isolation-trials', + // disable the first run tasks, whether or not it's actually the first run + '--no-first-run', + // disable the sandbox for all process types that are normally sandboxed + '--no-sandbox', + // specify a consistent encryption backend across platforms + '--password-store=basic', + // use a mock keychain on Mac to prevent blocking permissions dialogs + '--use-mock-keychain', + // enable remote debugging on the first available port + '--remote-debugging-port=0', + // sets navigator.webdriver to false + '--disable-blink-features=AutomationControlled', + // disable UA-CH feature + `--disable-features=UserAgentClientHint`, + ], + + // discovery request headers + REQUEST_HEADERS: { + // `HeadlessChrome` is added to sec-ch-ua, `--disable-features=UserAgentClientHint` doesn't seem to work + 'sec-ch-ua':'"Chromium";v="129", "Not=A?Brand";v="8"', + 'sec-ch-ua-mobile': '"?0"', + 'sec-ch-ua-platform': '"Windows"' + }, + // user agents CHROME_USER_AGENT: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.107 Safari/537.3', FIREFOX_USER_AGENT: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:112.0) Gecko/20100101 Firefox/112.0', diff --git a/src/lib/processSnapshot.ts b/src/lib/processSnapshot.ts index b7ba433..d4cbaf9 100644 --- a/src/lib/processSnapshot.ts +++ b/src/lib/processSnapshot.ts @@ -80,7 +80,10 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise = { headless: true } + let launchOptions: Record = { + headless: true, + args: constants.LAUNCH_ARGS + } let contextOptions: Record = { javaScriptEnabled: ctx.config.cliEnableJavaScript, userAgent: constants.CHROME_USER_AGENT, @@ -92,8 +95,8 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise { const requestUrl = request.url() const requestHostname = new URL(requestUrl).hostname; - let requestOptions: Record = { timeout: REQUEST_TIMEOUT } + let requestOptions: Record = { + timeout: REQUEST_TIMEOUT, + headers: { + ...await request.allHeaders(), + ...constants.REQUEST_HEADERS + } + } try { // abort audio/video media requests @@ -149,10 +158,7 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise Date: Mon, 7 Oct 2024 17:05:24 +0530 Subject: [PATCH 09/13] Upgrade @playwright/test --- package.json | 8 +++--- pnpm-lock.yaml | 74 +++++++++++++++++++++----------------------------- 2 files changed, 35 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index df75269..dee08b2 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,10 @@ "author": "LambdaTest ", "license": "MIT", "dependencies": { - "@playwright/browser-chromium": "^1.45.3", - "@playwright/browser-firefox": "^1.45.3", - "@playwright/browser-webkit": "^1.45.3", - "@playwright/test": "^1.45.3", + "@playwright/browser-chromium": "^1.47.2", + "@playwright/browser-firefox": "^1.47.2", + "@playwright/browser-webkit": "^1.47.2", + "@playwright/test": "^1.47.2", "@types/cross-spawn": "^6.0.4", "@types/node": "^20.8.9", "@types/which": "^3.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ffc6331..b49e672 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,17 +9,17 @@ importers: .: dependencies: '@playwright/browser-chromium': - specifier: ^1.45.3 - version: 1.45.3 + specifier: ^1.47.2 + version: 1.47.2 '@playwright/browser-firefox': - specifier: ^1.45.3 - version: 1.45.3 + specifier: ^1.47.2 + version: 1.47.2 '@playwright/browser-webkit': - specifier: ^1.45.3 - version: 1.45.3 + specifier: ^1.47.2 + version: 1.47.2 '@playwright/test': - specifier: ^1.45.3 - version: 1.45.3 + specifier: ^1.47.2 + version: 1.47.2 '@types/cross-spawn': specifier: ^6.0.4 version: 6.0.5 @@ -262,84 +262,72 @@ packages: engines: {glibc: '>=2.26', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-arm@1.0.2': resolution: {integrity: sha512-iLWCvrKgeFoglQxdEwzu1eQV04o8YeYGFXtfWU26Zr2wWT3q3MTzC+QTCO3ZQfWd3doKHT4Pm2kRmLbupT+sZw==} engines: {glibc: '>=2.28', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-s390x@1.0.2': resolution: {integrity: sha512-cmhQ1J4qVhfmS6szYW7RT+gLJq9dH2i4maq+qyXayUSn9/3iY2ZeWpbAgSpSVbV2E1JUL2Gg7pwnYQ1h8rQIog==} engines: {glibc: '>=2.28', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [s390x] os: [linux] - libc: [glibc] '@img/sharp-libvips-linux-x64@1.0.2': resolution: {integrity: sha512-E441q4Qdb+7yuyiADVi5J+44x8ctlrqn8XgkDTwr4qPJzWkaHwD489iZ4nGDgcuya4iMN3ULV6NwbhRZJ9Z7SQ==} engines: {glibc: '>=2.26', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] - libc: [glibc] '@img/sharp-libvips-linuxmusl-arm64@1.0.2': resolution: {integrity: sha512-3CAkndNpYUrlDqkCM5qhksfE+qSIREVpyoeHIU6jd48SJZViAmznoQQLAv4hVXF7xyUB9zf+G++e2v1ABjCbEQ==} engines: {musl: '>=1.2.2', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] - libc: [musl] '@img/sharp-libvips-linuxmusl-x64@1.0.2': resolution: {integrity: sha512-VI94Q6khIHqHWNOh6LLdm9s2Ry4zdjWJwH56WoiJU7NTeDwyApdZZ8c+SADC8OH98KWNQXnE01UdJ9CSfZvwZw==} engines: {musl: '>=1.2.2', npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] - libc: [musl] '@img/sharp-linux-arm64@0.33.4': resolution: {integrity: sha512-2800clwVg1ZQtxwSoTlHvtm9ObgAax7V6MTAB/hDT945Tfyy3hVkmiHpeLPCKYqYR1Gcmv1uDZ3a4OFwkdBL7Q==} engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] - libc: [glibc] '@img/sharp-linux-arm@0.33.4': resolution: {integrity: sha512-RUgBD1c0+gCYZGCCe6mMdTiOFS0Zc/XrN0fYd6hISIKcDUbAW5NtSQW9g/powkrXYm6Vzwd6y+fqmExDuCdHNQ==} engines: {glibc: '>=2.28', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm] os: [linux] - libc: [glibc] '@img/sharp-linux-s390x@0.33.4': resolution: {integrity: sha512-h3RAL3siQoyzSoH36tUeS0PDmb5wINKGYzcLB5C6DIiAn2F3udeFAum+gj8IbA/82+8RGCTn7XW8WTFnqag4tQ==} engines: {glibc: '>=2.31', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [s390x] os: [linux] - libc: [glibc] '@img/sharp-linux-x64@0.33.4': resolution: {integrity: sha512-GoR++s0XW9DGVi8SUGQ/U4AeIzLdNjHka6jidVwapQ/JebGVQIpi52OdyxCNVRE++n1FCLzjDovJNozif7w/Aw==} engines: {glibc: '>=2.26', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] - libc: [glibc] '@img/sharp-linuxmusl-arm64@0.33.4': resolution: {integrity: sha512-nhr1yC3BlVrKDTl6cO12gTpXMl4ITBUZieehFvMntlCXFzH2bvKG76tBL2Y/OqhupZt81pR7R+Q5YhJxW0rGgQ==} engines: {musl: '>=1.2.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [arm64] os: [linux] - libc: [musl] '@img/sharp-linuxmusl-x64@0.33.4': resolution: {integrity: sha512-uCPTku0zwqDmZEOi4ILyGdmW76tH7dm8kKlOIV1XC5cLyJ71ENAAqarOHQh0RLfpIpbV5KOpXzdU6XkJtS0daw==} engines: {musl: '>=1.2.2', node: ^18.17.0 || ^20.3.0 || >=21.0.0, npm: '>=9.6.5', pnpm: '>=7.1.0', yarn: '>=3.2.0'} cpu: [x64] os: [linux] - libc: [musl] '@img/sharp-wasm32@0.33.4': resolution: {integrity: sha512-Bmmauh4sXUsUqkleQahpdNXKvo+wa1V9KhT2pDA4VJGKwnKMJXiSTGphn0gnJrlooda0QxCtXc6RX1XAU6hMnQ==} @@ -388,20 +376,20 @@ packages: resolution: {integrity: sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==} engines: {node: '>= 8'} - '@playwright/browser-chromium@1.45.3': - resolution: {integrity: sha512-UVPW8HveE8SghaahoMy8CfG0QdJ2mO0BZLOcPT8nlQh7Z97Gkv4e3Ad69D1oCqM3m3zYkDPAiGB+hOASNS0d/g==} + '@playwright/browser-chromium@1.47.2': + resolution: {integrity: sha512-tsk9bLcGzIu4k4xI2ixlwDrdJhMqCalUCsSj7TRI8VuvK7cLiJIa5SR0dprKbX+wkku/JMR4EN6g9DMHvfna+Q==} engines: {node: '>=18'} - '@playwright/browser-firefox@1.45.3': - resolution: {integrity: sha512-YuAXUcQfSw1BkkRFcRJTguBdtf2pUuIGMFydBjUzHtOBpJmTxeR8THWT/OzPTqdJy2bpSXWV9ktFJPRYL+i5pw==} + '@playwright/browser-firefox@1.47.2': + resolution: {integrity: sha512-0+APQGDqeTrb7XLCUr13sgTXV04ky121JsxE93JXj6mrEkoXeBqvbHLkXO3xrPUs1O1kL92Bc2eJ87KW2i5Jog==} engines: {node: '>=18'} - '@playwright/browser-webkit@1.45.3': - resolution: {integrity: sha512-68Z6XT2sGPyCM3sC8rke/s3vsjbYwscUqGFUzBIvLlivFNrjm5v1Ax1nHs5nOm0ReOnhgcOdYia0AEUuuee+CQ==} + '@playwright/browser-webkit@1.47.2': + resolution: {integrity: sha512-NHXueW09Ou26raqzDccUaSUbmiBMY0eonqQVvUbrTRNNRlMA8Vp6lGqZiPy5qo/FvEeQBSsZSCfH/MnathYhdg==} engines: {node: '>=18'} - '@playwright/test@1.45.3': - resolution: {integrity: sha512-UKF4XsBfy+u3MFWEH44hva1Q8Da28G6RFtR2+5saw+jgAFQV5yYnB1fu68Mz7fO+5GJF3wgwAIs0UelU8TxFrA==} + '@playwright/test@1.47.2': + resolution: {integrity: sha512-jTXRsoSPONAs8Za9QEQdyjFn+0ZQFjCiIztAIF6bi1HqhBzG9Ma7g1WotyiGqFSBRZjIEqMdT8RUlbk1QVhzCQ==} engines: {node: '>=18'} hasBin: true @@ -918,13 +906,13 @@ packages: resolution: {integrity: sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==} engines: {node: '>= 6'} - playwright-core@1.45.3: - resolution: {integrity: sha512-+ym0jNbcjikaOwwSZycFbwkWgfruWvYlJfThKYAlImbxUgdWFO2oW70ojPm4OpE4t6TAo2FY/smM+hpVTtkhDA==} + playwright-core@1.47.2: + resolution: {integrity: sha512-3JvMfF+9LJfe16l7AbSmU555PaTl2tPyQsVInqm3id16pdDfvZ8TTZ/pyzmkbDrZTQefyzU7AIHlZqQnxpqHVQ==} engines: {node: '>=18'} hasBin: true - playwright@1.45.3: - resolution: {integrity: sha512-QhVaS+lpluxCaioejDZ95l4Y4jSFCsBvl2UZkpeXlzxmqS+aABr5c82YmfMHrL6x27nvrvykJAFpkzT2eWdJww==} + playwright@1.47.2: + resolution: {integrity: sha512-nx1cLMmQWqmA3UsnjaaokyoUpdVaaDhJhMoxX2qj3McpjnsqFHs516QAKYhqHAgOP+oCFTEOCOAaD1RgD/RQfA==} engines: {node: '>=18'} hasBin: true @@ -1412,21 +1400,21 @@ snapshots: '@nodelib/fs.scandir': 2.1.5 fastq: 1.15.0 - '@playwright/browser-chromium@1.45.3': + '@playwright/browser-chromium@1.47.2': dependencies: - playwright-core: 1.45.3 + playwright-core: 1.47.2 - '@playwright/browser-firefox@1.45.3': + '@playwright/browser-firefox@1.47.2': dependencies: - playwright-core: 1.45.3 + playwright-core: 1.47.2 - '@playwright/browser-webkit@1.45.3': + '@playwright/browser-webkit@1.47.2': dependencies: - playwright-core: 1.45.3 + playwright-core: 1.47.2 - '@playwright/test@1.45.3': + '@playwright/test@1.47.2': dependencies: - playwright: 1.45.3 + playwright: 1.47.2 '@types/cross-spawn@6.0.5': dependencies: @@ -1960,11 +1948,11 @@ snapshots: pirates@4.0.6: {} - playwright-core@1.45.3: {} + playwright-core@1.47.2: {} - playwright@1.45.3: + playwright@1.47.2: dependencies: - playwright-core: 1.45.3 + playwright-core: 1.47.2 optionalDependencies: fsevents: 2.3.2 From f5a247d8d061d14dfafd488d4fa56fcb69134025 Mon Sep 17 00:00:00 2001 From: sushobhit-lt Date: Tue, 8 Oct 2024 16:27:04 +0530 Subject: [PATCH 10/13] fix undefined length issue --- src/lib/processSnapshot.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/processSnapshot.ts b/src/lib/processSnapshot.ts index 4a90cd7..3666615 100644 --- a/src/lib/processSnapshot.ts +++ b/src/lib/processSnapshot.ts @@ -72,7 +72,7 @@ export default class Queue { } isEmpty(): boolean { - return this.snapshots.length ? false : true; + return this.snapshots && this.snapshots.length ? false : true; } } From e4f002aac6613d607a944abe1c6a1549dace9fb2 Mon Sep 17 00:00:00 2001 From: Pinank Solanki Date: Thu, 10 Oct 2024 19:43:59 +0530 Subject: [PATCH 11/13] Use null coalescing operator instead of logical OR for default config --- src/lib/ctx.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/ctx.ts b/src/lib/ctx.ts index 7857435..eb294ef 100644 --- a/src/lib/ctx.ts +++ b/src/lib/ctx.ts @@ -70,8 +70,8 @@ export default (options: Record): Context => { mobile: mobileConfig, waitForPageRender: config.waitForPageRender || 0, waitForTimeout: config.waitForTimeout || 0, - enableJavaScript: config.enableJavaScript || false, - cliEnableJavaScript: config.cliEnableJavaScript || true, + enableJavaScript: config.enableJavaScript ?? false, + cliEnableJavaScript: config.cliEnableJavaScript ?? true, scrollTime: config.scrollTime || constants.DEFAULT_SCROLL_TIME, allowedHostnames: config.allowedHostnames || [], basicAuthorization: basicAuthObj, From 1b6b8386fa8f6fd725faac8c2553fd29a7d6befa Mon Sep 17 00:00:00 2001 From: Pinank Solanki Date: Thu, 10 Oct 2024 21:35:12 +0530 Subject: [PATCH 12/13] Revert responsive DOM changes --- src/lib/processSnapshot.ts | 40 ------------------------- src/lib/schemaValidation.ts | 58 ------------------------------------- src/types.ts | 9 ------ 3 files changed, 107 deletions(-) diff --git a/src/lib/processSnapshot.ts b/src/lib/processSnapshot.ts index 3666615..961f13a 100644 --- a/src/lib/processSnapshot.ts +++ b/src/lib/processSnapshot.ts @@ -231,45 +231,6 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise 0) { - processedOptions.web.viewports = options.web.viewports.filter(viewport => - Array.isArray(viewport) && viewport.length > 0 - ); - } - - // Check and process browsers in web - if (options.web.browsers && options.web.browsers.length > 0) { - processedOptions.web.browsers = options.web.browsers; - } - } - - if (options.mobile && Object.keys(options.mobile).length) { - processedOptions.mobile = {}; - - // Check and process devices in mobile - if (options.mobile.devices && options.mobile.devices.length > 0) { - processedOptions.mobile.devices = options.mobile.devices; - } - - // Check if 'fullPage' is provided and is a boolean, otherwise set default to true - if (options.mobile.hasOwnProperty('fullPage') && typeof options.mobile.fullPage === 'boolean') { - processedOptions.mobile.fullPage = options.mobile.fullPage; - } else { - processedOptions.mobile.fullPage = true; // Default value for fullPage - } - - // Check if 'orientation' is provided and is valid, otherwise set default to 'portrait' - if (options.mobile.hasOwnProperty('orientation') && (options.mobile.orientation === 'portrait' || options.mobile.orientation === 'landscape')) { - processedOptions.mobile.orientation = options.mobile.orientation; - } else { - processedOptions.mobile.orientation = 'portrait'; // Default value for orientation - } - } - if (options.element && Object.keys(options.element).length) { if (options.element.id) processedOptions.element = '#' + options.element.id; else if (options.element.class) processedOptions.element = '.' + options.element.class; @@ -379,7 +340,6 @@ async function processSnapshot(snapshot: Snapshot, ctx: Context): Promise = { errorMessage: "Invalid snapshot options; selectDOM xpath array must have unique and non-empty items" }, } - }, - web: { - type: "object", - properties: { - browsers: { - type: "array", - items: { - type: "string", - enum: [constants.CHROME, constants.FIREFOX, constants.SAFARI, constants.EDGE], - minLength: 1 - }, - uniqueItems: true, - errorMessage: `Invalid snapshot options; allowed browsers - ${constants.CHROME}, ${constants.FIREFOX}, ${constants.SAFARI}, ${constants.EDGE}` - }, - viewports: { - type: "array", - items: { - type: "array", - items: { - type: "number", - minimum: 1 - }, - minItems: 1, - maxItems: 2, - errorMessage: "Invalid snapshot options; each viewport array must contain either a single width or a width and height tuple with positive values." - }, - uniqueItems: true, - errorMessage: "Invalid snapshot options; viewports must be an array of unique arrays." - } - }, - required: ["viewports"], - errorMessage: "Invalid snapshot options; web must include viewports property." - }, - mobile: { - type: "object", - properties: { - devices: { - type: "array", - items: { - type: "string", - enum: Object.keys(constants.SUPPORTED_MOBILE_DEVICES), - minLength: 1 - }, - uniqueItems: true, - errorMessage: "Invalid snapshot options; devices must be an array of unique supported mobile devices." - }, - fullPage: { - type: "boolean", - errorMessage: "Invalid snapshot options; fullPage must be a boolean." - }, - orientation: { - type: "string", - enum: [constants.MOBILE_ORIENTATION_PORTRAIT, constants.MOBILE_ORIENTATION_LANDSCAPE], - errorMessage: "Invalid snapshot options; orientation must be either 'portrait' or 'landscape'." - } - }, - required: ["devices"], - errorMessage: "Invalid snapshot options; mobile must include devices property." } }, additionalProperties: false diff --git a/src/types.ts b/src/types.ts index bc36479..7bc1283 100644 --- a/src/types.ts +++ b/src/types.ts @@ -87,15 +87,6 @@ export interface Snapshot { class?: string, cssSelector?: string, xpath?: string - }, - web?: { - browsers?: string[], - viewports: ([number] | [number, number])[] - }, - mobile?: { - devices: string[], - fullPage?: boolean, - orientation?: string } } } From aa341e5fcadcda3a94072b781aef58a45125484a Mon Sep 17 00:00:00 2001 From: Pinank Solanki Date: Thu, 10 Oct 2024 21:50:34 +0530 Subject: [PATCH 13/13] 4.0.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dee08b2..d3af3f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lambdatest/smartui-cli", - "version": "4.0.5", + "version": "4.0.6", "description": "A command line interface (CLI) to run SmartUI tests on LambdaTest", "files": [ "dist/**/*"