2

I am trying to write UI automation scripts to perform the automated testing of a vs code extension. After reading tutorials about spectron/ vs code test, I found that they both need source code to perform tests. I am trying to perform from a QA side and hence I have the extension installed on my vs code but now I need to perform automation.

I am able to launch vs code and open the extension using selenium-webdriver but cannot access the elements that are loaded under vs code web view. VS code hides the web element for the extension and hence selenium-webdriver cannot find the elements.

{ describe, it, after, before } require('mocha');
// const Config = require('../../config/config.json');
const webdriver = require('selenium-webdriver'),
      By = webdriver.By
const assert = require('chai').assert

function sleep(ms) {
        return new Promise(resolve => setTimeout(resolve, ms));
      }

        try{
            describe('Launch VS Code', function(){
                this.timeout(20000);
                let driver=  new webdriver.Builder()
                // The "9515" is the port opened by chrome driver.
                .usingServer('http://localhost:9515')
                .withCapabilities({
                  chromeOptions: {
                    // Here is the path to your Electron binary"
                    binary: 'path to vs code'
                  }
                })
                .forBrowser('electron')
                .build();

                it('open extension', async function(){
                    await driver.findElement(By.xpath(".//div[contains(@aria-label,'View')]")).click()
                    await driver.findElement(By.xpath("//*[text()='Command Palette...']")).click()
                    await driver.findElement(By.className('input')).sendKeys('extensionname')
                    await driver.findElement(By.xpath("//*[contains(text(),'extensionname')]")).click()
                    await sleep(5000)
                    await driver.findElement(By.xpath("//*[contains(@title,'extension title')]")).click()
                    var title =await driver.getTitle()
                    assert.equal(title,'extensiontitle')
                    await sleep(5000)
                    await driver.switchTo().frame(driver.findElement(By.tagName('iframe')))
                    await driver.getPageSource().then(function(tmptext){
                        console.log(tmptext.includes('extension web element'))
                    })


                });
            })
        }
        catch(ex){
            console.log(ex)
        }

the code should be able to find the web driver and complete the test.

0 Answers0