├── .gitignore ├── Gemfile ├── Gemfile.lock ├── LICENSE.txt ├── README.md ├── Rakefile ├── lib ├── protractor-rails.rb ├── protractor │ ├── rails.rb │ └── rails │ │ ├── configuration.rb │ │ ├── railtie.rb │ │ └── version.rb └── tasks │ ├── install.rake │ └── protractor.rake ├── protractor-rails.gemspec └── spec ├── example_spec.js ├── javascripts └── templates │ ├── example_spec.js │ └── protractor.conf.js └── protractor_example.conf.js /.gitignore: -------------------------------------------------------------------------------- 1 | .ruby-gemset 2 | spec/javascripts/protractor.conf.js 3 | spec/javascripts/example_spec.js 4 | pkg 5 | .DS_Store -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in protractor-rails.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | protractor-rails (0.0.19) 5 | colorize 6 | railties 7 | 8 | GEM 9 | remote: https://rubygems.org/ 10 | specs: 11 | actionpack (4.2.6) 12 | actionview (= 4.2.6) 13 | activesupport (= 4.2.6) 14 | rack (~> 1.6) 15 | rack-test (~> 0.6.2) 16 | rails-dom-testing (~> 1.0, >= 1.0.5) 17 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 18 | actionview (4.2.6) 19 | activesupport (= 4.2.6) 20 | builder (~> 3.1) 21 | erubis (~> 2.7.0) 22 | rails-dom-testing (~> 1.0, >= 1.0.5) 23 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 24 | activesupport (4.2.6) 25 | i18n (~> 0.7) 26 | json (~> 1.7, >= 1.7.7) 27 | minitest (~> 5.1) 28 | thread_safe (~> 0.3, >= 0.3.4) 29 | tzinfo (~> 1.1) 30 | builder (3.2.2) 31 | colorize (0.7.7) 32 | erubis (2.7.0) 33 | i18n (0.7.0) 34 | json (1.8.3) 35 | loofah (2.0.3) 36 | nokogiri (>= 1.5.9) 37 | mini_portile2 (2.0.0) 38 | minitest (5.8.4) 39 | nokogiri (1.6.7.2) 40 | mini_portile2 (~> 2.0.0.rc2) 41 | rack (1.6.4) 42 | rack-test (0.6.3) 43 | rack (>= 1.0) 44 | rails-deprecated_sanitizer (1.0.3) 45 | activesupport (>= 4.2.0.alpha) 46 | rails-dom-testing (1.0.7) 47 | activesupport (>= 4.2.0.beta, < 5.0) 48 | nokogiri (~> 1.6.0) 49 | rails-deprecated_sanitizer (>= 1.0.1) 50 | rails-html-sanitizer (1.0.3) 51 | loofah (~> 2.0) 52 | railties (4.2.6) 53 | actionpack (= 4.2.6) 54 | activesupport (= 4.2.6) 55 | rake (>= 0.8.7) 56 | thor (>= 0.18.1, < 2.0) 57 | rake (10.1.1) 58 | thor (0.19.1) 59 | thread_safe (0.3.5) 60 | tzinfo (1.2.2) 61 | thread_safe (~> 0.1) 62 | 63 | PLATFORMS 64 | ruby 65 | 66 | DEPENDENCIES 67 | bundler (~> 1.5) 68 | protractor-rails! 69 | rake 70 | 71 | BUNDLED WITH 72 | 1.10.6 73 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Tyrone 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Protractor::Rails 2 | 3 | This gem helps you seamlessly setup, run and maintain a angularjs e2e test suite using protractor in a rails application. 4 | 5 | ## Dependencies 6 | 7 | Make sure you have Nodejs installed and that you do not need to use `sudo` to install npm packages 8 | 9 | ## Installation 10 | 11 | Add this line to your application's Gemfile: 12 | 13 | gem 'protractor-rails' 14 | 15 | And then execute the following command to load dependencies on your machine: 16 | 17 | $ rake protractor:install 18 | 19 | 20 | You can test that everything has been set up correctly using the command below. 21 | This command will run protractor's example configuration and test file against the 22 | http://angular.org website. If everything starts up ok and runs till the end giving you 23 | a summary of test results then you are 'good to go'! 24 | 25 | $ rake protractor:example 26 | 27 | ## Usage 28 | 29 | ### Initialization 30 | 31 | You can initialize your app with protractor rails by running 32 | 33 | $ rake protractor:init 34 | 35 | ### Dummy test in local environment 36 | 37 | This will generate and template configuration and a dummy example test. Once you have run this you can test that 38 | everything has been set up correctly in your local environment by running the following command: 39 | 40 | $ rake protractor:spec 41 | 42 | This will run a local rails test server, the webdriver selenium server and run protractor against the example_spec.js 43 | If everything starts up and runs cleanly you should see the test summary of 1 test 1 pass and 0 failures. 44 | 45 | ### Running your tests 46 | 47 | When the `rake protractor:init` script is run it will create a file `spec/javascripts/protractor.conf.js`. This file is where you 48 | can configure the tests that should be run. [See Protractor Documentation for more details] (https://github.com/angular/protractor/blob/master/docs/getting-started.md). 49 | 50 | In this file you can provide patterns for matching your protractor specs. **NB: It is recommended that you use a subdirectory such as spec/javascripts/protractor_specs for easy matching and organization** 51 | 52 | **Example** 53 | 54 | If I have a directory set up for protractor specs in `spec/javascripts/protractor_specs/`, my configuration file would look something like the below 55 | 56 | ``` 57 | // An example configuration file. 58 | exports.config = { 59 | // The address of a running selenium server. 60 | seleniumAddress: 'http://localhost:4444/wd/hub', 61 | 62 | // Capabilities to be passed to the webdriver instance. 63 | capabilities: { 64 | 'browserName': 'chrome' 65 | }, 66 | 67 | // If you would like to test against multiple browsers, use the multiCapabilities 68 | // configuration option instead. 69 | multiCapabilities: [{ 70 | 'browserName': 'firefox' 71 | }, { 72 | 'browserName': 'chrome' 73 | }], 74 | 75 | // Spec patterns are relative to the current working directly when protractor is called 76 | specs: ['protractor_specs/**/*.js '], 77 | 78 | baseUrl: 'http://localhost:4000', 79 | 80 | // Options to be passed to Jasmine-node. 81 | jasmineNodeOpts: { 82 | showColors: true, 83 | defaultTimeoutInterval: 30000 84 | }, 85 | 86 | // Specify a version of Jasmine you wish to use. Default version is v1.3 87 | // Jasmine v2 has many more built-in functions to help with testing, 88 | // such as beforeAll and afterAll. 89 | // Jasmine v2 documentation can be found here: 90 | // http://jasmine.github.io/2.0/introduction.html 91 | framework: 'jasmine2' 92 | }; 93 | 94 | ``` 95 | 96 | Once you have setup your tests as above, running `rake protractor:spec` will pick up new tests and run them for you. 97 | 98 | You can specify the binding for the rails server as an environment variable: `rake protractor:spec rails_binding=hostname_or_ip`. 99 | 100 | ### Suites 101 | 102 | If you want to organise your tests then you can use suites. Replace the specs: line in the above with the following 103 | 104 | suites: { 105 | login: 'protractor_specs/login/*.js', 106 | user: 'protractor_specs/user/*.js' 107 | }, 108 | 109 | You can run specific test suites by passing in options to the rake task as per the below example. 110 | 111 | $ rake protractor:spec -- --suite suite-name 112 | 113 | **NOTE You must have the -- first otherwise rake will think the arguments are for rake instead of the task** 114 | 115 | ### Run in debug mode 116 | 117 | $ DEBUG=true rake protractor:spec 118 | 119 | 120 | ### Run a specific spec file 121 | 122 | $ rake protractor:spec -- --specs spec-filename 123 | 124 | ### Setup and teardown 125 | 126 | There is a task to reset your database to remove items you have created during your tests. This will also seed your database with any fixtures you might have prepared 127 | 128 | $ rake protractor:cleanup 129 | 130 | This will reset your test database and load in seeds in db/seeds.rb into your test database only. 131 | 132 | There is also a convenience function for running cleanup after you have run your tests ready for the next test run. 133 | 134 | $ rake protractor:spec_and_cleanup 135 | 136 | ### Task Options 137 | 138 | #### rake protractor:spec 139 | 140 | You can control verbosity of logging with the following ENV flags: 141 | 142 | * `rake protractor:spec nolog=y # all quiet` 143 | * `rake protractor:spec nolog_selenium=y # no selenium (just drivers)` 144 | * `rake protractor:spec nolog_rails=y # no rails` 145 | 146 | ## Notes about integration tests 147 | 148 | Integration tests are **MUCH** faster than testing things yourself but they are MUCH slower than running unit tests or 149 | rspec tests. Keep your integration tests to a minimum and test as much as possible with your normal rails test suite. 150 | 151 | ## Contributing 152 | 153 | **Contributions, questions, comments, threats or suggestions are welcome.** 154 | 155 | 1. Fork it (http://github.com/my-github-username/protractor-rails/fork) 156 | 2. Create your feature branch (`git checkout -b my-new-feature`) 157 | 3. Commit your changes (`git commit -am 'Add some feature'`) 158 | 4. Push to the branch (`git push origin my-new-feature`) 159 | 5. Create new Pull Request 160 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | 3 | load 'lib/tasks/install.rake' 4 | load 'lib/tasks/protractor.rake' 5 | -------------------------------------------------------------------------------- /lib/protractor-rails.rb: -------------------------------------------------------------------------------- 1 | require 'protractor/rails' 2 | -------------------------------------------------------------------------------- /lib/protractor/rails.rb: -------------------------------------------------------------------------------- 1 | require 'protractor/rails/version' 2 | require 'protractor/rails/railtie' 3 | require 'protractor/rails/configuration' 4 | 5 | module Protractor 6 | module Rails 7 | class PlatformHelper 8 | def self.mac? 9 | RbConfig::CONFIG['target_os'] =~ /darwin/i 10 | end 11 | 12 | def self.linux? 13 | RbConfig::CONFIG['target_os'] =~ /linux/i 14 | end 15 | 16 | def self.windows? 17 | RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/protractor/rails/configuration.rb: -------------------------------------------------------------------------------- 1 | 2 | require 'yaml' 3 | 4 | module Protractor 5 | class << self 6 | attr_accessor :configuration 7 | end 8 | 9 | def self.load file_name 10 | file_name = file_name 11 | 12 | if File.exists? file_name 13 | file = File.read file_name 14 | yaml = ERB.new( file ).result 15 | data = YAML.load yaml 16 | end 17 | 18 | return Configuration.new data 19 | end 20 | 21 | def self.configuration 22 | @configuration ||= load 'config/protractor.yml' 23 | end 24 | 25 | class Configuration 26 | attr_accessor :config_path, 27 | :config_file, 28 | :startup_timeout, 29 | :spec_path, 30 | :server, 31 | :port 32 | 33 | def initialize ( data=nil ) 34 | @data = data 35 | @config_path = get( :config_path ) || 'spec/javascripts' 36 | @config_file = get( :config_file ) || 'protractor.conf.js' 37 | @spec_path = get( :spec_path ) || 'spec/javascripts' 38 | @startup_timeout = get( :startup_timeout ) || 8 39 | @server = get( :server ) || 'webrick' 40 | @port = get( :port ) || 4000 41 | end 42 | 43 | def get *keys 44 | keys.inject( @data ) { |result, key| result.try :[], key.to_s } 45 | end 46 | end 47 | end 48 | -------------------------------------------------------------------------------- /lib/protractor/rails/railtie.rb: -------------------------------------------------------------------------------- 1 | module Protractor 2 | module Rails 3 | class Railtie < ::Rails::Railtie 4 | rake_tasks do 5 | load File.expand_path('../../../tasks/install.rake', __FILE__) 6 | load File.expand_path('../../../tasks/protractor.rake', __FILE__) 7 | end 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/protractor/rails/version.rb: -------------------------------------------------------------------------------- 1 | module Protractor 2 | module Rails 3 | VERSION = "0.0.19" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/tasks/install.rake: -------------------------------------------------------------------------------- 1 | require 'colorize' 2 | 3 | namespace :protractor do 4 | desc "Install dependencies for running protractor on your machine" 5 | task :install => [:check_nodejs_installed, :install_protractor, :install_webdriver] do 6 | end 7 | 8 | task :check_nodejs_installed do 9 | if linux? || mac? 10 | puts "Check that Nodejs is installed" 11 | result = `node -v` 12 | if result 13 | puts "Nodejs #{result[0..-2]} found [OK]".yellow 14 | else 15 | raise "Nodejs is not installed. Please installed Nodejs and run this script again".red 16 | end 17 | elsif windows? 18 | puts "Thank you for choosing to use protractor-rails. Unfortunately Windows is not yet supported. Feel free to contribute.".red 19 | end 20 | end 21 | 22 | task :install_protractor do 23 | puts "Installing Protractor using npm installer".green 24 | system "npm install -g protractor" 25 | end 26 | 27 | task :install_webdriver do 28 | puts "Installing webdriver using protractor install manager...".green 29 | system "webdriver-manager update --standalone" 30 | end 31 | 32 | task :coffee_script_support do 33 | puts "Installing RequireJS on your machine.....".green 34 | system "npm install -g requirejs" 35 | puts "Installing coffee-script with npm".green 36 | system "npm install -g coffee-script" 37 | puts "You have dependencies installed and ready to use. Read the coffee-script section at https://github.com/tyronewilson/protractor-rails for details on configuration" 38 | end 39 | 40 | desc "Initialize protractor rails." 41 | task :init do 42 | conf_path = Protractor.configuration.config_path 43 | conf_file = File.join(conf_path, Protractor.configuration.config_file) 44 | spec_path = Protractor.configuration.spec_path 45 | 46 | if !File.directory?(spec_path) 47 | puts "You have chosen to put your protractor-rails specs file in #{spec_path} but the directory doesn't exist. Please create it and then rerun this command".red 48 | next 49 | end 50 | if File.exist? conf_file 51 | puts "You already have a configuration file. If you would like to start over, remove #{Protractor.configuration.config_path} and run rake protractor:init".red 52 | next 53 | else 54 | puts "Creating template configuration file in #{conf_path}".green 55 | template_path = File.expand_path("../../../spec/javascripts/templates", __FILE__) 56 | template_conf = File.join(template_path, 'protractor.conf.js') 57 | template_spec = File.join(template_path, 'example_spec.js') 58 | system "cp #{template_conf} #{conf_file}" 59 | puts "You will need to edit the #{conf_file} file to suite your requirements." 60 | system "cp #{template_spec} #{File.join(Protractor.configuration.spec_path, 'example_spec.js')}" 61 | puts "created example_spec.js in #{spec_path}. You can test it out by running rake protractor:example" 62 | end 63 | end 64 | end 65 | 66 | def mac? 67 | RbConfig::CONFIG['target_os'] =~ /darwin/i 68 | end 69 | 70 | def linux? 71 | RbConfig::CONFIG['target_os'] =~ /linux/i 72 | end 73 | 74 | def windows? 75 | RbConfig::CONFIG['target_os'] =~ /mswin|mingw/i 76 | end 77 | -------------------------------------------------------------------------------- /lib/tasks/protractor.rake: -------------------------------------------------------------------------------- 1 | require 'optparse' 2 | 3 | namespace :protractor do |args| 4 | desc "starts protractor example test to see if you have your system set up correctly" 5 | task :example do 6 | begin 7 | webdriver_pid = fork do 8 | Rake::Task["protractor:webdriver"].invoke 9 | end 10 | write_log "Waiting for test server and webdriver server to start" 11 | sleep 5 12 | file = File.expand_path('../../../spec/protractor_example.conf.js', __FILE__) 13 | system "protractor #{file}" 14 | ensure 15 | Rake::Task["protractor:kill_webdriver"].invoke 16 | Rake::Task["protractor:kill_selenium_processes"].invoke 17 | end 18 | end 19 | 20 | def write_log(message) 21 | return if ENV['nolog'].present? 22 | puts message 23 | end 24 | 25 | desc "Run specs from config file" 26 | task :spec do 27 | begin 28 | options = '' 29 | OptionParser.new(args) do |opts| 30 | # Test specific spec files instead of a whole suite. 31 | specsKey = '--specs' 32 | opts.on("#{specsKey} {filename}", 'Test spec files', String) do |filename| 33 | options = options + "#{specsKey} #{filename}" 34 | end 35 | # Suite setup 36 | suiteKey = '--suite' 37 | opts.on("#{suiteKey} {suite}", 'Test suite name', String) do |suite| 38 | options = options + "#{suiteKey} #{suite}" 39 | end 40 | 41 | opts.on("--debug", String) do 42 | options = options + "debug" 43 | end 44 | end.parse! 45 | 46 | options += "--specs #{ENV['SPECS']}" if ENV['SPECS'].present? 47 | options += "--suite #{ENV['SUITE']}" if ENV['SUITE'].present? 48 | options += "debug" if ENV['DEBUG'].present? 49 | 50 | webdriver_pid = fork do 51 | [$stdout,$stderr].each { |fh| fh.reopen File.open("/dev/null","w") } if ENV['nolog'].present? || ENV['nolog_selenium'].present? 52 | Rake::Task['protractor:webdriver'].invoke 53 | end 54 | rails_server_pid = fork do 55 | [$stdout,$stderr].each { |fh| fh.reopen File.open("/dev/null","w") } if ENV['nolog'].present? || ENV['nolog_rails'].present? 56 | Rake::Task['protractor:rails'].invoke 57 | end 58 | write_log "webdriver PID: #{webdriver_pid}" 59 | write_log "Rails Server PID: #{rails_server_pid}".yellow.bold 60 | write_log "Waiting for servers to finish starting up...." 61 | sleep Protractor.configuration.startup_timeout 62 | cmd = "protractor #{options} #{Protractor.configuration.config_path}/#{Protractor.configuration.config_file}" 63 | write_log cmd 64 | success = system cmd 65 | write_log "Protractor has failed to run test with options '#{options}'".red.bold unless success 66 | Process.kill 'TERM', webdriver_pid 67 | Process.kill 'TERM', rails_server_pid 68 | Process.wait webdriver_pid 69 | Process.wait rails_server_pid 70 | write_log "Waiting to shut down cleanly.........".yellow.bold 71 | sleep 5 72 | rescue Exception => e 73 | puts e 74 | ensure 75 | Rake::Task["protractor:kill"].invoke 76 | exit 1 unless success 77 | end 78 | end 79 | 80 | task :spec_and_cleanup => [:spec, :cleanup] 81 | 82 | task :kill do 83 | write_log "killing running protractor processes".green.bold 84 | Rake::Task["protractor:kill_rails"].invoke 85 | Rake::Task["protractor:kill_webdriver"].invoke 86 | Rake::Task["protractor:kill_selenium_processes"].invoke 87 | end 88 | 89 | task :kill_selenium_processes do 90 | write_log "kill left over selenium processes...".yellow 91 | system "ps aux | grep -ie 'protractor\/selenium' | grep -v grep | awk '{print $2}' | xargs kill -9" 92 | end 93 | 94 | task :kill_webdriver do 95 | write_log "kill webdriver server...".yellow 96 | system "ps aux | grep -ie '\-Dwebdriver' | grep -v grep | awk '{print $2}' | xargs kill -9" 97 | end 98 | 99 | task :kill_rails do 100 | write_log "kill protractor rails tests server...".yellow 101 | system "kill `cat tmp/pids/protractor_test_server.pid`" 102 | end 103 | 104 | task :rails do 105 | env = ENV['PROTRACTOR_SERVER_ENV'] ||= 'test' 106 | server = Protractor.configuration.server 107 | write_log "Starting Rails server #{server} on port #{Protractor.configuration.port} environement #{env} pid file in tmp/pids/protractor_test_server.pid".green 108 | rails_command = "rails s #{server} -e #{env} -P tmp/pids/protractor_test_server.pid --port=#{Protractor.configuration.port}" 109 | if ENV['rails_binding'] != nil 110 | rails_command << " --binding #{ ENV['rails_binding'] }" 111 | end 112 | system rails_command 113 | end 114 | 115 | task :webdriver do 116 | write_log "Starting selenium server".green 117 | system "webdriver-manager start --standalone" 118 | end 119 | 120 | task :cleanup do 121 | write_log "rake db:test:prepare to cleanup for the next test session".green 122 | system 'rake db:test:prepare --trace' 123 | write_log "Seeding the test database....".green 124 | system "rake db:test:seed --trace" 125 | end 126 | end 127 | 128 | namespace :db do 129 | namespace :test do 130 | desc "seed only the test database (Task provided by protractor-rails)" 131 | task :seed do 132 | system "rake db:seed RAILS_ENV=test" 133 | end 134 | end 135 | end 136 | -------------------------------------------------------------------------------- /protractor-rails.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | require File.expand_path('../lib/protractor/rails/version', __FILE__) 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "protractor-rails" 7 | spec.version = Protractor::Rails::VERSION 8 | spec.authors = ["Tyrone Wilson"] 9 | spec.email = ["tdubs241083@gmail.com"] 10 | spec.summary = %q{Seemlessly run protractor for angularjs in your rails app.} 11 | spec.description = %q{Protractor rails makes it a bit easier to integrate and run angularjs' protractor e2e test framework directly in your rails app.} 12 | spec.homepage = "http://github.com/tyronewilson/protractor-rails" 13 | spec.license = "MIT" 14 | 15 | spec.files = `git ls-files -z`.split("\x0") 16 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 17 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 18 | spec.require_paths = ["lib"] 19 | 20 | spec.add_development_dependency "bundler", "~> 1.5" 21 | spec.add_development_dependency "rake" 22 | spec.add_runtime_dependency 'colorize' 23 | spec.add_runtime_dependency 'railties' 24 | end 25 | -------------------------------------------------------------------------------- /spec/example_spec.js: -------------------------------------------------------------------------------- 1 | describe('angularjs homepage', function() { 2 | it('should greet the named user', function() { 3 | browser.get('http://www.angularjs.org'); 4 | 5 | element(by.model('yourName')).sendKeys('Julie'); 6 | 7 | var greeting = element(by.binding('yourName')); 8 | 9 | expect(greeting.getText()).toEqual('Hello Julie!'); 10 | }); 11 | 12 | describe('todo list', function() { 13 | var todoList; 14 | 15 | beforeEach(function() { 16 | browser.get('http://www.angularjs.org'); 17 | 18 | todoList = element.all(by.repeater('todo in todos')); 19 | }); 20 | 21 | it('should list todos', function() { 22 | expect(todoList.count()).toEqual(2); 23 | expect(todoList.get(1).getText()).toEqual('build an angular app'); 24 | }); 25 | 26 | it('should add a todo', function() { 27 | var addTodo = element(by.model('todoText')); 28 | var addButton = element(by.css('[value="add"]')); 29 | 30 | addTodo.sendKeys('write a protractor test'); 31 | addButton.click(); 32 | 33 | expect(todoList.count()).toEqual(3); 34 | expect(todoList.get(2).getText()).toEqual('write a protractor test'); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /spec/javascripts/templates/example_spec.js: -------------------------------------------------------------------------------- 1 | describe('angularjs homepage', function() { 2 | it('should greet the named user', function() { 3 | browser.get('http://www.angularjs.org'); 4 | 5 | element(by.model('yourName')).sendKeys('Julie'); 6 | 7 | var greeting = element(by.binding('yourName')); 8 | 9 | expect(greeting.getText()).toEqual('Hello Julie!'); 10 | }); 11 | 12 | describe('todo list', function() { 13 | var todoList; 14 | 15 | beforeEach(function() { 16 | browser.get('http://www.angularjs.org'); 17 | 18 | todoList = element.all(by.repeater('todo in todos')); 19 | }); 20 | 21 | it('should list todos', function() { 22 | expect(todoList.count()).toEqual(2); 23 | expect(todoList.get(1).getText()).toEqual('build an angular app'); 24 | }); 25 | 26 | it('should add a todo', function() { 27 | var addTodo = element(by.model('todoText')); 28 | var addButton = element(by.css('[value="add"]')); 29 | 30 | addTodo.sendKeys('write a protractor test'); 31 | addButton.click(); 32 | 33 | expect(todoList.count()).toEqual(3); 34 | expect(todoList.get(2).getText()).toEqual('write a protractor test'); 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /spec/javascripts/templates/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // An example configuration file. 2 | require('coffee-script'); 3 | 4 | exports.config = { 5 | // The address of a running selenium server. 6 | seleniumAddress: 'http://localhost:4444/wd/hub', 7 | 8 | // Capabilities to be passed to the webdriver instance. 9 | capabilities: { 10 | 'browserName': 'chrome' 11 | }, 12 | 13 | // Spec patterns are relative to the current working directly when 14 | // protractor is called. 15 | specs: ['example_spec.js ', 'protractor_specs/**/*.js', 'protractor_specs/**/*.coffee'], 16 | 17 | baseUrl: 'http://localhost:4000', 18 | 19 | // Options to be passed to Jasmine-node. 20 | jasmineNodeOpts: { 21 | showColors: true, 22 | defaultTimeoutInterval: 30000 23 | }, 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /spec/protractor_example.conf.js: -------------------------------------------------------------------------------- 1 | // An example configuration file. 2 | exports.config = { 3 | // The address of a running selenium server. 4 | seleniumAddress: 'http://localhost:4444/wd/hub', 5 | 6 | // Capabilities to be passed to the webdriver instance. 7 | capabilities: { 8 | 'browserName': 'chrome' 9 | }, 10 | 11 | // Spec patterns are relative to the current working directly when 12 | // protractor is called. 13 | specs: ['example_spec.js'], 14 | 15 | // Options to be passed to Jasmine-node. 16 | jasmineNodeOpts: { 17 | showColors: true, 18 | defaultTimeoutInterval: 30000 19 | } 20 | }; 21 | --------------------------------------------------------------------------------