Skip to content

Commit 3bf772c

Browse files
committed
Initial import WebDriver Eiffel for Selenium2
0 parents  commit 3bf772c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+8834
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
EIFGENs
2+
.svn/
3+
*.swp
4+
*~
5+
*#

examples/application.e

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
note
2+
description : "project application root class"
3+
date : "$Date$"
4+
revision : "$Revision$"
5+
6+
class
7+
APPLICATION
8+
9+
inherit
10+
ARGUMENTS
11+
12+
create
13+
make
14+
15+
feature {NONE} -- Initialization
16+
17+
make
18+
-- Run application.
19+
do
20+
execute_search
21+
end
22+
23+
execute_example1
24+
do
25+
(create {EXAMPLE_1}).test
26+
end
27+
28+
execute_search
29+
do
30+
(create {EXAMPLE_SEARCH}).search
31+
end
32+
end

examples/example_1.e

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
note
2+
description: "Summary description for {EXAMPLE_1}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
EXAMPLE_1
9+
10+
feature -- Access
11+
test
12+
local
13+
web_driver: SE_JSON_WIRE_PROTOCOL
14+
capabilities: SE_CAPABILITIES
15+
l_session : detachable SE_SESSION
16+
do
17+
create web_driver.make
18+
if attached web_driver.status as l_status then
19+
create capabilities.make
20+
capabilities.set_browser_name ("chrome")
21+
l_session:= web_driver.create_session_with_desired_capabilities (capabilities)
22+
if attached l_session as l_s then
23+
24+
-- navigate to www.google.com
25+
web_driver.navigate_to_url (l_s.session_id, "http://www.google.com/")
26+
27+
-- Find the text input element by its name
28+
if attached {WEB_ELEMENT} web_driver.search_element (l_s.session_id, (create {SE_BY}).name ("q")) as l_element then
29+
-- search something
30+
web_driver.send_event(l_s.session_id, l_element.element,<<"Eiffel Room">>)
31+
32+
-- Submit Form
33+
web_driver.element_submit (l_s.session_id, l_element.element)
34+
35+
if attached web_driver.page_title (l_s.session_id) as l_page then
36+
print ("Page Name" + l_page)
37+
end
38+
end
39+
end
40+
41+
end
42+
end
43+
44+
-- // And now use this to visit Google
45+
-- driver.get("http://www.google.com");
46+
47+
-- // Find the text input element by its name
48+
-- WebElement element = driver.findElement(By.name("q"));
49+
50+
-- // Enter something to search for
51+
-- element.sendKeys("Cheese!");
52+
53+
-- // Now submit the form. WebDriver will find the form for us from the element
54+
-- element.submit();
55+
56+
-- // Check the title of the page
57+
-- System.out.println("Page title is: " + driver.getTitle());
58+
end

examples/example_search.e

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
note
2+
description: "Summary description for {EXAMPLE_SEARCH}."
3+
author: ""
4+
date: "$Date$"
5+
revision: "$Revision$"
6+
7+
class
8+
EXAMPLE_SEARCH
9+
10+
inherit
11+
12+
ANY
13+
redefine
14+
default_create
15+
end
16+
17+
feature
18+
19+
default_create
20+
do
21+
search
22+
end
23+
24+
feature -- Example
25+
26+
search
27+
local
28+
web_driver: WEB_DRIVER
29+
wait: WEB_DRIVER_WAIT
30+
do
31+
--Create a new instance of a Web driver
32+
create web_driver.make
33+
34+
-- Start session with chrome
35+
web_driver.start_session_chrome
36+
37+
-- Go to Google
38+
web_driver.to_url ("http://www.google.com/")
39+
40+
-- Find the text input element by its name
41+
if attached web_driver.find_element ((create {SE_BY}).name ("q")) as l_element then
42+
43+
-- Enter something to search for
44+
l_element.send_keys (<<"Eiffel Room">>)
45+
46+
-- Now submit the form. WebDriver will find the form for us from the element
47+
l_element.submit
48+
end
49+
if attached web_driver.get_page_tile as l_title then
50+
print ("%NPage title is:" + l_title)
51+
end
52+
53+
-- Google's search is rendered dynamically with JavaScript.
54+
-- Wait for the page to load, timeout after 10 seconds
55+
create wait.make (web_driver, 10)
56+
wait.until_when (agent expected_title(web_driver, "Eiffel Room"))
57+
if attached web_driver.get_page_tile as l_title then
58+
print ("%NPage title is:" + l_title)
59+
end
60+
61+
-- close the window
62+
web_driver.window_close
63+
end
64+
65+
expected_title (driver: WEB_DRIVER; title: STRING_32): BOOLEAN
66+
do
67+
if attached {STRING_32} driver.get_page_tile as l_title and then l_title.has_substring (title) then
68+
Result := True
69+
end
70+
end
71+
72+
end

