如何在量角器

时间:2016-07-04 10:56:50

标签: selenium protractor

我的conf.js文件在本地运行正常。但是现在根据我的要求,我需要在竹子任务中运行它。由于我的代码将在服务器上运行,因此我需要将一个远程selenium webdriver添加到conf.js.

你可以帮我解决它是怎么做的吗?我的conf.js看起来像这样:

exports.config = {
     params: {
        url: "URL",
        testroadname:"Testing123",
        sleeptime:1000

    },
  directConnect: true,




  // Capabilities to be passed to the webdriver instance.
  capabilities: {
    'browserName': 'chrome'
  },

  // Framework to use. Jasmine is recommended.
  framework: 'jasmine',

  // Spec patterns are relative to the current working directly when
  // protractor is called.
  specs: ['mapfeedback.js'],

  // Options to be passed to Jasmine.
  jasmineNodeOpts: {

    defaultTimeoutInterval: 30000
  }

2 个答案:

答案 0 :(得分:3)

您必须删除directConnect = true并在配置中提供seleniumAddress或设置environment.js文件 - 您只需添加远程selenium的地址并启动您的量角器测试,以下将是您的environment.js -

  // Common configuration files with defaults plus overrides from environment vars
var webServerDefaultPort = 8081;

module.exports = {
// The address of a running selenium server.You can add your remote address here
seleniumAddress:
(process.env.SELENIUM_URL || 'http://localhost:4444/wd/hub'),

// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName':
    (process.env.TEST_BROWSER_NAME || 'chrome'),
'version':
    (process.env.TEST_BROWSER_VERSION || 'ANY')
},

 // Default http port to host the web server
webServerDefaultPort: webServerDefaultPort,

 // Protractor interactive tests
 interactiveTestPort: 6969,

 // A base URL for your application under test.
 baseUrl:
'http://' + (process.env.HTTP_HOST || 'localhost') +
      ':' + (process.env.HTTP_PORT || webServerDefaultPort)

};

您的配置文件看起来像 -

 var env = require('./environment.js');
 exports.config = {
 params: {
    url: "URL",
    testroadname:"Testing123",
    sleeptime:1000

  },
 seleniumAddress: env.seleniumAddress,


  // Capabilities to be passed to the webdriver instance.
  capabilities: {
'browserName': 'chrome'
 },

// Framework to use. Jasmine is recommended.
 framework: 'jasmine',

 // Spec patterns are relative to the current working directly when
 // protractor is called.
 specs: ['mapfeedback.js'],

 // Options to be passed to Jasmine.
 jasmineNodeOpts: {

   defaultTimeoutInterval: 30000
 }

答案 1 :(得分:1)

为Protractor远程设置selenium-grid: -

  1. 使用命令启动集线器: -
  2. java -jar selenium-server-standalone-3.3.1.jar -role hub -port 4444

    1. 现在使用您要执行远程测试用例的命令启动远程节点: -
    2. java -jar selenium-server-standalone-3.3.1.jar -role webdriver -hub http://HubDomain-IP:4444/grid/register -port 5556 -browser browserName = internet explorer,maxInstances = 1,platform = WINDOWS,applicationName = remoteNode -Dwebdriver .ie.driver = IEDriverServer.exe的路径

      完成selenium-grid设置并将节点与Hub连接后,将配置文件配置为此conf.js文件: -

          exports.config = {
      
        //The address of your running selenium Hub server.
        seleniumAddress: 'http://HubDomain-IP:4444/wd/hub',
      
        //Capabilities to be passed to the webdriver instance.
        capabilities: {
          'browserName': 'internet explorer',
      
          // add node-name as applicationName where you have started node and wanted to remotely execute test cases 
          'applicationName': 'remoteNode'
        },
      
        //Specify the name of the specs files.
        specs: ['grid_spec.js'],
      
        //Options to be passed to Jasmine-node.
        jasmineNodeOpts: {
            onComplete: null,
            isVerbose: false,
            showColors: true,
            includeStackTrace: true
        }
      };
      

      使用上面提到的配置和设置命令,您可以为Protractor.Thanks运行selenium-grid设置!