Capybara:js => true导致测试失败

时间:2016-07-01 04:29:05

标签: javascript ruby-on-rails selenium capybara

我几天前开始使用Capybara,之前从未使用过Selenium。 我想看看我的测试如何在beowser中执行并使用它为gem #ifndef X265_LOWRES_H #define X265_LOWRES_H #include "primitives.h" #include "common.h" #include "picyuv.h" #include "mv.h" namespace X265_NS { // private namespace struct ReferencePlanes { ReferencePlanes() { memset(this, 0, sizeof(ReferencePlanes)); } pixel* fpelPlane[3]; pixel* lowresPlane[4]; PicYuv* reconPic; bool isWeighted; bool isLowres; intptr_t lumaStride; intptr_t chromaStride; struct { int weight; int offset; int shift; int round; } w[3]; pixel* getLumaAddr(uint32_t ctuAddr, uint32_t absPartIdx) { return fpelPlane[0] + reconPic->m_cuOffsetY[ctuAddr] + reconPic->m_buOffsetY[absPartIdx]; } pixel* getCbAddr(uint32_t ctuAddr, uint32_t absPartIdx) { return fpelPlane[1] + reconPic->m_cuOffsetC[ctuAddr] + reconPic->m_buOffsetC[absPartIdx]; } pixel* getCrAddr(uint32_t ctuAddr, uint32_t absPartIdx) { return fpelPlane[2] + reconPic->m_cuOffsetC[ctuAddr] + reconPic->m_buOffsetC[absPartIdx]; } /* lowres motion compensation, you must provide a buffer and stride for QPEL averaged pixels * in case QPEL is required. Else it returns a pointer to the HPEL pixels */ inline pixel *lowresMC(intptr_t blockOffset, const MV& qmv, pixel *buf, intptr_t& outstride) { if ((qmv.x | qmv.y) & 1) { int hpelA = (qmv.y & 2) | ((qmv.x & 2) >> 1); pixel *frefA = lowresPlane[hpelA] + blockOffset + (qmv.x >> 2) + (qmv.y >> 2) * lumaStride; int qmvx = qmv.x + (qmv.x & 1); int qmvy = qmv.y + (qmv.y & 1); int hpelB = (qmvy & 2) | ((qmvx & 2) >> 1); pixel *frefB = lowresPlane[hpelB] + blockOffset + (qmvx >> 2) + (qmvy >> 2) * lumaStride; primitives.pu[LUMA_8x8].pixelavg_pp(buf, outstride, frefA, lumaStride, frefB, lumaStride, 32); return buf; } else { outstride = lumaStride; int hpel = (qmv.y & 2) | ((qmv.x & 2) >> 1); return lowresPlane[hpel] + blockOffset + (qmv.x >> 2) + (qmv.y >> 2) * lumaStride; } } inline int lowresQPelCost(pixel *fenc, intptr_t blockOffset, const MV& qmv, pixelcmp_t comp) { if ((qmv.x | qmv.y) & 1) { ALIGN_VAR_16(pixel, subpelbuf[8 * 8]); int hpelA = (qmv.y & 2) | ((qmv.x & 2) >> 1); pixel *frefA = lowresPlane[hpelA] + blockOffset + (qmv.x >> 2) + (qmv.y >> 2) * lumaStride; int qmvx = qmv.x + (qmv.x & 1); int qmvy = qmv.y + (qmv.y & 1); int hpelB = (qmvy & 2) | ((qmvx & 2) >> 1); pixel *frefB = lowresPlane[hpelB] + blockOffset + (qmvx >> 2) + (qmvy >> 2) * lumaStride; primitives.pu[LUMA_8x8].pixelavg_pp(subpelbuf, 8, frefA, lumaStride, frefB, lumaStride, 32); return comp(fenc, FENC_STRIDE, subpelbuf, 8); } else { int hpel = (qmv.y & 2) | ((qmv.x & 2) >> 1); pixel *fref = lowresPlane[hpel] + blockOffset + (qmv.x >> 2) + (qmv.y >> 2) * lumaStride; return comp(fenc, FENC_STRIDE, fref, lumaStride); } } }; /* lowres buffers, sizes and strides */ struct Lowres : public ReferencePlanes { pixel *buffer[4]; int frameNum; // Presentation frame number int sliceType; // Slice type decided by lookahead int width; // width of lowres frame in pixels int lines; // height of lowres frame in pixel lines int leadingBframes; // number of leading B frames for P or I bool bScenecut; // Set to false if the frame cannot possibly be part of a real scenecut. bool bKeyframe; bool bLastMiniGopBFrame; /* lookahead output data */ int64_t costEst[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2]; int64_t costEstAq[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2]; int32_t* rowSatds[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2]; int intraMbs[X265_BFRAME_MAX + 2]; int32_t* intraCost; uint8_t* intraMode; int64_t satdCost; uint16_t* lowresCostForRc; uint16_t(*lowresCosts[X265_BFRAME_MAX + 2][X265_BFRAME_MAX + 2]); int32_t* lowresMvCosts[2][X265_BFRAME_MAX + 1]; MV* lowresMvs[2][X265_BFRAME_MAX + 1]; uint32_t maxBlocksInRow; uint32_t maxBlocksInCol; /* used for vbvLookahead */ int plannedType[X265_LOOKAHEAD_MAX + 1]; int64_t plannedSatd[X265_LOOKAHEAD_MAX + 1]; int indB; int bframes; /* rate control / adaptive quant data */ double* qpAqOffset; // AQ QP offset values for each 16x16 CU double* qpCuTreeOffset; // cuTree QP offset values for each 16x16 CU int* invQscaleFactor; // qScale values for qp Aq Offsets uint32_t* blockVariance; uint64_t wp_ssd[3]; // This is different than SSDY, this is sum(pixel^2) - sum(pixel)^2 for entire frame uint64_t wp_sum[3]; uint64_t frameVariance; /* cutree intermediate data */ uint16_t* propagateCost; double weightedCostDelta[X265_BFRAME_MAX + 2]; ReferencePlanes weightedRef[X265_BFRAME_MAX + 2]; bool create(PicYuv *origPic, int _bframes, bool bAqEnabled); void destroy(); void init(PicYuv *origPic, int poc); }; } 。 我在Capybara有下一个测试:

