Skip to content

Commit

Permalink
Multiple element selectors do not use subtypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffnyman committed Mar 18, 2016
1 parent 0a9bb15 commit 240e726
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
11 changes: 5 additions & 6 deletions README.md
@@ -1,14 +1,14 @@
# Symbiont

[![Build Status](https://travis-ci.org/jnyman/symbiont.svg)](https://travis-ci.org/jnyman/symbiont)
[![Gem Version](https://badge.fury.io/rb/symbiont.svg)](http://badge.fury.io/rb/symbiont)
[![License](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jnyman/symbiont/blob/master/LICENSE.txt)

[![Build Status](https://travis-ci.org/jnyman/symbiont.svg)](https://travis-ci.org/jnyman/symbiont)
[![Dependency Status](https://gemnasium.com/jnyman/symbiont.png)](https://gemnasium.com/jnyman/symbiont)
[![Code Climate](https://codeclimate.com/github/jnyman/symbiont/badges/gpa.svg)](https://codeclimate.com/github/jnyman/symbiont)

Symbiont provides a semantic domain-specific language that can be used to construct a fluent interface for test execution libraries. The initial focus will be on using the [watir-webdriver](https://github.com/watir/watir-webdriver) API as the underlying driver library.

[![Gitter chat](https://badges.gitter.im/jnyman/symbiont.png)](https://gitter.im/jnyman/symbiont)
[![endorse](https://api.coderwall.com/jnyman/endorsecount.png)](https://coderwall.com/jnyman)

Symbiont provides a semantic domain-specific language that can be used to construct a fluent interface for test execution libraries. The initial focus will be on using the [watir-webdriver](https://github.com/watir/watir-webdriver) API as the underlying driver library.

## What is this?

Expand All @@ -20,7 +20,6 @@ In terms of what Symbiont does, it provides a way to describe your application i

The DSL provides a fluent interface that can be used for constructing test execution logic. This fluent interface promotes the idea of compressibility of your test logic, allowing for more factoring, more reuse, and less repetition.


## Installation

To get the latest stable release, add this line to your application's Gemfile:
Expand Down
6 changes: 5 additions & 1 deletion lib/symbiont/accessor.rb
Expand Up @@ -3,7 +3,11 @@ module Accessor
# @param element [Symbol] name of Watir-based object
# @param locator [Hash] locators for referencing the element
def reference_element(element, locator)
browser.send(element, *locator).to_subtype
begin
browser.send(element, *locator).to_subtype
rescue NoMethodError
browser.send(element, *locator)
end
end
end
end
10 changes: 9 additions & 1 deletion spec/fixtures/element_definitions.rb
Expand Up @@ -4,7 +4,7 @@
context "#{element} on the watir-webdriver platform" do
it "will locate a specific #{element} with a single locator" do
expect(watir_browser).to receive(element).with(id: element).and_return(watir_element)
allow(watir_element).to receive(:to_subtype).and_return(watir_element)
expect(watir_element).to receive(:to_subtype).and_return(watir_element)
expect(watir_definition.send "#{element}").to eq(watir_element)
end

Expand All @@ -27,6 +27,14 @@
expect(watir_browser).to receive(element).with(id: element).and_return(watir_element)
expect(watir_definition.send "#{element}_block_arg", element).to eq(watir_element)
end

it 'will not use subtype for multiple element selector' do
if element == 'buttons'
allow(watir_element).to receive(:to_subtype) { raise NoMethodError }
expect(watir_browser).to receive(element).twice.with(id: element).and_return(watir_element)
expect(watir_definition.send "#{element}").to eq(watir_element)
end
end
end

end
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/page_definitions.rb
Expand Up @@ -23,7 +23,7 @@ class ValidPage
url_matches /:\d{4}/
title_is 'Symbiote'

%w(text_field button file_field textarea select_list checkbox).each do |element|
%w(buttons text_field button file_field textarea select_list checkbox).each do |element|
send element, :"#{element}", id: element

send element, :"#{element}_proc", proc { browser.send(element, id: element) }
Expand Down
2 changes: 1 addition & 1 deletion spec/symbiont/elements_spec.rb
Expand Up @@ -2,7 +2,7 @@
include_context :page
include_context :element

provides_an 'element generator for', %w{text_field button}
provides_an 'element generator for', %w{text_field button buttons}
provides_an 'element set generator for', %w{text_field file_field textarea}
provides_an 'element select generator for', %w{select_list}
end
22 changes: 10 additions & 12 deletions test/symbiont-with-watir.rb
Expand Up @@ -4,23 +4,23 @@
require 'symbiont'
include Symbiont::Factory

class Symbiote
class Decohere
attach Symbiont

url_is 'http://localhost:9292'
url_matches /:\d{4}/
url_is 'https://decohere.herokuapp.com/'
url_matches /decohere/

element :open_form, id: 'open'
element :open_form, id: 'openLogin'

text_field :username, id: 'username'
text_field :password, id: 'password'
button :login, id: 'login-button'
text_field :username, id: 'username'
text_field :password, id: 'password'
button :login, id: 'login'
end

class Stardate
attach Symbiont

url_is 'http://localhost:9292/stardate'
url_is 'https://decohere.herokuapp.com/stardate'

elements :facts, css: 'ul#fact-list li a'
end
Expand All @@ -29,9 +29,7 @@ class Stardate

Symbiont.set_browser

on_view(Symbiote)
#@page = Symbiote.new
#@page.view
on_view(Decohere)

puts "Page displayed? #{@page.displayed?}"

Expand All @@ -42,7 +40,7 @@ class Stardate
puts "Page URL: #{@page.current_url}"
puts "Page secure? #{@page.secure?}"

on(Symbiote) do
on(Decohere) do
@page.open_form.click
@page.username.set 'admin'
@page.password.set 'admin'
Expand Down

0 comments on commit 240e726

Please sign in to comment.