2

I am writing automated tests for a webshop using Visual studio Code, webdriverIO and javascript/nodeJS

Everything works fine, but I can't seem to get vs code to autocomplete my methods (I am using a page object model, pageobjects which contain methods are called in tests).

This is my login pageobject with a method to login a user (just an example, actual pageobject contains many more methods) :

class LoginPage{

    login(username, password) {
        browser.setValue('#ShopLoginForm_Login', username)
        browser.setValue('#ShopLoginForm_Password', password)
        browser.click('button=Login')
  }
}

module.exports = { LoginPage };

This is how I call it in the testfile:

describe('login test', function() {

    const LoginPage = require('../../pages/loginPage').LoginPage;
    loginPage = new LoginPage
    const Menu = require('../../pages/menu').Menu;
    menu = new Menu

    it('should be able to login with valid credentials', function () {
        browser.url(url)
        menu.gotoLoginPage()
        loginPage.login(username, password)
    });
});

Every time I want to call a method in a test, it does not autocomplete the methods name, forcing me to write it out full, leading to many unneccesary typo's. Other types of methods, like webdriverIO browser.click, are autocompleted just fine.

I have tried the same code in webstorm, and there autocomplete does work.

Does anyone know what I can do to get VS code to autocomplete my methods?

2 Answers 2

3

pity that no-one was able to answer. I eventually found the answer myself. I will post it here for reference

in my imports:

const LoginPage = require('../../pages/loginPage').LoginPage;
loginPage = new LoginPage

I am forgetting to declare the new instance of the class. The right way should have been;

const LoginPage = require('../../pages/loginPage').LoginPage;
var loginPage = new LoginPage

An alternative way would have been to make my methods static, which removes the need for instantiating the class altogether

Sign up to request clarification or add additional context in comments.

Comments

0

I struggled to use auto-suggest in vscode with webdriverio.

This links helped me. https://webdriver.io/docs/autocompletion.html https://webdriver.io/docs/pageobjects.html

You answer is right. instanciate the page. In the official doc, they export class with 'new'

export default new LoginPage()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.