aidy
February 27, 2008, 8:25pm
1
Hi,
All I want it to read this YAML as a ruby hash and place into the
below methods. Could someone help?
test: tiscali
url: http://tiscali3-test.vizumi.com/
register:
first_name: aidy
surname: smith
email: ‘[email protected] ’
password: password
registration: KJHDF123
tiscali= SmokeTest.new(“Tiscali”, “http://tiscali3-test.vizumi.com/ ”)
tiscali.register(‘aidy’, 'smith, ‘[email protected] ’,
‘password’, ‘KJHDF123’)
Aidy
aidy
February 27, 2008, 8:34pm
2
On Thu, Feb 28, 2008 at 04:24:58AM +0900, aidy wrote:
registration: KJHDF123
tiscali= SmokeTest.new(“Tiscali”, “http://tiscali3-test.vizumi.com/ ”)
tiscali.register(‘aidy’, 'smith, ‘[email protected] ’,
‘password’, ‘KJHDF123’)
require ‘yaml’
def SmokeTest.create_from_yaml_file(filename)
data = YAML.load_file(filename)
obj = new(data[‘test’], data[‘url’])
obj.register(data[‘first_name’], data[‘surname’], data[‘email’],
data[‘password’], data[‘registration’])
obj
end
tiscali = SmokeTest.create_from_yaml_file(‘tiscali.yml’)
Aidy
–Greg
aidy
February 27, 2008, 9:45pm
3
Hi Greg
On Feb 27, 7:33 pm, Gregory S. [email protected]
wrote:
password: password
obj = new(data[‘test’], data[‘url’])
Brilliant thanks.
Aidy
aidy
February 28, 2008, 2:05pm
4
Hi Greg,
Thanks for you help but I am having trouble losing the hash value when
calling the method
one.rb
def SmokeTest.create_from_yaml_file(filename)
data = YAML.load_file(filename)
obj = new(data[‘test’], data[‘url’])
obj.register(data[‘first_name’], data[‘surname’], data[‘email’],
data[‘password’], data[‘registration’])
end
SmokeTest.create_from_yaml_file(‘C:\test.yaml’)
two.rb
def register_an_account(first_name, last_name, email, password,
registration_code)
enter_first_name(first_name)
..........
end
def enter_first_name(first_name)
$browser.text_field(:id, /firstname/).set(first_name)
$test_log.test_results “comment”, “first name entered of:
#{first_name}”
end
Cheers
Aidy
aidy
February 28, 2008, 2:14pm
5
On Thu, Feb 28, 2008 at 10:04:57PM +0900, aidy wrote:
Hi Greg,
Thanks for you help but I am having trouble losing the hash value when
calling the method
I don’t know what you mean by that.
one.rb
def SmokeTest.create_from_yaml_file(filename)
data = YAML.load_file(filename)
obj = new(data[‘test’], data[‘url’])
obj.register(data[‘first_name’], data[‘surname’], data[‘email’],
data[‘password’], data[‘registration’])
end
[…]
This is incorrect. You are missing the last line from the method I
originally wrote, which is just obj. If you don’t have that, the
create_from_yaml method returns whatever obj.register returns, rather
than
the created object itself. This may be the problem you are having.
Cheers
Aidy
–Greg
aidy
February 28, 2008, 5:04pm
6
Hi,
def SmokeTest.create_from_yaml_file(filename)
data = YAML.load_file(filename)
obj = new(data[‘test’], data[‘url’])
obj.register(data[‘first_name’], data[‘surname’], data[‘email’],
data[‘password’], data[‘registration’])
obj
end
SmokeTest.create_from_yaml_file(‘C:\tiscali.yml’)
When I get to obj.register(data[‘first_name’], I get a nil object.
My yaml is
test: tiscali
url: http://tiscali3-test.vizumi.com/
register:
first_name: aidy
surname: smith
email: ‘[email protected] ’
password: password
registration: KJHDF123
Thanks
Aidy
aidy
February 28, 2008, 9:42pm
7
On Fri, Feb 29, 2008 at 01:09:55AM +0900, aidy wrote:
The problem is I am trying to use nested mapping. I have commented out
register.
Ah, yes, that would do it. Sorry, I missed that.
Aidy
–Greg
aidy
February 28, 2008, 5:17pm
8
test: tiscali
url: http://tiscali3-test.vizumi.com/
register:
first_name: aidy
surname: smith
email: ‘[email protected] ’
password: password
registration: KJHDF123
The problem is I am trying to use nested mapping. I have commented out
register.
Aidy
aidy
March 3, 2008, 2:50pm
9
Hi Greg,
On 28 Feb, 20:40, Gregory S. [email protected]
wrote:
On Fri, Feb 29, 2008 at 01:09:55AM +0900, aidy wrote:
There are two things I do not undersand
why you have added a method to this class:
def SmokeTest.create_from_yaml_file(filename)
And how can you get away with instantiating here.
obj = new(data[‘test’], data[‘url’])
Cheers
Aidy
aidy
March 3, 2008, 5:31pm
10
Hi All (greg)
I just can’t get the code to iterate through both docs.
def SmokeTest.create_from_yaml_file(filename)
require ‘yaml’
log = File.open(filename)
#yp = YAML::load_documents(log) { |data|
YAML::each_document(log) { |data|
obj = new(data[‘test’], data[‘url’])
obj.register(data[‘first_name’], data[‘surname’], data[‘email’],
data[‘password’], data[‘registration’])
obj.login_to_site(data[‘email’], data[‘password’])
obj.search_for_film(data[‘search_term’],
data[‘expected_search_result’])
obj
}
end
SmokeTest.create_from_yaml_file(‘C:\tiscali.yaml’)
test: tiscali
url: http://tiscali3-test.vizumi.com/
first_name: aidy
surname: lewis
email: [email protected]
password: password
registration: KJHDF123
search_term: Alien
expected_search_result: Alien 3
test: Vizumi
url: http://vizumi3-test.vizumi.com/
first_name: aidy
surname: lewis
email: [email protected]
password: password
registration: KJHDF123
search_term: Alien
expected_search_result: Alien 3
Cheers
Aidy
aidy
March 3, 2008, 3:36pm
11
On Mon, Mar 03, 2008 at 10:49:54PM +0900, aidy wrote:
And how can you get away with instantiating here.
obj = new(data[‘test’], data[‘url’])
Well, it’s sort of a constructor built on top of the standard
constructor
(new). It certainly belongs to the class, since it is building an object
of
that class, and because it is a method of that class object, it can call
new without fully qualifying it (i.e. SmokeTest.new).
Remember that there is nothing terribly special about the new method. I
believe it does nothing more than call alloc (to get an uninitialized
object of the class) then call initialize on that object. (I’m sure I
will
be corrected if there is more to it than that.) Likewise, there
is nothing special about the initialize function. By convention (and
default implementation), it is called by the class new method, but it’s
just a method like any other.
All I did was write a new constructor for your class, wrapping the
default
constructor.
Cheers
Aidy
–Greg
aidy
March 3, 2008, 6:02pm
12
On Tue, Mar 04, 2008 at 01:30:09AM +0900, aidy wrote:
Hi All (greg)
I just can’t get the code to iterate through both docs.
[…]
I am insufficiently familiar with multi-document YAML to help you here.
Sorry. Perhaps someone else will be able to help.
Cheers
Aidy
–Greg
aidy
March 3, 2008, 7:46pm
13
Thanks for the help. Not much documention on YAML. Just feel it is
right for testing. Doing this and just one iteration running (
def SmokeTest.create_from_yaml_file(filename)
require ‘yaml’
File.open(filename) do |yf|
YAML.each_document(yf) do |data|
obj = new(data[‘test’], data[‘url’])
obj.register(data[‘first_name’], data[‘surname’], data[‘email’],
data[‘password’], data[‘registration’])
obj.login_to_site(data[‘email’], data[‘password’])
obj.search_for_film(data[‘search_term’],
data[‘expected_search_result’])
obj
end
end
end
SmokeTest.create_from_yaml_file(‘C:\tiscali.yaml’)
(one file)
test: tiscali
url: http://tiscali3-test.vizumi.com/
first_name: aidy
surname: smith
email: ‘[email protected] ’
password: password
registration: KJHDF123
test: vizumi
url: vizumi3-test.vizumi.com
first_name: aidy
surname: smith222
email: ‘[email protected] ’
password: password
registration: KJHDF123
aidy
March 3, 2008, 6:31pm
14
On Tue, Mar 04, 2008 at 01:30:09AM +0900, aidy wrote:
Hi All (greg)
I just can’t get the code to iterate through both docs.
Hi, question: do you have a document separator between each YAML
document?
It’s three dashes.
docs = <<END
Document 2
END
=> “- Document 1\n—\n- Document 2\n”
YAML.each_document(docs) { |doc| p doc }
[“Document 1”]
[“Document 2”]
=> nil
_why