0

使用editablegrid.net。真的很喜欢布局和功能。唯一的问题是功能测试。在 capybara 中似乎没有任何效果 - 页面快照不显示实际网格的页面内容,匹配器看不到在 js 中呈现的内容。

我必须使用较旧的 phantom (v1.9.2),因为 mac os x 上似乎还没有对 capybara 的支持。

任何人有任何运气功能测试?

尝试过的事情

  • 页面刷新:page.driver.browser.navigate.refresh
  • 确保使用 turbolinks 事件进行加载
  • 尝试过硒和恶作剧

设置详细信息

版本

        rails 4.1.0
        capybara (2.9.1)
        rspec (3.5.0)
        phantomjs 192

        selenium-webdriver (2.53.4)

        poltergeist (1.5.1)
          capybara (~> 2.1)
          cliver (~> 0.3.1)
          multi_json (~> 1.0)
          websocket-driver (>= 0.2.0)

    $ phantomjs -v
    1.9.2

更新 更新版本

   $ phantomjs -v
    2.1.1
    $ gem list | grep polter
    poltergeist (1.10.0)
    $ selenium-webdriver (2.53.4)

但是当我做一个简单的测试时

      visit 'address_books/'+user.address_book.id.to_s
      page.save_screenshot("file1.png", :full => true)
      sleep 4.seconds # just in case the delayed redraw takes time
      page.save_screenshot("file2.png", :full => true)
      expect(page).to have_content(/Person A.*2 8888 9999.*home/)

此页面包含editablegrid在开发中运行良好的(参见示例屏幕截图(http://imgbox.com/rqwx1vHe))不会在保存屏幕截图(http://imgbox.com/t1CG6hQa)中呈现

其他注意事项

  • 我也试过 selenium,同样的问题:很明显网格没有显示。
  • 我已经使用涡轮链接加载事件来触发页面加载。

网格代码

                  var editableGrid = null;
        $(document).on('turbolinks:load', function() {
                        editableGrid = new EditableGrid("AddressBookGridJSON"); 
                        editableGrid.tableLoaded = function() { this.renderGrid("tablecontent", "testgrid"); };
                        editableGrid.loadJSON('/address_books.json');
                        // $.getJSON('/address_books.json', function(json) {
                        //     editableGrid.load({"metadata": json.metadata,              "data": json.data});
                        //     console.log(editableGrid);
                        // });
                    }); 

更新 2

index.json.jbuilder

        json.set! :metadata do
        json.array! @address_book.generate_view_table_meta_data
        end

        json.set! :data do
            json.array! @contacts do |contact|
              json.id contact.id
                  json.set! :values do
                      json.name contact.name
                      json.phone_number contact.get_presentation_number
                      json.phone_type contact.get_humanize_phone_type
                      json.action contact.get_url_to_view_delete
                  end
            end
        end

更新 3

已加载数据库清理代码

需要 'database_cleaner' RSpec.configure 做 |config| config.before(:each) 做 DatabaseCleaner.clean_with(:truncation) 结束

      config.before(:each) do
        #DatabaseCleaner.strategy = :transaction
        # if we use transaction the data is NOT saved during the actual rspec scenario. we must have commit
        # during rspec so external compare processs can access data
        # TODO make this conditional based on the compare plans process only

        # tests will not have :nontransactional defined except compareplans testing
        if self.class.metadata[:nontransactional]
          DatabaseCleaner.strategy = :truncation
        else
          DatabaseCleaner.strategy = :transaction
        end
      end

      config.before(:each, :js => true) do
        DatabaseCleaner.strategy = :truncation
      end

      config.before(:each) do
        DatabaseCleaner.start
      end

      config.append_after(:each) do
        DatabaseCleaner.clean
      end
    end
4

0 回答 0