how to assign selector to an object class in Cypress

I’m trying to assign the selector to one of my object classes by using cypress. but it doesn’t work for me. here is the error I got

stocksTradePage.getStocksSearch(…).getInputField is not a function

here are my classes.


const locators = {
  inputField: 'input',

class StocksSearch {
  getInputField() {
    return cy.get(locators.inputField);

module.exports = StocksSearch;


import StocksSearch from './stocksSearch'

const locators = {
  strocksSearch: '[data-cy=stock-search-field]',

let stocksSearch = new StocksSearch();

class StocksTradePage {
  getStocksSearch() {
    stocksSearch = cy.get(locators.strocksSearch);
    return stocksSearch;

module.exports = StocksTradePage;


import StocksTradePage from '../../support/trade/stroksTradePage'

const stocksTradePage = new StocksTradePage();

describe('global nav test', () => {
  it('test input field', () => {

48 thoughts on “how to assign selector to an object class in Cypress”

Leave a Comment