Angularjs 使用Cloud9时如何使量角器工作?

Angularjs 使用Cloud9时如何使量角器工作?,angularjs,cloud,protractor,Angularjs,Cloud,Protractor,我是Cloud9的新手,我正在尝试使用量角器进行e2e测试。我正在运行angular phonecat示例 错误如下: Using ChromeDriver directly... /home/ubuntu/workspace/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109 var template = new Error(this.message);

我是Cloud9的新手,我正在尝试使用量角器进行e2e测试。我正在运行angular phonecat示例

错误如下:

Using ChromeDriver directly...
/home/ubuntu/workspace/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109
  var template = new Error(this.message);
                 ^
UnknownError: chrome not reachable
  (Driver info: chromedriver=2.10.267518,platform=Linux 3.14.13-c9 x86_64)
    at new bot.Error (/home/ubuntu/workspace/node_modules/protractor/node_modules/selenium-webdriver/lib/atoms/error.js:109:18)
..
我安装了chromedriver。唯一的问题是如何在cloud9上安装真正的Chrome并运行测试

提前谢谢大家,

干杯,
Haytham不可能在cloud9上“安装”浏览器来运行基于浏览器的端到端测试场景。selenium web驱动程序希望加载chrome来运行测试,但是抛出了一个错误,因为在cloud9开发环境中找不到它

如果您致力于在cloud9这样的在线IDE上运行这些测试,那么您唯一的选择就是使用phantomJS这样的无头浏览器,但需要注意量角器文档

我们建议不要在带有量角器的测试中使用PhantomJS。有很多关于PhantomJS崩溃和行为与真实浏览器不同的报道

我建议您在本地下载您的应用程序,并跨浏览器运行广泛的E2E测试,您的用户将实际使用这些浏览器访问您的应用程序


另一种选择是使用Saucelabs()之类的工具进行自动化的基于云的跨浏览器测试;这需要在
量角器_conf.js
文件中进行一些配置。请注意,基于云的测试可能会带来额外的成本。

我是webase IDE的粉丝,也是最好的测试之一。这里介绍了一种在Cloud9上安装Xvfb、chrome和进行端到端自动测试的方法

打开一个终端(c9.io上已经安装了xvfb)

  • 安装X11字体

    $ sudo apt-get install -y xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
    
  • 安装最后一个chrome

    $ wget -q -O - \
      https://dl-ssl.google.com/linux/linux_signing_key.pub \
      | sudo apt-key add - 
    $ sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main"  \
      >> /etc/apt/sources.list.d/google-chrome.list'
    $ sudo apt-get update 
    $ sudo apt-get install -y google-chrome-stable
    
  • 安装量角器

    $ npm install -g protractor
    
  • 更新webdriver

    $ webdriver-manager update
    
  • 使用--chrome中没有沙盒选项

    由于c9.io在容器内运行,因此需要此选项。
    更新progrator conf.js以将选项传递给chrome

    capabilities: {
      browserName: 'chrome',
      'chromeOptions': {
        args: ['--no-sandbox'] 
      }   
    }
    
对无头铬合金进行量角器测试

  • 使用xvfb启动webdriver(无头)

  • 在其他终端上运行测试

    $ protrator conf.js
    

我刚刚测试了这个,它在我的chromebook上对我有效。它包含完成的第一页所需的所有步骤,包括设置量角器测试

create new blank workspace

run these commands
  rm -rf * .c9
  git clone --depth=16 https://github.com/angular/angular-phonecat.git
  cd angular-phonecat
  nvm install 7
  nvm alias default node
  npm install minimatch
  sudo npm install npm -g


edit this file
  angular-phonecat/package.json
    "start": "http-server ./app -a $IP -p $PORT -c-1"

run these commands
  npm start

click 'Share'
browse to url next to 'Application'

yay! the phonecat webapp should be running!



karma
  add these lines to karma.conf.js
    hostname: process.env.IP,
    port: process.env.PORT
  edit package.json
    "test": "karma start karma.conf.js --no-browsers"
  run this command
    npm test
  browse to http://<projectName>.<cloud9User>.c9.io:8081
  go forth and test!



