我们如何使用Cypress.io测试Google地图上标记的显示?

时间:2018-08-26 02:46:34

标签: javascript cypress

我们如何使用Cypress.io测试Google地图上标记的显示? 我不知道如何使用哪种方法来查找显示在Google地图上的标记。

describe('Display of marker on Google map', function(){
  it.only('Check the display of marker on Google map', function(){
  cy.visit('https://www.google.co.nz/maps/@-36.9139788,174.8740846,15z?hl=en')
    cy.get('#searchboxinput').type('gold coast')
     //don't know how to select Gold Coast from the populated search items
    //How to find a marker displayed on Google Map ?
  })
})

2 个答案:

答案 0 :(得分:0)

According to the docs,这是一种反模式:

  

反模式:尝试访问不受控制的站点或服务器或与之交互。

Also from the docs,这可能是从生成的页面获取信息的最佳选择:

cy.visit('index.html').then((contentWindow) => {
  // contentWindow is the remote page's window object
})

答案 1 :(得分:0)

我不会尝试断言 Google Maps 上的标记,而是对发送的 HTTP 请求进行断言。您可以使用 cy.request() 方法并断言您得到的是 200 status response,如下所示:

describe('Display of marker on Google map', () => {
  it('Check the display of marker on Google map', () => {
    cy.visit('https://www.google.co.nz/maps/@-36.9139788,174.8740846,15z?hl=en');
    cy.get('#searchboxinput').type('gold coast{enter}');
    cy.request('GET', 'https://www.google.co.nz/search?tbm=map').then(res =>
      expect(res.status).to.eq(200) // assert the status response is a success
    );
  });
});

如果您仍然绝对需要断言标记。您可以尝试使用 cypress-image-snapshot 之类的插件进行两次搜索并断言图像快照匹配。

您还可以探索其他 Visual Testing plugins