lapis_lazuli 0.9.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lapis_lazuli.gemspec +12 -0
- data/lib/lapis_lazuli.rb +1 -1
- data/lib/lapis_lazuli/api.rb +1 -1
- data/lib/lapis_lazuli/argparse.rb +1 -1
- data/lib/lapis_lazuli/browser.rb +1 -1
- data/lib/lapis_lazuli/browser/error.rb +1 -1
- data/lib/lapis_lazuli/browser/find.rb +1 -1
- data/lib/lapis_lazuli/browser/interaction.rb +1 -1
- data/lib/lapis_lazuli/browser/remote.rb +1 -1
- data/lib/lapis_lazuli/browser/screenshots.rb +1 -1
- data/lib/lapis_lazuli/browser/wait.rb +23 -12
- data/lib/lapis_lazuli/cli.rb +1 -1
- data/lib/lapis_lazuli/cucumber.rb +1 -1
- data/lib/lapis_lazuli/generators/cucumber.rb +1 -1
- data/lib/lapis_lazuli/generators/cucumber/template/Gemfile +3 -7
- data/lib/lapis_lazuli/generators/cucumber/template/README.md +3 -1
- data/lib/lapis_lazuli/generators/cucumber/template/config/config.yml +32 -2
- data/lib/lapis_lazuli/generators/cucumber/template/config/cucumber.yml +0 -9
- data/lib/lapis_lazuli/generators/cucumber/template/features/account.feature +26 -0
- data/lib/lapis_lazuli/generators/cucumber/template/features/example.feature +23 -10
- data/lib/lapis_lazuli/generators/cucumber/template/features/step_definitions/interaction_steps.rb +135 -7
- data/lib/lapis_lazuli/generators/cucumber/template/features/step_definitions/precondition_steps.rb +52 -3
- data/lib/lapis_lazuli/generators/cucumber/template/features/step_definitions/validation_steps.rb +44 -0
- data/lib/lapis_lazuli/generators/cucumber/template/features/support/env.rb +29 -1
- data/lib/lapis_lazuli/generators/cucumber/template/features/support/functions.rb +68 -0
- data/lib/lapis_lazuli/generic/xpath.rb +1 -1
- data/lib/lapis_lazuli/options.rb +1 -1
- data/lib/lapis_lazuli/placeholders.rb +1 -1
- data/lib/lapis_lazuli/proxy.rb +1 -1
- data/lib/lapis_lazuli/runtime.rb +1 -1
- data/lib/lapis_lazuli/scenario.rb +1 -1
- data/lib/lapis_lazuli/storage.rb +1 -1
- data/lib/lapis_lazuli/version.rb +2 -2
- data/lib/lapis_lazuli/versions.rb +1 -1
- data/lib/lapis_lazuli/world/annotate.rb +1 -1
- data/lib/lapis_lazuli/world/api.rb +1 -1
- data/lib/lapis_lazuli/world/browser.rb +1 -1
- data/lib/lapis_lazuli/world/config.rb +1 -1
- data/lib/lapis_lazuli/world/error.rb +1 -1
- data/lib/lapis_lazuli/world/hooks.rb +1 -1
- data/lib/lapis_lazuli/world/logging.rb +1 -1
- data/lib/lapis_lazuli/world/proxy.rb +1 -1
- data/lib/lapis_lazuli/world/variable.rb +1 -1
- data/test/Gemfile +10 -33
- data/test/features/step_definitions/interaction_steps.rb +25 -3
- data/test/features/step_definitions/validation_steps.rb +265 -230
- data/test/features/timing.feature +40 -4
- data/test/server/www/timing.html +15 -0
- metadata +90 -4
data/lib/lapis_lazuli/generators/cucumber/template/features/step_definitions/precondition_steps.rb
CHANGED
@@ -6,9 +6,58 @@
|
|
6
6
|
# precondition_steps.rb is used to define steps that contain multiple steps to come to a certain start of a scenrario.
|
7
7
|
# For example: "Given the user is logged in" will contain all steps done before logging in
|
8
8
|
|
9
|
-
Given(/^the user has searched for "(.*?)" on (.*?)
|
9
|
+
Given(/^the user has searched for "(.*?)" on "(.*?)"$/) do |query, page|
|
10
10
|
# Run step to go to page
|
11
|
-
step "the user navigates to #{
|
11
|
+
step "the user navigates to \"#{page}\""
|
12
12
|
# Run step to search
|
13
13
|
step "the user searches for \"#{query}\""
|
14
|
-
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
Given(/^the user is logged out$/) do
|
18
|
+
# In this step we want to make sure that the user is not logged in.
|
19
|
+
# If the user is not logged in, then this step does nothing, else it will trigger the logout step.
|
20
|
+
|
21
|
+
# Make this step independent by going to the homepage
|
22
|
+
step 'the user navigates to the "training-page" page'
|
23
|
+
|
24
|
+
# Check if the user is already logged in
|
25
|
+
loggedin = browser.find(
|
26
|
+
:like => [:img, :id, 'user-gravatar'],
|
27
|
+
:throw => false # This will prevent that the lookup will thow an error if it fails
|
28
|
+
)
|
29
|
+
if !loggedin.nil?
|
30
|
+
# Then try clicking the logout button
|
31
|
+
begin
|
32
|
+
step 'the user clicks on the logout button'
|
33
|
+
rescue Exception => e
|
34
|
+
# Ignoring the error, since it probably means we're already logged out.
|
35
|
+
log.debug "Logout failed, so I should already be logged out: #{e}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# And confirm we've successfully logged out
|
40
|
+
step 'the page should display as logged out state'
|
41
|
+
end
|
42
|
+
|
43
|
+
Given(/^(".*?"|the user) is logged in$/) do |user_tag|
|
44
|
+
# First, make sure we're not logged into another account
|
45
|
+
step 'the user is logged out'
|
46
|
+
# Note: This could be more efficient, often you're already logged in with the correct user.
|
47
|
+
# So a different solution would be to check if the correct user is already logged in:
|
48
|
+
# set_user_data(user_tag)
|
49
|
+
# logged_in? = browser.find(
|
50
|
+
# :span => {:text => get_user_data('username')},
|
51
|
+
# :throw => false
|
52
|
+
# )
|
53
|
+
# if logged_in? skip the rest
|
54
|
+
|
55
|
+
# Then follow the login steps
|
56
|
+
step "#{user_tag} logs in"
|
57
|
+
|
58
|
+
# And confirm the login was successful
|
59
|
+
step 'the page should display as logged in state'
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
|
data/lib/lapis_lazuli/generators/cucumber/template/features/step_definitions/validation_steps.rb
CHANGED
@@ -20,4 +20,48 @@ Then(/text "([^"]*)" should display/) do |string|
|
|
20
20
|
|
21
21
|
# There's a shortcut for that in find/wait:
|
22
22
|
browser.wait(:html => /#{string}/i)
|
23
|
+
end
|
24
|
+
|
25
|
+
Then(/^the user should be on page "(.*?)"$/) do |page|
|
26
|
+
# Get the expected url
|
27
|
+
expected_url = env('pages.root')
|
28
|
+
expected_url += env("pages.#{page}")
|
29
|
+
|
30
|
+
# A custom loop that waits 5 seconds until the expected_url is the same as the current url
|
31
|
+
start = Time.now
|
32
|
+
while browser.url != expected_url
|
33
|
+
break if (Time.now - start).to_i >= 5
|
34
|
+
sleep(0.1)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Check if they are the same
|
38
|
+
if browser.url != expected_url
|
39
|
+
error("The current URL and expected URL were not the same: \n Current: #{current_url}\n Expected: #{expected_url}")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
Then(/^the page should display as logged (in|out) state$/) do |logged|
|
45
|
+
# pending # Write code here that turns the phrase above into concrete actions
|
46
|
+
|
47
|
+
# Adjust variable for checking logged in or logged out state.
|
48
|
+
if logged == 'in'
|
49
|
+
condition = :until
|
50
|
+
message = 'Unable to find profile picture, the user wasnt logged in successfully'
|
51
|
+
elsif logged == 'out'
|
52
|
+
condition = :while
|
53
|
+
message = 'The profile picture is present, indicating that the user did not log out successfully'
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
# Try to find a way to confirm that a user is logged out.
|
58
|
+
# Easiest way is to a reversed check on an element that is only present when you're logged in
|
59
|
+
# For example, the profile picture
|
60
|
+
browser.wait(
|
61
|
+
:img => {:class => 'user-gravatar'},
|
62
|
+
:condition => condition,
|
63
|
+
:timeout => 5,
|
64
|
+
:message => message
|
65
|
+
)
|
66
|
+
# Lapis lazuli will automatically create a screenshot if this step fails.
|
23
67
|
end
|
@@ -6,4 +6,32 @@ require 'lapis_lazuli'
|
|
6
6
|
require 'lapis_lazuli/cucumber'
|
7
7
|
|
8
8
|
LapisLazuli::WorldModule::Config.config_file = "config/config.yml"
|
9
|
-
World(LapisLazuli)
|
9
|
+
World(LapisLazuli)
|
10
|
+
|
11
|
+
# Do something when LapisLazuli is started (This is before the browser is opened)
|
12
|
+
LapisLazuli.Start do
|
13
|
+
|
14
|
+
# This code snippet prevents the security popup to appear in FF v>47.
|
15
|
+
# If BROWSER is NIL, Lapis Lazuli will default to Firefox
|
16
|
+
if !ENV['BROWSER'] || ENV['BROWSER'] == 'firefox'
|
17
|
+
# Get Selenium to create a profile object
|
18
|
+
require 'selenium-webdriver'
|
19
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
20
|
+
profile['network.http.phishy-userpass-length'] = 255
|
21
|
+
browser :firefox, :profile => profile
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# This function is called before every scenario.
|
26
|
+
Before do
|
27
|
+
# This can be very handy to make sure a browser has the same settings before a new scenario starts.
|
28
|
+
# For example, to enforce a certain browser window size
|
29
|
+
new_width = 1024
|
30
|
+
new_height = 768
|
31
|
+
current_size = browser.window.size
|
32
|
+
# Only change the browser size, if it is not already the correct size
|
33
|
+
unless current_size.width == new_width && current_size.height == new_height
|
34
|
+
log.info "Resizing browser to #{new_width}x#{new_height} (Was #{current_size.width}x#{current_size.height}"
|
35
|
+
browser.window.resize_to(new_width, new_height)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Sometimes you're repeating a piece of code over and over again.
|
2
|
+
# At that point you should consider making it a function.
|
3
|
+
|
4
|
+
# Define a the user data to use.
|
5
|
+
def set_user_data(data)
|
6
|
+
# Load the user data from the configuration file
|
7
|
+
user_data = config("users.#{data}")
|
8
|
+
|
9
|
+
# Replace all random and time values in the data
|
10
|
+
user_data = replace_hash_constants(user_data)
|
11
|
+
|
12
|
+
# Put it in the global variable
|
13
|
+
$USER_DATA = user_data
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
# Get the data for the requested field.
|
18
|
+
def get_user_data(field)
|
19
|
+
# Make sure the user data is set before this function was called.
|
20
|
+
if $USER_DATA.nil?
|
21
|
+
error "No user data was set when get_user_data() was called for #{field}."
|
22
|
+
end
|
23
|
+
# Check if the specifically requested field is defined
|
24
|
+
if $USER_DATA[field].nil?
|
25
|
+
error "The requested user data `#{field}` does not exist. Are you sure it's defined in ./config/config.yml ?"
|
26
|
+
end
|
27
|
+
# Return te requested data
|
28
|
+
return $USER_DATA[field]
|
29
|
+
end
|
30
|
+
|
31
|
+
# Replace random or time values of a complete hash
|
32
|
+
def replace_hash_constants(hash)
|
33
|
+
if hash.respond_to? :each
|
34
|
+
new_hash = {}
|
35
|
+
hash.each do |key, value|
|
36
|
+
new_hash[key] = replace_constants(value)
|
37
|
+
end
|
38
|
+
else
|
39
|
+
new_hash = replace_constants(hash)
|
40
|
+
end
|
41
|
+
return new_hash
|
42
|
+
end
|
43
|
+
|
44
|
+
# replace certain constants in a string, for example '_TIMESTAMP_' becomes '154875631'
|
45
|
+
def replace_constants(value)
|
46
|
+
epoch = Time.now.to_i
|
47
|
+
alpha = number_to_letter(epoch)
|
48
|
+
timestamp = Time.now.strftime("D%Y-%M-%d-T%H-%M-%S")
|
49
|
+
value = value.to_s
|
50
|
+
old_val = value
|
51
|
+
value = value.sub('_RAND_', epoch.to_s)
|
52
|
+
value = value.sub('_TIMESTAMP_', timestamp)
|
53
|
+
value = value.sub('_RAND-ALPHA_', alpha)
|
54
|
+
unless value == old_val
|
55
|
+
log.debug "#{old_val} > #{value}"
|
56
|
+
end
|
57
|
+
return value
|
58
|
+
end
|
59
|
+
|
60
|
+
def number_to_letter(numbers)
|
61
|
+
num_string = numbers.to_s
|
62
|
+
alpha26 = ("a".."j").to_a
|
63
|
+
letters = ''
|
64
|
+
num_string.scan(/./).each do |number|
|
65
|
+
letters += alpha26[number.to_i]
|
66
|
+
end
|
67
|
+
return letters
|
68
|
+
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# LapisLazuli
|
3
3
|
# https://github.com/spriteCloud/lapis-lazuli
|
4
4
|
#
|
5
|
-
# Copyright (c) 2013-
|
5
|
+
# Copyright (c) 2013-2017 spriteCloud B.V. and other LapisLazuli contributors.
|
6
6
|
# All rights reserved.
|
7
7
|
#
|
8
8
|
module LapisLazuli
|
data/lib/lapis_lazuli/options.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# LapisLazuli
|
3
3
|
# https://github.com/spriteCloud/lapis-lazuli
|
4
4
|
#
|
5
|
-
# Copyright (c) 2013-
|
5
|
+
# Copyright (c) 2013-2017 spriteCloud B.V. and other LapisLazuli contributors.
|
6
6
|
# All rights reserved.
|
7
7
|
#
|
8
8
|
module LapisLazuli
|
data/lib/lapis_lazuli/proxy.rb
CHANGED
data/lib/lapis_lazuli/runtime.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# LapisLazuli
|
3
3
|
# https://github.com/spriteCloud/lapis-lazuli
|
4
4
|
#
|
5
|
-
# Copyright (c) 2013-
|
5
|
+
# Copyright (c) 2013-2017 spriteCloud B.V. and other LapisLazuli contributors.
|
6
6
|
# All rights reserved.
|
7
7
|
#
|
8
8
|
require 'singleton'
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# LapisLazuli
|
3
3
|
# https://github.com/spriteCloud/lapis-lazuli
|
4
4
|
#
|
5
|
-
# Copyright (c) 2013-
|
5
|
+
# Copyright (c) 2013-2017 spriteCloud B.V. and other LapisLazuli contributors.
|
6
6
|
# All rights reserved.
|
7
7
|
#
|
8
8
|
require "securerandom"
|
data/lib/lapis_lazuli/storage.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# LapisLazuli
|
3
3
|
# https://github.com/spriteCloud/lapis-lazuli
|
4
4
|
#
|
5
|
-
# Copyright (c) 2013-
|
5
|
+
# Copyright (c) 2013-2017 spriteCloud B.V. and other LapisLazuli contributors.
|
6
6
|
# All rights reserved.
|
7
7
|
#
|
8
8
|
module LapisLazuli
|
data/lib/lapis_lazuli/version.rb
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
# LapisLazuli
|
3
3
|
# https://github.com/spriteCloud/lapis-lazuli
|
4
4
|
#
|
5
|
-
# Copyright (c) 2013-
|
5
|
+
# Copyright (c) 2013-2017 spriteCloud B.V. and other LapisLazuli contributors.
|
6
6
|
# All rights reserved.
|
7
7
|
#
|
8
8
|
module LapisLazuli
|
9
|
-
VERSION = "0.
|
9
|
+
VERSION = "1.0.1"
|
10
10
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# LapisLazuli
|
3
3
|
# https://github.com/spriteCloud/lapis-lazuli
|
4
4
|
#
|
5
|
-
# Copyright (c) 2013-
|
5
|
+
# Copyright (c) 2013-2017 spriteCloud B.V. and other LapisLazuli contributors.
|
6
6
|
# All rights reserved.
|
7
7
|
#
|
8
8
|
require 'lapis_lazuli/api'
|
data/test/Gemfile
CHANGED
@@ -1,44 +1,21 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
# Add following two lines to your ~/.gemrc or /etc/gemrc:
|
5
|
-
# install: --no-rdoc --no-ri
|
6
|
-
# update: --no-rdoc --no-ri
|
7
|
-
|
8
|
-
# Install helper libraries
|
9
|
-
gem 'rspec'
|
10
|
-
gem 'gherkin'
|
11
|
-
gem 'xml-simple'
|
12
|
-
gem 'mechanize'
|
13
|
-
|
14
|
-
# Debuggers
|
15
|
-
platforms :ruby_18, :ruby_19 do
|
16
|
-
gem 'debugger'
|
17
|
-
end
|
18
|
-
platforms :ruby_20, :ruby_21 do
|
19
|
-
gem 'byebug'
|
20
|
-
gem 'rb-readline'
|
21
|
-
end
|
22
|
-
|
23
3
|
# Windows specific
|
24
4
|
platforms :mswin, :mingw do
|
25
5
|
gem 'win32console'
|
26
6
|
gem 'term-ansicolor'
|
27
7
|
end
|
28
8
|
|
9
|
+
# LapisLazul itself; test code should point to the current repo and branch
|
10
|
+
# repo = `git config --get remote.origin.url`
|
11
|
+
# branch = `git rev-parse --abbrev-ref HEAD`
|
12
|
+
# gem 'lapis_lazuli', :git => repo, :branch => branch
|
13
|
+
# gem "lapis_lazuli", '0.9.9-dev', path: 'E:\Ruby\lib\ruby\gems\2.3.0\gems\lapis-lazuli-dev'
|
14
|
+
gem "lapis_lazuli"
|
29
15
|
|
30
|
-
#
|
31
|
-
gem 'watir-webdriver'
|
16
|
+
# Project specific gems
|
32
17
|
gem 'watir-scroll'
|
33
|
-
|
34
|
-
gem '
|
35
|
-
# gem 'cucumber', '=1.3.19'
|
36
|
-
|
37
|
-
# Testing related
|
18
|
+
gem 'xml-simple'
|
19
|
+
gem 'mechanize'
|
38
20
|
gem 'simplecov'
|
39
|
-
gem 'test-unit'
|
40
|
-
|
41
|
-
# LapisLazul itself; test code should point to the current repo and branch
|
42
|
-
repo = `git config --get remote.origin.url`
|
43
|
-
branch = `git rev-parse --abbrev-ref HEAD`
|
44
|
-
gem 'lapis_lazuli', :git => repo, :branch => branch
|
21
|
+
gem 'test-unit'
|