From f1c5ec16fbfddb0c572d606733935af1c2aef532 Mon Sep 17 00:00:00 2001 From: THEBOSS0369 Date: Fri, 15 Nov 2024 18:42:25 +0530 Subject: [PATCH] Added android test --- tests/e2e/spec/tonedear.e2e.spec.js | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/tests/e2e/spec/tonedear.e2e.spec.js b/tests/e2e/spec/tonedear.e2e.spec.js index 2a7093579..11497f42c 100644 --- a/tests/e2e/spec/tonedear.e2e.spec.js +++ b/tests/e2e/spec/tonedear.e2e.spec.js @@ -103,6 +103,70 @@ function runTests (driver, modes) { await driver.sleep(1300); } }); + + it('Verify Android and iOS store images in ' + (mode === 'jquery' ? 'Restricted' : 'ServiceWorker') + ' mode', async function () { + if (!serviceWorkerAPI && mode === 'jquery') { + // Restricted mode test for data URIs + const androidImage = await driver.findElement(By.css('img[alt="Get it on Google Play"]')); + const iosImage = await driver.findElement(By.css('img[alt="Download on the App Store"]')); + + // Verify src attribute has changed to a data URI + const androidSrc = await androidImage.getAttribute('src'); + const iosSrc = await iosImage.getAttribute('src'); + + assert.ok(androidSrc.startsWith('data:image/png;base64,'), 'Android image src is a data URI'); + assert.ok(iosSrc.startsWith('data:image/png;base64,'), 'iOS image src is a data URI'); + + // Compare the first 30 characters of data URIs + const androidDataSnippet = androidSrc.substring(22, 52); + const iosDataSnippet = iosSrc.substring(22, 52); + + // Expected snippet for comparison + const expectedAndroidSnippet = 'iVBORw0KGgoAAAANSUhEUg'; + const expectedIosSnippet = 'iVBORw0KGgoAAAANSUhEUg'; + + assert.strictEqual(androidDataSnippet, expectedAndroidSnippet, 'Android image data matches expected'); + assert.strictEqual(iosDataSnippet, expectedIosSnippet, 'iOS image data matches expected'); + } else if (serviceWorkerAPI && mode === 'serviceworker') { + try { + // ServiceWorker mode test for image loading + await driver.sleep(3000); + + const swRegistration = await driver.executeScript('return navigator.serviceWorker.ready'); + assert.ok(swRegistration, 'Service Worker is registered'); + + console.log('Current URL:', await driver.getCurrentUrl()); + + await driver.wait(async function () { + const images = await driver.findElements(By.css('img[alt="Get it on Google Play"], img[alt="Download on the App Store"]')); + return images.length > 0; + }, 20000, 'No store images found after 10 seconds'); + + const androidImage = await driver.findElement(By.css('img[alt="Get it on Google Play"]')); + const iosImage = await driver.findElement(By.css('img[alt="Download on the App Store"]')); + + // Wait for images to load and verify dimensions + await driver.wait(async function () { + const androidLoaded = await driver.executeScript('return arguments[0].complete && arguments[0].naturalWidth > 0 && arguments[0].naturalHeight > 0;', androidImage); + const iosLoaded = await driver.executeScript('return arguments[0].complete && arguments[0].naturalWidth > 0 && arguments[0].naturalHeight > 0;', iosImage); + return androidLoaded && iosLoaded; + }, 5000, 'Images did not load successfully'); + + const androidWidth = await driver.executeScript('return arguments[0].naturalWidth;', androidImage); + const androidHeight = await driver.executeScript('return arguments[0].naturalHeight;', androidImage); + + const iosWidth = await driver.executeScript('return arguments[0].naturalWidth;', iosImage); + const iosHeight = await driver.executeScript('return arguments[0].naturalHeight;', iosImage); + + assert.ok(androidWidth > 0 && androidHeight > 0, 'Android image has valid dimensions'); + assert.ok(iosWidth > 0 && iosHeight > 0, 'iOS image has valid dimensions'); + } catch (err) { + // If we still can't find the images, log the page source to help debug + console.error('Failed to find store images:', err.message); + throw err; + } + } + }); }); }); }