Automation 从支持导入要在集成测试用例中使用的文件时出现问题
Cypress不允许我将页面对象文件导入测试用例。文件构造正确,但当我尝试从“支持”文件夹导入测试用例时,“支持文件夹”不会出现,它清楚地显示了我的经历 代码如下:Automation 从支持导入要在集成测试用例中使用的文件时出现问题,automation,automated-tests,cypress,Automation,Automated Tests,Cypress,Cypress不允许我将页面对象文件导入测试用例。文件构造正确,但当我尝试从“支持”文件夹导入测试用例时,“支持文件夹”不会出现,它清楚地显示了我的经历 代码如下: /// <reference types="Cypress" /> import Homepage from '../' describe('My test feature',function() { beforeEach(function(){ cy.fixture
/// <reference types="Cypress" />
import Homepage from '../'
describe('My test feature',function() {
beforeEach(function(){
cy.fixture('example').then(function(data){
this.data=data
})
})
it('my first test scenario', function(){
cy.visit('https://rahulshettyacademy.com/angularpractice/')
cy.get('input[name="name"]:nth-child(2)').type(this.data.name)
cy.get('select').select(this.data.gender)
cy.get('input[name="name"]:nth-child(1)').should('have.value',this.data.name )
cy.get('input[name="name"]:nth-child(2)').should('have.attr', 'minlength','2')
cy.get('input[id=inlineRadio3]').should('be.disabled')
cy.get('a[href="/angularpractice/shop"]').click()
this.data.mobileHandset.forEach(function(element) {
cy.AddToCart(element)
});
})//end of test case
})//end of describe
如果您的spec文件位于
cypress/integration/
中,而POM类位于cypress/support/pageObjects/
中,那么您需要像这样导入POM类:
从“../support/pageObjects/Homepage”导入主页;
因为您需要升级一级,然后进入
support/pageObjects/
目录。如果您的规范文件位于cypress/integration/
中,并且您的POM类位于cypress/support/pageObjects/
中,那么您需要像这样导入POM类:
从“../support/pageObjects/Homepage”导入主页;
因为您需要升级一级,然后进入
support/pageObjects/
目录。好的,所以我找到了问题所在。cypress中的区分大小写是关键!!!我认为我没有编写我想要导入的文件,因为它在框架中显示的字母大小写正确。正是这些小事情会让你花时间去解决问题,因为它们太难看了
另外,作为一方,不要确保您一直“保存所有”,因为有时事情不会像预期的那样工作,因为整个框架都没有保存——只有您正在使用的文件(如果有意义的话)
好的,我知道问题出在哪里了。cypress中的区分大小写是关键!!!我认为我没有编写我想要导入的文件,因为它在框架中显示的字母大小写正确。正是这些小事情会让你花时间去解决问题,因为它们太难看了 另外,作为一方,不要确保您一直“保存所有”,因为有时事情不会像预期的那样工作,因为整个框架都没有保存——只有您正在使用的文件(如果有意义的话)
@pavelsman感谢您的回复。我刚试过你的建议。我在问题中发布了一段视频,向您展示发生了什么。@fypnlp:您的规范文件不在
cypress/integration/examples/
目录下吗?如果是这样,您需要再上一层:“../support/pageObjects/Homepage”
是的,我的规范文件位于cypress/integration/examples/中。让我试试,我会让你知道的happens@pavelsman我用您的建议的结果更新了“单击此处”视频链接。@fypnlp:但是当您运行测试用例时,它实际工作了吗(也就是说,您可以使用导入的主页类)?这可能只是IDE的一些设置。@pavelsman感谢您的回复。我刚试过你的建议。我在问题中发布了一段视频,向您展示发生了什么。@fypnlp:您的规范文件不在cypress/integration/examples/
目录下吗?如果是这样,您需要再上一层:“../support/pageObjects/Homepage”
是的,我的规范文件位于cypress/integration/examples/中。让我试试,我会让你知道的happens@pavelsman我用您的建议的结果更新了“单击此处”视频链接。@fypnlp:但是当您运行测试用例时,它实际工作了吗(也就是说,您可以使用导入的主页类)?它可能只是IDE的一些设置。
class Homepage
{
getCustomerRegistrationName()
{
return cy.get('input[name="name"]:nth-child(2)')
}
getTwoWayDataBinding()
{
return cy.get('input[name="name"]:nth-child(1)')
}
getGenderDropdownList()
{
return cy.get('select')
}
getEntrepreneur()
{
return cy.get('#inlineRadio3')
}
getShopTab()
{
return cy.get(':nth-child(2) > .nav-link')
}
}
export default Homepage;