[英]Cypress+TypeScript. Import class
I am using Cypress.io + TypeScript for test automation and trying to do simple stuff.我正在使用 Cypress.io + TypeScript 进行测试自动化并尝试做一些简单的事情。 Import class from one file to another, that code do not repeat.将类从一个文件导入到另一个文件,该代码不再重复。
ps I have tried few solutions from stack overflow. ps 我尝试了一些堆栈溢出的解决方案。 It does not helped me.它对我没有帮助。
Files : File System文件:文件系统
Code :代码:
loginPage.ts登录页面.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和 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 运行 client_NewJob.ts 脚本,然后收到错误消息:
./cypress/helpers/loginPage.ts | ./cypress/helpers/loginPage.ts | TS1005: ';' TS1005: ';' expected.预期的。
./cypress/helpers/loginPage.ts TS1003: Identifier expected. ./cypress/helpers/loginPage.ts TS1003:需要标识符。
./cypress/helpers/loginPage.ts TS1144: '{' or ';' ./cypress/helpers/loginPage.ts TS1144: '{' 或 ';' 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:我可以看到的一个问题是,您的LogIn
类中的内容应该位于不在类主体中的方法中:
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.