Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updaing SauceConnect to use a more robust example #2

Merged
merged 1 commit into from
Apr 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.solano*
*.swp
solano*.gem
2 changes: 1 addition & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ and retrieve your account status all from within your terminal.

== Getting Started

See http://docs.solanolabs.com for more information.
See https://docs.solanolabs.com for more information.

For contributed code, see the extras directory.

Expand Down
34 changes: 0 additions & 34 deletions Rakefile

This file was deleted.

6 changes: 3 additions & 3 deletions appspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ files:
- source: www/
destination: /var/www/html/
hooks:
BeforeInstall:
- location: scripts/say_hello
ApplicationStart:
- location: scripts/say_hello.sh
timeout: 300
runas: root
ApplicationStop:
- location: scripts/say_goodbye
- location: scripts/say_goodbye.sh
timeout: 300
runas: root
13 changes: 0 additions & 13 deletions config/solano.yml

This file was deleted.

8 changes: 8 additions & 0 deletions functional/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source 'https://rubygems.org'

gem 'rspec'
gem 'selenium-webdriver'
gem 'require_all'
gem 'parallel_split_test'
gem 'sauce_whisk'
gem 'rake'
61 changes: 61 additions & 0 deletions functional/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
## Ruby-RSpec-Selenium

This code is provided on an "AS-IS” basis without warranty of any kind, either express or implied, including without limitation any implied warranties of condition, uninterrupted use, merchantability, fitness for a particular purpose, or non-infringement. Your tests and testing environments may require you to modify this framework. Issues regarding this framework should be submitted through GitHub. For questions regarding Sauce Labs integration, please see the Sauce Labs documentation at https://wiki.saucelabs.com/. This framework is not maintained by Sauce Labs Support.

### Environment Setup

