I am using Cypress.io + TypeScript for test automation and trying to do simple stuff. Import class from one file to another, that code do not repeat.
ps I have tried few solutions from stack overflow. It does not helped 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
})
})
I try to run client_NewJob.ts script via Cypress and then I am getting error message:
./cypress/helpers/loginPage.ts | TS1005: ';' expected.
./cypress/helpers/loginPage.ts TS1003: Identifier expected.
./cypress/helpers/loginPage.ts TS1144: '{' or ';' expected
And a lot same error messages...
How can I import class?
One issue I can see, is that stuff in your LogIn
class should be in a method not in the classes body:
export class LogIn {
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
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.