selenium-webdriver

RSpec.feature 'Authentication', :type => :feature do def register_with_form visit '/' click_on 'Account' click_on 'Register' fill_in 'Email', :with => 'test@example.com' fill_in 'Name', :with => 'John' fill_in 'Last name', :with => 'Smith' fill_in 'Password', :with => '1234567890' fill_in 'Password confirmation', :with => '1234567890' find('.testing-sign-up-class') click_button 'Sign up' expect(page).to have_css '.hd-title', 'Get Started' end scenario 'User registers' do register_with_form expect(page).to have_css '.hd-title', 'Get Started' expect(page).to have_css '.alert-success', 'Welcome! You have signed up successfully.' expect(page).to have_css '.panel-title', 'What would you like to use GridHub for?' end scenario 'User sign out', :js => true do register_with_form click_on 'Account' click_on 'Logout' expect(page).to have_css '.alert-success', 'Signed out successfully.' end end 添加到任何:js => true破解测试中。 控制台显示:

scenario

我添加了gem database_cleaner,我的 1) Authentication When not registered User sign out Failure/Error: click_button 'Sign up' Selenium::WebDriver::Error::UnknownError: Element is not clickable at point (606, 23.73333740234375). Other element would receive the click: <input autocomplete="off" name="term" id="term" class="form-control nav-search-field main-ac autocomplete ui-autocomplete-input" placeholder="search items" data-url="/search" type="text"> 有下一个代码:

spec_helper.rb

我的 config.before(:each, type: :feature) do driver_shares_db_connection_with_specs = Capybara.current_driver == :rack_test if !driver_shares_db_connection_with_specs DatabaseCleaner.strategy = :truncation end end config.before(:each) do DatabaseCleaner.start end config.append_after(:each) do DatabaseCleaner.clean end 文件有下一行:

bin/rspec

感谢。

更新

我认为浏览器中可能存在其他问题。在某些情况下,当测试打开浏览器时(因为我遇到了firefox和chrome),而某些元素可能会在“浏览器窗口下方”,在这种情况下测试失败,导致无法找到必要的按钮。 如果我有时间向下滚动浏览器窗口,一些测试可能会成功。

1 个答案:

答案 0 :(得分:0)

使用任何支持JS的驱动程序click_button时,只需单击按钮然后继续。它不会等待页面上的任何内容发生变化,因为它无法知道预期会发生什么变化。我的猜测是,当您的测试调用register_with_form并返回时,它会立即点击“帐户”#39;链接与表单位于同一页面上。这将最终取消注册提交并转到没有注销链接的页面。要解决此问题,您需要将register_with_form的最后一行设为expect(page).to have_content('Welcome!'),以便在注册完成之前不会返回。

此外,使用https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example中建议的database_cleaner设置(append_after非常重要)而不是您拥有的设置,或者您最终难以诊断数据库在请求之前开始清理的问题已经完成等等。