【问题标题】:what does this mean? " expected <td.top-aligned-table.ng-star-inserted> to exist in the DOM"这是什么意思? “ 预期 <td.top-aligned-table.ng-star-inserted> 存在于 DOM 中”
【发布时间】:2019-07-24 09:19:11
【问题描述】:

enter image description here我有测试脚本测试,在脚本末尾带有断言,并产生像我上面的标题

【问题讨论】:

    标签: cypress


    【解决方案1】:

    我不完全确定你的意思,但我会解释一下你的测试结果。

    您看到的是您要求赛普拉斯对一个元素执行“获取”(用 .ui-datatable-data &gt; nth-child(1) nth-ch...&gt; 指定。当赛普拉斯在寻找该特定元素时,如果找到了类 &lt;td.top-aligned-table.ng-star-inserted&gt; 的元素。 DOM 是浏览器的视图,所以基本上是被测试的应用程序。 并且赛普拉斯希望该元素存在于 DOM 中,因为您对元素执行了cy.get()

    【讨论】:

    • 实际上我不知道我使用断言的元素是空的。实际上,我检查的数据是我刚刚更新而不是创建的数据。我跳过/未更新的 9 个元素中的一些元素。所以我检查了我对显示器上现有数据所做的更新结果。无论如何,关于您的评论,我已经应用断言来获取它们包含的内容。然而,只有前两个只有内容,尽管之前显示的所有元素都已更新。你觉得哪里不对?还是我需要显示整个代码?
    • 请参阅我的下一条评论。如下。
    【解决方案2】:

    this the picture after i click button save

    这是我所附图片的html代码部分

    this is that i wanna test

    点击按钮保存后 图片中看不到,我想断言我的测试结果`

    我想像这段代码一样更新/编辑测试这部分。无论如何,根据你的说法, 我的代码有多糟糕?在我的代码的核心,我填写了一些元素并传递了一些元素

    //file test runner 
    exports.productupdate=function(product_update){
        cy.url().should('include','/invoicer/dashboard')
        
        cy.clearCookies()
        //assertion
        cy.get('.paywall-dropdown > .btn-group > #single-button > .hidden-xs').should('contain','Free')
        
        //cy.get('.close-button').click()
        
        //choose language -> ID
        cy.get('.language-dropdown').click()
    
        cy.get('.ui-dropdown-items-wrapper').contains('EN').click()
        
        cy.get('div .olark-top-bar-button').click({force:true})
        
        cy.get('.dropdown-toggle').contains("Product").click()
        
        //sub menunya 
        cy.get('.open > .child-dropdown > :nth-child(1) > .dropdown-item').contains("Product").click()
        
        //global variabel 
    for(var i=0;i<product_update.length;i++){
        //tindakan Update 
        cy.get('.btn.btn-primary.dropdown-toggle').contains("Action").click({force:true})
        
        cy.get('.dropdown-item').contains("Edit").click({force:true})
    
        //Product Name
        if(product_update[i].product_name != null){
            //assertion
            cy.get('.btn-input-form-data').should('contain', "SAVE")
    
            cy.get('[name|="namaValidation"]').click({multiple:true}).clear().type(product_update[i].product_name)
        }
        else{
            cy.get('[name|="namaValidation"]').click({force:true}).end()
        }
        //Product Code
        if(product_update[i].product_code != null){
            cy.get('[name|="kodeValidation"]').click({multiple:true}).clear().type(product_update[i].product_code)
        }
        else{
            cy.get('[name|="kodeValidation"]').click({multiple:true}).end()
        }
    
        //Unit
        if(product_update[i].unit != null){
            cy.get(':nth-child(3) > div.ng-tns-c22-48 > .ng-tns-c22-48 > .ui-select-container > .ui-select-match > .btn').click({force:true})
    
            cy.get('.dropdown-item').contains(product_update[i].unit)
        }else{
            cy.get(':nth-child(3) > div.ng-tns-c22-39 > .ng-tns-c22-39 > .ui-select-container > .ui-select-match > .btn').end()
        }
    
        //Product Category 
        if(product_update[i].product_category != null){
            cy.get(':nth-child(4) > div.ng-tns-c22-48 > .ng-tns-c22-48 > .ui-select-container > .ui-select-match > .btn-default').click({force:true})
    
            cy.get('.dropdown-item').contains(product_update[i].product_category).click({force:true})
        }else{
            cy.get(':nth-child(4) > div.ng-tns-c22-39 > .ng-tns-c22-39 > .ui-select-container > .ui-select-match > .btn-default').end()
        }
    
        //Purchase Price 
        if(product_update[i].purchase_price != null){
            cy.get('[name|="purchaseValidation"]').click({force:true}).clear().type(product_update[i].purchase_price)
        }else{
            cy.get('[name|="purchaseValidation"]').click({force:true}).end()
        }
    
        //sales Price
        if(product_update[i].sales_price != null){
            cy.get('[name|="hargaValidation"]').click({force:true}).clear().type(product_update[i].sales_price)
        }else{
            cy.get('[name|="hargaValidation"]').click({force:true}).end()
        }
    
    
        //description
        if(product_update[i].description != null){
            cy.get('[name|="descriptionValidation"]').click({force:true}).clear().type(product_update[i].description)
        }else{
            cy.get('[name|="descriptionValidation"]').click({force:true}).end()
        }
        // //jika di klik ga bisa di save
        // //stok 
        //  cy.get('.location-initial > ng-select.ng-tns-c23-40 > .ui-select-container > .ui-select-match > .btn').contains("Select a Stock Location").click()
    
        // cy.get('.ui-select-choices-row > .dropdown-item').contains(
        // product_update[i].update_stock).click({force:true})
    
        //button 
        cy.get('.btn-input-form-data[type="button"]').contains("SAVE").click({force:true})
    
        //ASSERTION after button save
        if(product_update[i].product_name == null) {
            cy.get('.ng-star-inserted').should('contain', '')
        }
        else{
            cy.get('.ng-star-inserted').should('contain', product_update[i].product_name)
        }
        if(product_update[i].product_code== null) {
            cy.get('.ui-datatable-data > :nth-child(1) > :nth-child(2)').should('have.value', '')
        }
        else{
            cy.get('.top-aligned-table.ng-star-inserted').should('contain', product_update[i].product_code)
        }
        if(product_update[i].unit == null ) {
            cy.get('.ui-datatable-data > :nth-child(1) > :nth-child(3)').should('contain', '')
        }
        else{
            cy.get('.top-aligned-table.ng-star-inserted').should('contain',product_update[i].unit)
        }
        if(product_update[i].product_category== null) {
            cy.get('.ui-datatable-data > :nth-child(1) > :nth-child(4)').should('contain', '')
        }
        else{
            cy.get('.top-aligned-table.ng-star-inserted').should('contain', product_update[i].product_category)
        }
        if(product_update[i].purchase_price== null ) {
            cy.get('.ui-datatable-data > :nth-child(1) > :nth-child(5)').should('contain', '')
        }
        else{
            cy.get('.top-aligned-table.ng-star-inserted').should('contain', product_update[i].purchase_price)
        }
        if(product_update[i].sales_price== null) {
            cy.get('.ui-datatable-data > :nth-child(1) > :nth-child(7)').should('contain', '')
        }
        else{
            cy.get('.top-aligned-table.ng-star-inserted').should('contain', product_update[i].sales_price)
        }
        if(product_update[i].description== null) {
            cy.get('.ui-datatable-data > :nth-child(1) > :nth-child(8)').should('contain', '')
        }
        else{
            cy.get('.top-aligned-table.ng-star-inserted').should('not.have.value', product_update[i].description)
        }
    
    
        cy.url().should('include','/invoicer/product')
        }
    
    
    }
    
    
    
    
    //file function
    import {productupdate} from
    '../test_func/product_update.js'
    
    describe("Product", function(){
        
        beforeEach(function () {
          cy.login(); 
        });
        
        it("Update Product", function(){
            //Change partner type with Supplier or Client or Both
            var product_update=[{
              "product_name"      : "LCD Series Baru", 
              "product_code"      : "SER0", 
              "unit"              : null, 
              "product_category"  : null, 
              "purchase_price"    : null, 
              "sales_price"       : null, 
              "description"       : "Layar Seri 1", 
              "update_stock"      : null
              
            },
            {
              "product_name"      : "LCD", 
              "product_code"      : "BMW", 
              "unit"              : "Piece", 
              "product_category"  : "Television", 
              "purchase_price"    : "25555000", 
              "sales_price"       : "20,000", 
              "description"       : "Layar LCD", 
              "update_stock"      :"Stock"
            }
            
          
          
          ];
            
            productupdate(product_update);
            
    	});
    });

    `

    【讨论】:

      猜你喜欢
      • 2012-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 2011-08-17
      • 1970-01-01
      相关资源
      最近更新 更多