Getting Selenium to pause for X seconds

后端 未结 6 2086
小蘑菇
小蘑菇 2020-12-06 16:24

What I am trying to accomplish is browsing to a page, waiting for something to load and then taking and saving a screenshot.

The code I already have is



        
6条回答
  •  臣服心动
    2020-12-06 16:44

    const { By, until } = require('selenium-webdriver');
    
    
    this.wait = async function (amount: number) {
          try {
            await this.driver.wait(
              until.elementLocated(By.css('[data-test-id="does-not-exist"]')),
              amount,
              'Looking for element'
            );
          } catch (e) {
            console.log('waiting')
          }
    

    We look for a css identifier that isn't there for x amount of seconds. This is typescript btw. This would be a method on some relevant class, or a function by itself. Use it like this

      const button = await this.findByCSSSelector('[data-test-id="get-quote-button"]')
      const actions = this.driver.actions({ bridge: true }); 
      await actions.move({origin: button }).perform();
    
      // Small pause to observe animation is working correctly in all browsers
      await this.wait(700)
    
      const carat = await this.findByCSSSelector('[data-test-id="carat"]');
    

    This waits for .7 of a second so that you can see that whatever animation is working in your functional tests.

提交回复
热议问题