Автоматизация тестирования с Selenium и Node.js - PullRequest
1 голос
/ 04 июля 2019

Я пытаюсь написать автоматический тест с использованием Selenium и JS с помощью LambdaTest, я выполнил все шаги в этом видео https://www.youtube.com/watch?v=6XbgNXcLUSE&t=370s

Установить Nodejs Скачать Selenium (npm установить selenium-webdriver) Скачать Chromedriver Тест

Как всегда, когда я запускаю последнюю команду "node test.js", я продолжаю получать эту ошибку. Любая идея, где я делал неправильно?

> c:\***>node test.js (node:15708)
> UnhandledPromiseRejectionWarning: Error: ETIMEDOUT connect ETIMEDOUT
> 35.157.187.40:443
>     at ClientRequest.<anonymous> (c:\****\node_modules\selenium-webdriver\http\index.js:258:15)
>     at ClientRequest.emit (events.js:198:13)
>     at TLSSocket.socketErrorListener (_http_client.js:392:9)
>     at TLSSocket.emit (events.js:198:13)
>     at emitErrorNT (internal/streams/destroy.js:91:8)
>     at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
>     at process._tickCallback (internal/process/next_tick.js:63:19) (node:15708) UnhandledPromiseRejectionWarning: Unhandled promise
> rejection. This error originated either by throwing inside of an async
> function without a catch block, or by rejecting a promise which was
> not handled with .catch(). (rejection id: 1) (node:15708) [DEP0018]
> DeprecationWarning: Unhandled promise rejections are deprecated. In
> the future, promise rejections that are not handled will terminate the
> Node.js process with a non-zero exit code. (node:15708)
> UnhandledPromiseRejectionWarning: Error: ETIMEDOUT connect ETIMEDOUT
> 35.157.187.40:443
>     at ClientRequest.<anonymous> (c:\***\node_modules\selenium-webdriver\http\index.js:258:15)
>     at ClientRequest.emit (events.js:198:13)
>     at TLSSocket.socketErrorListener (_http_client.js:392:9)
>     at TLSSocket.emit (events.js:198:13)
>     at emitErrorNT (internal/streams/destroy.js:91:8)
>     at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
>     at process._tickCallback (internal/process/next_tick.js:63:19) (node:15708) UnhandledPromiseRejectionWarning: Unhandled promise
> rejection. This error originated either by throwing inside of an async
> function without a catch block, or by rejecting a promise which was
> not handled with .catch(). (rejection id: 2)
/*
    LambdaTest selenium automation sample example
    Configuration
    ----------
    username: Username can be found at automation dashboard
    accessKey:  AccessKey can be generated from automation dashboard or profile section

    Result
    -------
    Execute NodeJS Automation Tests on LambdaTest Distributed Selenium Grid
*/
const webdriver = require("selenium-webdriver");

/*
    Setup remote driver
    Params
    ----------
    platform : Supported platform - (Windows 10, Windows 8.1, Windows 8, Windows 7,  macOS High Sierra, macOS Sierra, OS X El Capitan, OS X Yosemite, OS X Mavericks)
    browserName : Supported platform - (chrome, firefox, Internet Explorer, MicrosoftEdge, Safari)
    version :  Supported list of version can be found at https://www.lambdatest.com/capabilities-generator/
*/

// username: Username can be found at automation dashboard
const USERNAME = "hide";

// AccessKey:  AccessKey can be generated from automation dashboard or profile section
const KEY = "hide";

// gridUrl: gridUrl can be found at automation dashboard
const GRID_HOST = "hub.lambdatest.com/wd/hub";

function searchTextOnGoogle() {
  // Setup Input capabilities
  const capabilities = {
    platform: "windows 10",
    browserName: "chrome",
    version: "67.0",
    resolution: "1280x800",
    network: true,
    visual: true,
    console: true,
    video: true,
    name: "Test 123", // name of the test
    build: "NodeJS build 23" // name of the build
  };

  // URL: https://{username}:{accessKey}@hub.lambdatest.com/wd/hub
  const gridUrl = "https://" + USERNAME + ":" + KEY + "@" + GRID_HOST;

  // setup and build selenium driver object
  const driver = new webdriver.Builder()
    .usingServer(gridUrl)
    .withCapabilities(capabilities)
    .build();

  // // navigate to a url, search for a text and get title of page
  // driver.get('https://www.google.com/ncr').then(function() {
  //     driver.findElement(webdriver.By.name('q')).sendKeys('LambdaTest\n').then(function() {
  //         driver.getTitle().then(function(title) {
  //             setTimeout(function() {
  //                 console.log(title);
  //                 driver.quit();
  //             }, 5000);
  //         });
  //     });
  // });

  driver.get("https://www.google.com").then(function() {
    driver
      .findElement(webdriver.By.linkText("Automation"))
      .click()
      .then(function() {
        driver.getTitle().then(function(title) {
          setTimeout(function() {
            console.log(title);
            driver.quit();
          }, 5000);
        });
      });
  });
}
searchTextOnGoogle();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...