在无头模式下使用selenium chrome节点时,量角器无法在页面上找到Angular

时间:2017-11-01 17:25:26

标签: protractor selenium-chromedriver google-chrome-headless

我使用量角器指令确定我可以使用无头浏览器。

按照说明......

conf.js

exports.config = {
  seleniumAddress: 'http://seleniumhub:4444/wd/hub',
  multiCapabilities: [
    {
        browserName: 'firefox',
        'moz:firefoxOptions': {
            args: [
                "--headless",
            ]
        }
    },
    {
        browserName: 'chrome',
        chromeOptions: {
            args: [
                // chrome will crash without this
                '--headless',
                "--disable-gpu",
            ]
        }

    }
  ],

  framework: 'jasmine2',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
  },
  specs: ['todo-spec.js']
};  

待办事项-spec.js

describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('https://angularjs.org');

element(by.model('todoList.todoText')).sendKeys('write first protractor test');
element(by.css('[value="add"]')).click();

var todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write first protractor test');

// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
});
});

从我的节点8.8.1容器中运行

./node_modules/.bin/protractor conf.js

标准的东西真的非常香草,因为我想找到罪魁祸首。

当测试运行时,firefox传递并且chrome失败并带有

  

E /量角器 - 无法在页面https://angularjs.org/上找到Angular:重试超出角度

任何线索/想法/建议?

我的" seleniumhub"是一个带有firefox和chrome节点的dockerised selenium网格。一切都在3.6.0版本上。

总结版本......

  • 节点8.8.1(泊坞窗)
  • Selenium Hub 3.6.0(docker)
  • Selenium Chrome Node 3.6.0(docker)
  • Selenium Firefox Node 3.6.0(docker)
  • 量角器5.2.0

此处还有 docker-compose.yml

version: "3.2"
services:

  seleniumhub:
    image: selenium/hub:${SELENIUM_VERSION}
    networks:
      - private
    ports:
      - 4444:4444
    environment:
    # As integer, maps to "maxSession"
      GRID_MAX_SESSION: 10
    # In milliseconds, maps to "newSessionWaitTimeout"
      GRID_NEW_SESSION_WAIT_TIMEOUT: -1
    # As a boolean, maps to "throwOnCapabilityNotPresent"
      GRID_THROW_ON_CAPABILITY_NOT_PRESENT: 'true'
    # As an integer
      GRID_JETTY_MAX_THREADS: -1
    # In milliseconds, maps to "cleanUpCycle"
      GRID_CLEAN_UP_CYCLE: 5000
    # In seconds, maps to "browserTimeout"
      GRID_BROWSER_TIMEOUT: 0
    # In seconds, maps to "timeout"
      GRID_TIMEOUT: 30
    # Debug
      GRID_DEBUG: 'false'
    depends_on:
      - webserver

  firefoxnode:
    image: selenium/node-firefox${SELENIUM_DEBUG}:${SELENIUM_VERSION}
    networks:
      - private
    volumes:
      - /dev/urandom:/dev/random
      - .:/tmp/app:cached
    depends_on:
      - seleniumhub
    environment:
      HUB_PORT_4444_TCP_ADDR: seleniumhub
      HUB_PORT_4444_TCP_PORT: 4444
      # https://stackoverflow.com/questions/13723349/selenium-grid-maxsessions-vs-maxinstances
      NODE_MAX_SESSION: 10
      NODE_MAX_INSTANCES: 10

  chromenode:
    image: selenium/node-chrome${SELENIUM_DEBUG}:${SELENIUM_VERSION}
    networks:
      - private
    volumes:
      - /dev/urandom:/dev/random:ro
      - /dev/shm:/dev/shm:ro
      - .:/tmp/app:cached
    depends_on:
      - seleniumhub
    environment:
      HUB_PORT_4444_TCP_ADDR: seleniumhub
      HUB_PORT_4444_TCP_PORT: 4444
      # https://stackoverflow.com/questions/13723349/selenium-grid-maxsessions-vs-maxinstances
      NODE_MAX_SESSION: 10
      NODE_MAX_INSTANCES: 10

  node:
    depends_on:
      - seleniumhub

非常感谢提前

1 个答案:

答案 0 :(得分:0)

所以罪魁祸首是/ dev / urandom和/ dev / shm共享。 如果它们被删除,一切正常。

这些是硒2.53.1所必需的,但不是当前版本。

所以享受其余的配置。它只是有效。 :)