protractor
  run these commands
    sudo apt-get update
    sudo apt-get install -y xvfb
    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
    sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
    sudo apt-get update
    sudo apt-get install -y google-chrome-stable
  edit protractor.conf.js
    capabilities: {
      'browserName': 'chrome',
      'chromeOptions': {
        args: ['--no-sandbox']
      }
    }
  run these commands
    npm install -g protractor
    sudo webdriver-manager update
    xvfb-run webdriver-manager start
  edit protractor.conf.js
    baseUrl: 'http://' + process.env.IP + ':' + process.env.PORT + '/'
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub'
  run these commands
    protractor protractor.conf.js
创建新的空白工作区
运行这些命令
rm-rf*.c9
git克隆--深度=16https://github.com/angular/angular-phonecat.git
角形音标
nvm安装7
nvm别名默认节点
npm安装最小匹配
sudo npm安装npm-g
编辑此文件
angular phonecat/package.json
“开始”:“http服务器./app-a$IP-p$PORT-c-1”
运行这些命令
npm启动
单击“共享”
浏览到“应用程序”旁边的url
耶!phonecat网络应用程序应该正在运行!
因果报应
将这些行添加到karma.conf.js
主机名:process.env.IP,
端口:process.env.port
编辑package.json
“测试”:“karma start karma.conf.js--无浏览器”
运行此命令
npm试验
浏览到http://..c9.io:8081
去试试吧!
量角器
运行这些命令
更新源
sudo apt get安装-y xvfb
wget-q-O-https://dl-ssl.google.com/linux/linux_signing_key.pub |sudoapt键添加-
sudo sh-c'echo“deb[arch=amd64]http://dl.google.com/linux/chrome/deb/ 稳定的main“>>/etc/apt/sources.list.d/google chrome.list”
更新源
sudo apt获得安装-y谷歌浏览器稳定
编辑progrator.conf.js
能力:{
'browserName':'chrome',
“颜色选项”:{
args:['--无沙盒']
}
}
运行这些命令
npm安装-g量角器
sudowebdriver管理器更新
xvfb运行webdriver管理器启动
编辑progrator.conf.js
baseUrl:'http://'+process.env.IP+':'+process.env.PORT+'/'
赛琳娜的裙子:'http://127.0.0.1:4444/wd/hub'
运行这些命令
progrator progrator.conf.js

必须在当前版本的c9.io上安装xvfb:
sudo apt get install-y xvfb
如果遇到
无法找到预期条目“main/binary-i386/Packages”
错误,请更改
debhttp://dl.google.com/linux/chrome/deb/ 稳定干管
to
deb[arch=amd64] http://dl.google.com/linux/chrome/deb/ 稳定的主电源
create new blank workspace

run these commands
  rm -rf * .c9
  git clone --depth=16 https://github.com/angular/angular-phonecat.git
  cd angular-phonecat
  nvm install 7
  nvm alias default node
  npm install minimatch
  sudo npm install npm -g


edit this file
  angular-phonecat/package.json
    "start": "http-server ./app -a $IP -p $PORT -c-1"

run these commands
  npm start

click 'Share'
browse to url next to 'Application'

yay! the phonecat webapp should be running!



karma
  add these lines to karma.conf.js
    hostname: process.env.IP,
    port: process.env.PORT
  edit package.json
    "test": "karma start karma.conf.js --no-browsers"
  run this command
    npm test
  browse to http://<projectName>.<cloud9User>.c9.io:8081
  go forth and test!



protractor
  run these commands
    sudo apt-get update
    sudo apt-get install -y xvfb
    wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
    sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list'
    sudo apt-get update
    sudo apt-get install -y google-chrome-stable
  edit protractor.conf.js
    capabilities: {
      'browserName': 'chrome',
      'chromeOptions': {
        args: ['--no-sandbox']
      }
    }
  run these commands
    npm install -g protractor
    sudo webdriver-manager update
    xvfb-run webdriver-manager start
  edit protractor.conf.js
    baseUrl: 'http://' + process.env.IP + ':' + process.env.PORT + '/'
    seleniumAddress: 'http://127.0.0.1:4444/wd/hub'
  run these commands
    protractor protractor.conf.js