1. Global Dependencies
* [Install Ruby](https://www.ruby-lang.org/en/documentation/installation/)
* Or Install Ruby with [Homebrew](http://brew.sh/)
```
$ brew install ruby
```
* Install [Rake](http://docs.seattlerb.org/rake/)
```
$ gem install rake
```
* Install bundler (Sudo may be necessary)
```
$ gem install bundler
```

2. Sauce Credentials
* In the terminal export your Sauce Labs Credentials as environmental variables:
```
$ export SAUCE_USERNAME=<your Sauce Labs username>
$ export SAUCE_ACCESS_KEY=<your Sauce Labs access key>
```
3. Project Dependencies
* Install packages (Use sudo if necessary)
```
$ bundle install
```
* Set Build ID (Optional)
```
$ export BUILD_TAG=sauce_automated_build_name
```
### Running Tests

Tests in Parallel:
```
$ rake test_sauce
```

[Sauce Labs Dashboard](https://saucelabs.com/beta/dashboard/)

### Advice/Troubleshooting

1. There may be additional latency when using a remote webdriver to run tests on Sauce Labs. Timeouts or Waits may need to be increased.
* [Selenium tips regarding explicit waits](https://wiki.saucelabs.com/display/DOCS/Best+Practice%3A+Use+Explicit+Waits)

### Resources
##### [Sauce Labs Documentation](https://wiki.saucelabs.com/)

##### [SeleniumHQ Documentation](http://www.seleniumhq.org/docs/)

##### [RSpec Documentation](http://rspec.info/documentation/)

##### [Ruby Documentation](http://ruby-doc.org/)

##### [Stack Overflow](http://stackoverflow.com/)
* A great resource to search for issues not explicitly covered by documentation.
30 changes: 30 additions & 0 deletions functional/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def run_tests(platform, browser, version, junit_dir)
puts "platform=\"#{platform}\" browserName=\"#{browser}\" version=\"#{version}\" JUNIT_DIR=\"#{junit_dir}\" parallel_split_test spec"
#system("platform=\"#{platform}\" browserName=\"#{browser}\" version=\"#{version}\" JUNIT_DIR=\"#{junit_dir}\" parallel_split_test spec")
end

task :windows_8_1_chrome_43 do
run_tests('Windows 8.1', 'chrome', '43', 'junit_reports/windows_8_1_chrome_43')
end

task :windows_7_firefox_40 do
run_tests('Windows 7', 'firefox', '40', 'junit_reports/windows_7_firefox40')
end

task :os_x_10_9_chrome_45 do
run_tests('OS X 10.9', 'chrome', '45', 'junit_reports/os_x_10_9_chrome_45')
end

task :windows_xp_firefox_39 do
run_tests('Windows XP', 'firefox', '39', 'junit_reports/windows_xp_firefox_39')
end

multitask :test_sauce => [
:windows_8_1_chrome_43,
:windows_7_firefox_40,
:os_x_10_9_chrome_45,
:windows_xp_firefox_39
] do
puts 'Running automation'
end

22 changes: 22 additions & 0 deletions functional/spec/test1_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require_relative "../util/spec_helper"

describe "Webpage sample for Solano + Sauce" do
it "should have meme" do
@browser.get "http://localhost:8000"
meme = @browser.find_element(:class => 'sl-meme')
expect(meme.displayed?).to be true
end

it "should see caption" do
@browser.get "http://localhost:8000"
caption = @browser.find_element(:class => 'caption')
expect(caption.displayed?).to be true
expect(caption.text).to eq("THAT FEELING WHEN YOU'RE DEPLOYING CONTINUOUSLY")
end

it "should have a link in the caption" do
@browser.get "http://localhost:8000"
link = @browser.find_element(:class => 'caption').attribute('href')
expect(link).not_to include("_placeholder_")
end
end
51 changes: 51 additions & 0 deletions functional/util/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require "rspec/expectations"
require "selenium-webdriver"
require "rspec"
require "sauce_whisk"

def setup_sauce_env()
if ENV['SAUCE_USERNAME'] == nil or ENV['SAUCE_ACCESS_KEY'] == nil
abort("No Sauce Labs credentials are set!")
end
# check if selenium relay port is set if not set it to direct
if ENV['SELENIUM_PORT'] == nil or ENV['SELENIUM_HOST'] == nil
ENV['SELENIUM_HOST'] = 'ondemand.saucelabs.com'
ENV['SELENIUM_PORT'] = '80'
end
end

RSpec.configure do | config |
config.before(:all) do
setup_sauce_env()
end

config.before(:each) do | test |
capabilities_config = {
:version => "#{ENV['version']}",
:browserName => "#{ENV['browserName']}",
:platform => "#{ENV['platform']}",
:name => test.full_description
}
#If there's a build tag set it.
if ENV['BUILD_TAG'] != nil
capabilities_config['build'] = ENV['BUILD_TAG']
end
if ENV['TUNNEL_IDENTIFIER'] != nil
capabilities_config['tunnel-identifier'] = ENV['TUNNEL_IDENTIFIER']
end
url = "http://#{ENV['SAUCE_USERNAME']}:#{ENV['SAUCE_ACCESS_KEY']}@#{ENV['SELENIUM_HOST']}:#{ENV['SELENIUM_PORT']}/wd/hub".strip
@browser = Selenium::WebDriver.for(:remote, :url => url, :desired_capabilities => capabilities_config)
end

config.after(:each) do | test |
sessionid = @browser.session_id
puts("SauceOnDemandSessionID=#{sessionid} job-name=#{test.full_description}")
@browser.quit
if test.exception
SauceWhisk::Jobs.fail_job sessionid
else
SauceWhisk::Jobs.pass_job sessionid
end
end

end
80 changes: 80 additions & 0 deletions karma.conf-solano.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
var fs = require('fs');

module.exports = function(config) {

// Browsers to run on Sauce Labs
var customLaunchers = {
'SL_Chrome': {
base: 'SauceLabs',
browserName: 'chrome'
},
'SL_InternetExplorer': {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '10'
},
'SL_InternetExplorer': {
base: 'SauceLabs',
browserName: 'internet explorer',
version: '11'
},
'SL_FireFox': {
base: 'SauceLabs',
browserName: 'firefox',
},
};

config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],

// list of files / patterns to load in the browser
files: [
'src/*.js',
'test/*.js',
{
pattern: 'www/images/*',
watched: false,
included: false,
served: true
},
{
pattern: 'www/solano.html',
watched: true,
included: false,
served: true
}
],

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['dots', 'saucelabs'],

// web server port
port: 9876,

colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

sauceLabs: {
testName: 'CodePipeline, SauceLabs, and Solano CI using Karma',
startConnect: false
},
captureTimeout: 120000,
customLaunchers: customLaunchers,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: Object.keys(customLaunchers),
singleRun: true
});
};
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "karma-sauce-example",
"version": "0.0.0",
"description": "An example of using the Karma test runner with Sauce Labs' browser cloud to run JavaScript unit tests",
"main": "karma.conf-solano.js",
"scripts": {
"test": "karma start karma.conf-solano.js"
},
"author": "Sauce Labs",
"license": "Apache V2",
"devDependencies": {
"karma": "^0.12.0",
"karma-sauce-launcher": "^0.2.3",
"karma-jasmine": "^0.2.2",
"karma-chrome-launcher": "^0.1.2",
"karma-firefox-launcher": "^0.1.3",
"karma-safari-launcher": "^0.1.1"
}
}
4 changes: 4 additions & 0 deletions sauce-sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"username": "yourSauceUsername",
"accessKey": "yourSauceAccessKey"
}
26 changes: 26 additions & 0 deletions scripts/build_and_upload_gem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /bin/bash

# Copyright (c) 2016 Solano Labs Inc. All Rights Reserved

set -x

if [ $TDDIUM_BUILD_STATUS != 'passed' ];
then
echo "Build Failed, not uploading";
exit 0;
fi

# Build the gam
gem build solano.gemspec || { echo "Gem build failed"; exit 1; }

# Upload the gem and capture the link
location=`./scripts/upload_to_s3.sh ./solano*.gem` || { echo "Upload failed..."; exit 1; }
location=$(echo $location | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/&/\\\&/g')

# Change the href of the gem download link
sed -i.bak "s/_placeholder_/$location/g" www/solano.html
sed -i.bak "s/_placeholder_/$location/g" www/index.html

# Swap the solano.yml for the next step
mv solano.yml solano.yml.pt1
mv solano.yml.pt2 solano.yml
1 change: 0 additions & 1 deletion scripts/say_goodbye

This file was deleted.

8 changes: 8 additions & 0 deletions scripts/say_goodbye.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash

# Copyright (c) 2016 Solano Labs Inc. All Rights Reserved

echo 'goodbye'

# Stop apache
sudo /etc/init.d/httpd stop
Loading