Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Selenium和Node.js进行自动化测试_Javascript_Testing_Npm_Lambda_Cross Browser - Fatal编程技术网

Javascript 使用Selenium和Node.js进行自动化测试

Javascript 使用Selenium和Node.js进行自动化测试,javascript,testing,npm,lambda,cross-browser,Javascript,Testing,Npm,Lambda,Cross Browser,我正在尝试使用LambdaTest编写Selenium和JS的自动测试,我遵循了视频中的所有步骤 安装Nodejs 下载Selenium(npm安装Selenium webdriver) 下载Chromedriver 试验 然而,当我运行最后一个命令“node test.js”时,我总是遇到这个错误。你知道我哪里做错了吗 > c:\***>node test.js (node:15708) > UnhandledPromiseRejectionWarning: Error: E

我正在尝试使用LambdaTest编写Selenium和JS的自动测试,我遵循了视频中的所有步骤

安装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();