examples/examples.ecf

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="ISO-8859-1"?>
2+
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-10-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-10-0 http://www.eiffel.com/developers/xml/configuration-1-10-0.xsd" name="selenium_example" uuid="61EFD50A-C916-494A-91D6-3E12E0738F4D">
3+
<target name="selenium_example">
4+
<file_rule>
5+
<exclude>/.git$</exclude>
6+
<exclude>/EIFGENs$</exclude>
7+
<exclude>/CVS$</exclude>
8+
<exclude>/.svn$</exclude>
9+
</file_rule>
10+
<option warning="true" is_attached_by_default="true" void_safety="all" syntax="transitional">
11+
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
12+
</option>
13+
<setting name="console_application" value="true"/>
14+
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
15+
<library name="selenium" location="..\selenium-safe.ecf"/>
16+
</target>
17+
<target name="search" extends="selenium_example">
18+
<root class="EXAMPLE_SEARCH" feature="default_create"/>
19+
<cluster name="src" location=".\" recursive="true"/>
20+
</target>
21+
<target name="findElementById" extends="selenium_example">
22+
<root class="FIND_ELEMENT_ID" feature="default_create"/>
23+
<cluster name="src" location=".\" recursive="true"/>
24+
</target>
25+
<target name="findElementByName" extends="selenium_example">
26+
<root class="FIND_ELEMENT_NAME" feature="default_create"/>
27+
<cluster name="src" location=".\" recursive="true"/>
28+
</target>
29+
<target name="findElementByClass" extends="selenium_example">
30+
<root class="FIND_ELEMENT_CLASS" feature="default_create"/>
31+
<cluster name="src" location=".\" recursive="true"/>
32+
</target>
33+
<target name="findElementChild" extends="selenium_example">
34+
<root class="FIND_ELEMENT_CHILD" feature="default_create"/>
35+
<cluster name="src" location=".\" recursive="true"/>
36+
</target>
37+
<target name="findElementsLinks" extends="selenium_example">
38+
<root class="FIND_ELEMENTS_LINKS" feature="default_create"/>
39+
<cluster name="src" location=".\" recursive="true"/>
40+
</target>
41+
<target name="findElementsLinksByText" extends="selenium_example">
42+
<root class="FIND_ELEMENTS_LINKS_BY_TEXT" feature="default_create"/>
43+
<cluster name="src" location=".\" recursive="true"/>
44+
</target>
45+
<target name="findElementsLinksByPartialText" extends="selenium_example">
46+
<root class="FIND_ELEMENTS_LINKS_BY_PARTIAL_TEXT" feature="default_create"/>
47+
<cluster name="src" location=".\" recursive="true"/>
48+
</target>
49+
<target name="findElementCssSelector" extends="selenium_example">
50+
<root class="FIND_ELEMENT_CSS_SELECTOR" feature="default_create"/>
51+
<cluster name="src" location=".\" recursive="true"/>
52+
</target>
53+
<target name="findElementXPath" extends="selenium_example">
54+
<root class="FIND_ELEMENT_XPATH" feature="default_create"/>
55+
<cluster name="src" location=".\" recursive="true"/>
56+
</target>
57+
58+
59+
60+
61+
62+
63+
</system>

