Cypress and TypeScript - Bringing in a new class

I am currently utilizing Cypress.io alongside TypeScript for test automation and attempting to perform simple tasks. I want to import a class from one file to another without repeating the code.

p.s. Despite trying several solutions on Stack Overflow, none of them have been successful for me.

Files: File System

Code:

loginPage.ts

export class LogIn {
    //Launch app: http://localhost:6400/
    cy.visit('localhost:6400')
    //Press on menu item.
    cy.get('.navbar-burger').click()
    //Press "Client" menu item near "Login As:".
    cy.get('#navbarMenu a').contains("Client").click()
    //TODO
    }

and client_NewJob.ts

import { LogIn } from '../helpers/loginPage';
import * as ChaiString from 'chai-string';

chai.use(ChaiString);
const lg = new LogIn();
//beforeEach
describe('BeforeEachTestLogIn', () =>{
    beforeEach(() =>{
        lg.LogIn()
    })
})
//Test
describe('New job page', function() {
    it('newJobCreation', function() {
        //TODO
    })
})

When I try to execute the client_NewJob.ts script via Cypress, I encounter an error message:

./cypress/helpers/loginPage.ts | TS1005: ';' expected.

./cypress/helpers/loginPage.ts TS1003: Identifier expected.

./cypress/helpers/loginPage.ts TS1144: '{' or ';' expected

I keep receiving similar error messages... How can I resolve this issue with importing the class?

Answer №1

It appears that one aspect needing attention is the structure of your LogIn class, as the functionality should be contained within a method instead of directly in the class body:

export class LogIn {
    logIn() {
        //Open application: http://localhost:6400/
        cy.visit('localhost:6400')
        //Click on the menu button.
        cy.get('.navbar-burger').click()
        //Select the "Client" option from the navigation menu.
        cy.get('#navbarMenu a').contains("Client").click()
        //TODO
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Sort and incorporate elements by multiple strings present in an array

Looking to filter and include strings in an array by matching them with items in another array? Here is a sample code snippet that filters based on a single string: const filteredString = `${this.filter}`.toLowerCase(); this.filteredCampaigns = this. ...

Having trouble interacting with an element using Selenium in Python

I am trying to figure out how to download an image from Instagram, but I cannot seem to programmatically click on the download button of this page. Even after attempting to use XPath and CSS selector methods for clicking, unfortunately, neither seems to w ...

Is it acceptable to access elements beyond the confines of a page object?

I am seeking insights from users based on their experiences regarding a question for which I have been unable to find a definitive source. My query revolves around the usage of webdriver for automation through Protractor, specifically on whether page eleme ...

Depicting a potential value within Typescript

Coming from a background of working with functional languages that utilize monadic constructs like Option or Optional, I have noticed libraries such as fp-ts that provide these features in TypeScript/JavaScript. However, I am curious to understand how deve ...

How can you customize the appearance of the filledInput component within a TextField component in Material UI?

I need some guidance on how to change the color of the FilledInput component within a TextField. Unlike InputProps, FilledInputProps are not directly accessible for styling with classes. Any suggestions on how I can customize the styling of the FilledInpu ...

Creating a flexible TypeScript function handler that accepts optional arguments depending on the function's name

I am facing a challenge with defining the function type for running helper functions that prepare database queries. Some of these functions have arguments, while others do not. TS Playground Link type PreparedQuery = { query: string; params?: string[] ...

RxJS: Observable.never() acts like an eternal subscription

Currently, I am working with rxjs version 5.5.6. Below is a snippet of code that showcases a specific behavior: Observable.of(1, 2) .do(a => { console.log(a); let d:string = null; let r = d.length; // this line throws a nu ...

The property 'x' cannot be found on the data type 'true | Point'

I am dealing with a variable named ctx which can be either of type boolean or Point. Here is how Point is defined: type Point = { x: number y: number } In my React component, I have the following setup: const App = () => { const [ctx, toggleC ...

When `console.log(enum)` is executed in Typescript and AngularJS, the result will be `undefined`

Below is the code snippet for the file that contains the enum: module mops { export enum Status { OK = 0, ROC = (1 << 0), LLA = (1 << 1), LOA = (1 << 2), HIA = (1 &l ...

Arrange an array of objects by making a nested API call in Angular

My task involves sorting an array of objects based on the response from the first API call in ascending order. The initial API call returns a list of arrays which will be used for the subsequent API call. The first API call fetches something like this: [0 ...

Sending the id from a component to a service in Angular

In my current project, I am working on a chat application using Angular with WebSocket integration. Let me provide an overview of the architecture I have designed for this project. I created a module called 'chatting' which contains a list of use ...

Attempting to engage with the like button on a Facebook page through Python's Selenium seems to be problematic

Here is the code for adding a (Facebook page like button): WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.XPATH, '/html/body/div[1]/div/div[4]/div/div[1]/div/div[1]/div[2]/div[2]/div/div/div[3]/div/div[1]'))).click() The clic ...

I thought enabling CORS would solve the issue, but it seems like the restrictions

This is my setup for an asp.net core web API: public void ConfigureServices(IServiceCollection services) { services.AddCors(o => o.AddPolicy("CorsPolicy", builder => { builder ...

Ways to bring in a Typescript Vue project to a Javascript Vue

I am trying to incorporate this Calendar component into my Javascript Vue 3 project. To achieve this, I have created a new component in my project named ProCalendar.vue and copied the code from the example found in App.vue. Additionally, I have added the n ...

Typescript headaches: Conflicting property types with restrictions

Currently, I am in the process of familiarizing myself with Typescript through its application in a validation library that I am constructing. types.ts export type Value = string | boolean | number | null | undefined; export type ExceptionResult = { _ ...

Custom hooks for Typescript and Javascript

As a beginner, I am currently working on refactoring JavaScript hooks into TypeScript. However, I am facing an issue where I cannot get the button onClick event to change state. Can anyone provide assistance with this? Here is the useToggler component: i ...

Is the input URL modified by the Angular HttpClientModule's GET request?

I am currently using an Angular service to make calls to a Node.js server in order to fetch data. Here is a snippet of my code: constructor(private http: HttpClient){ } getPersonData(): Observable<person[]> { //return this.http.get<person ...

What could be causing the QullJS delta to display in a nonsensical sequence?

The outcome showcased in the delta appears as: {"ops":[{"retain":710},{"insert":" yesterday, and she says—”\n“The clinic?","attributes":{"prediction":"prediction"}},{"del ...

Having trouble resolving rxjs/operators when using ngx-datatable?

I am attempting to integrate ngx-datatable into my Angular-2 project. I have followed all the steps outlined here, but I encountered the following error: ERROR in ./~/@swimlane/ngx-datatable/release/index.js Module not found: Error: Can't re ...

Component unit testing in Angular 2/4 fails to register click events causing a lack of change detection

I'm currently working on testing a component in Angular 2/4 to determine if clicking on a button element will result in the desired changes. However, I'm facing an issue with triggering the click event. Here is the component code: import { Comp ...