Added examples find by id, name and class.

This commit is contained in:
jvelilla
2013-05-14 09:28:21 -03:00
parent e0c3c783fa
commit d344df6e7e
5 changed files with 216 additions and 1 deletions

View File

@@ -6,7 +6,16 @@ note
class
EXAMPLE_SEARCH
inherit
ANY
redefine
default_create
end
feature
default_create
do
search
end
feature -- Example
search
local

View File

@@ -18,4 +18,16 @@
<root class="EXAMPLE_SEARCH" feature="default_create"/>
<cluster name="src" location=".\" recursive="true"/>
</target>
<target name="findElementById" extends="selenium_example">
<root class="FIND_ELEMENT_ID" feature="default_create"/>
<cluster name="src" location=".\" recursive="true"/>
</target>
<target name="findElementByName" extends="selenium_example">
<root class="FIND_ELEMENT_NAME" feature="default_create"/>
<cluster name="src" location=".\" recursive="true"/>
</target>
<target name="findElementByClass" extends="selenium_example">
<root class="FIND_ELEMENT_CLASS" feature="default_create"/>
<cluster name="src" location=".\" recursive="true"/>
</target>
</system>

View File

@@ -0,0 +1,84 @@
note
description: "Using the class attribute to find elements. The class attribute is provided to apply CSS to an element."
class
FIND_ELEMENT_CLASS
inherit
ANY
redefine
default_create
end
create
default_create
feature
default_create
do
search
end
feature -- Search by id
search
local
web_driver: WEB_DRIVER
wait: WEB_DRIVER_WAIT
capabilities : SE_CAPABILITIES
do
-- Create desired capabilities
create capabilities.make
capabilities.set_css_selectors_enabled (True)
capabilities.set_browser_name ("chrome")
--Create a new instance of a Web driver
create web_driver.make
-- Start session with chrome and capabilities
web_driver.start_session_chrome_with_desired_capabilities (capabilities)
-- Go to EiffelRoom login page
web_driver.to_url ("http://www.eiffelroom.com/user?destination=front")
-- Find the user name, password element by its id and submit
if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-name")) as l_user and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-pass")) as l_pass and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-submit")) as l_form then
l_user.send_keys (<<"test">>)
l_pass.send_keys (<<"pass">>)
l_form.submit
end
-- After submit, there is an error message, and we still are in the same page
-- Wait for the page to load, timeout after 10 seconds
create wait.make (web_driver,10)
wait.until_when (agent expected_title (web_driver, "User account"))
if attached web_driver.get_page_tile as l_title then
print ("%NPage title is:" + l_title)
end
if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).class_name ("title")) as l_title then
if attached l_title.get_text as l_text then
print ("%NDisplay:" + l_text)
end
end
-- close the window
web_driver.window_close
end
expected_title (driver : WEB_DRIVER; title : STRING_32) : BOOLEAN
do
if attached {STRING_32} driver.get_page_tile as l_title and then l_title.has_substring (title) then
Result := True
end
end
end

View File

@@ -0,0 +1,53 @@
note
description: "Using the id attribute is the most preferable way to locate elements on a page."
class
FIND_ELEMENT_ID
inherit
ANY
redefine
default_create
end
create
default_create
feature
default_create
do
search
end
feature -- Search by id
search
local
web_driver: WEB_DRIVER
wait: WEB_DRIVER_WAIT
do
--Create a new instance of a Web driver
create web_driver.make
-- Start session with chrome
web_driver.start_session_chrome
-- Go to EiffelRoom login page
web_driver.to_url ("http://www.eiffelroom.com/user?destination=front")
-- Find the user name, password element by its id and submit
if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-name")) as l_user and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-pass")) as l_pass and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("edit-submit")) as l_form then
l_user.send_keys (<<"test">>)
l_pass.send_keys (<<"pass">>)
l_form.submit
end
if attached web_driver.get_page_tile as l_title then
print ("%NPage title is:" + l_title)
end
-- close the window
web_driver.window_close
end
end

View File

@@ -0,0 +1,57 @@
note
description: "[
Unlike find_element_id, find by name attribute may not be unique on a page. We might find multiple elements
with similar name attributes,if that happends, the first element on the page
will be selected, which may not be the element we are looking for.
]"
class
FIND_ELEMENT_NAME
inherit
ANY
redefine
default_create
end
create
default_create
feature
default_create
do
search
end
feature -- Search by id
search
local
web_driver: WEB_DRIVER
wait: WEB_DRIVER_WAIT
do
--Create a new instance of a Web driver
create web_driver.make
-- Start session with chrome
web_driver.start_session_chrome
-- Go to EiffelRoom login page
web_driver.to_url ("http://www.eiffelroom.com/user?destination=front")
-- Find the user name, password element by its name and submit
if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).name ("name")) as l_user and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).name ("pass")) as l_pass and then attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).name ("op")) as l_form then
l_user.send_keys (<<"test">>)
l_pass.send_keys (<<"pass">>)
l_form.submit
end
if attached web_driver.get_page_tile as l_title then
print ("%NPage title is:" + l_title)
end
-- close the window
web_driver.window_close
end
end