examples/find_element_child.e

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
note
2+
description: "The WEB_ELEMENT class also supports find methods that find child elements."
3+
4+
class
5+
FIND_ELEMENT_CHILD
6+
7+
inherit
8+
9+
ANY
10+
redefine
11+
default_create
12+
end
13+
14+
create
15+
default_create
16+
17+
feature
18+
19+
default_create
20+
do
21+
search
22+
end
23+
24+
feature -- Search by id
25+
26+
search
27+
local
28+
web_driver: WEB_DRIVER
29+
wait: WEB_DRIVER_WAIT
30+
do
31+
--Create a new instance of a Web driver
32+
create web_driver.make
33+
34+
-- Start session with chrome
35+
web_driver.start_session_chrome
36+
37+
-- Go to EiffelRoom login page
38+
web_driver.to_url ("http://www.eiffelroom.com/")
39+
40+
-- Find the element div with id page,and then we can find a child element div page-inner
41+
--<div id="page">
42+
-- <div id="page-inner">
43+
-- <a id="navigation-top" name="top"></a>
44+
-- <div id="skip-to-nav">
45+
-- <div id="header">
46+
-- <div id="main">
47+
-- <div id="footer">
48+
-- </div>
49+
--</div>
50+
if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).id ("page")) as l_div_page then
51+
print ("%N Page element id" + l_div_page.element)
52+
if attached {WEB_ELEMENT}l_div_page.find_element ((create {SE_BY}).id ("page-inner")) as l_div_page_inner then
53+
print ("%N Inner Page element id" + l_div_page_inner.element)
54+
end
55+
end
56+
-- close the window
57+
web_driver.window_close
58+
print ("%N")
59+
end
60+
61+
end

examples/find_element_class.e

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
note
2+
description: "Using the class attribute to find elements. The class attribute is provided to apply CSS to an element."
3+
4+
class
5+
FIND_ELEMENT_CLASS
6+
7+
inherit
8+
9+
ANY
10+
redefine
11+
default_create
12+
end
13+
14+
create
15+
default_create
16+
17+
feature
18+
19+
default_create
20+
do
21+
search
22+
end
23+
24+
feature -- Search by id
25+
26+
search
27+
local
28+
web_driver: WEB_DRIVER
29+
wait: WEB_DRIVER_WAIT
30+
capabilities : SE_CAPABILITIES
31+
do
32+
-- Create desired capabilities
33+
34+
create capabilities.make
35+
capabilities.set_css_selectors_enabled (True)
36+
capabilities.set_browser_name ("chrome")
37+
38+
--Create a new instance of a Web driver
39+
create web_driver.make
40+
41+
-- Start session with chrome and capabilities
42+
web_driver.start_session_chrome_with_desired_capabilities (capabilities)
43+
44+
-- Go to EiffelRoom login page
45+
web_driver.to_url ("http://www.eiffelroom.com/user?destination=front")
46+
47+
48+
-- Find the user name, password element by its id and submit
49+
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
50+
l_user.send_keys (<<"test">>)
51+
l_pass.send_keys (<<"pass">>)
52+
l_form.submit
53+
end
54+
55+
-- After submit, there is an error message, and we still are in the same page
56+
57+
-- Wait for the page to load, timeout after 10 seconds
58+
create wait.make (web_driver,10)
59+
wait.until_when (agent expected_title (web_driver, "User account"))
60+
61+
62+
if attached web_driver.get_page_tile as l_title then
63+
print ("%NPage title is:" + l_title)
64+
end
65+
66+
if attached {WEB_ELEMENT} web_driver.find_element ((create {SE_BY}).class_name ("title")) as l_title then
67+
if attached l_title.get_text as l_text then
68+
print ("%NDisplay:" + l_text)
69+
70+
end
71+
end
72+
-- close the window
73+
web_driver.window_close
74+
end
75+
76+
77+
expected_title (driver : WEB_DRIVER; title : STRING_32) : BOOLEAN
78+
do
79+
if attached {STRING_32} driver.get_page_tile as l_title and then l_title.has_substring (title) then
80+
Result := True
81+
end
82+
end
83+
84+
end

0 commit comments

Comments
 (0)