diff --git a/examples/javascript/test/interactions/windows.spec.js b/examples/javascript/test/interactions/windows.spec.js index 7561b67eedd9..07f2523d4a97 100644 --- a/examples/javascript/test/interactions/windows.spec.js +++ b/examples/javascript/test/interactions/windows.spec.js @@ -1,17 +1,16 @@ -const {Builder} = require('selenium-webdriver'); +const {Builder, By} = require('selenium-webdriver'); const chrome = require('selenium-webdriver/chrome'); const assert = require("node:assert"); let opts = new chrome.Options(); opts.addArguments('--headless'); - let startIndex = 0 let endIndex = 5 let pdfMagicNumber = 'JVBER' +let imgMagicNumber = 'iVBOR' let base64Code describe('Interactions - Windows', function () { let driver; - before(async function () { driver = await new Builder().forBrowser('chrome').setChromeOptions(opts).build(); }); @@ -19,6 +18,7 @@ describe('Interactions - Windows', function () { after(async () => await driver.quit()); it('Should be able to print page to pdf', async function () { + await driver.get('https://www.selenium.dev/selenium/web/alerts.html'); let base64 = await driver.printPage({pageRanges: ["1-2"]}); // page can be saved as a PDF as below @@ -27,4 +27,24 @@ describe('Interactions - Windows', function () { base64Code = base64.slice(startIndex, endIndex) assert.strictEqual(base64Code, pdfMagicNumber) }); + + it('Should be able to get text using executeScript', async function () { + await driver.get('https://www.selenium.dev/selenium/web/javascriptPage.html'); + // Stores the header element + let header = await driver.findElement(By.css('h1')); + + // Executing JavaScript to capture innerText of header element + let text = await driver.executeScript('return arguments[0].innerText', header); + assert.strictEqual(text, `Type Stuff`) + }); + + it('Should be able to take Element Screenshot', async function () { + await driver.get('https://www.selenium.dev/selenium/web/javascriptPage.html'); + + let header = await driver.findElement(By.css('h1')); + // Captures the element screenshot + let encodedString = await header.takeScreenshot(true); + base64Code = encodedString.slice(startIndex, endIndex) + assert.strictEqual(base64Code, imgMagicNumber) + }); }); \ No newline at end of file