Skip to content

Commit

Permalink
py: Implement getAttribute and isDisplayed using atoms
Browse files Browse the repository at this point in the history
Obviously, only when connected to a w3c remote end.
  • Loading branch information
shs96c committed Sep 1, 2016
1 parent 65c0d49 commit 4c75ef0
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ py/selenium/webdriver/firefox/amd64/
py/selenium/webdriver/firefox/webdriver.xpi
py/selenium/webdriver/firefox/webdriver_prefs.json
py/selenium/webdriver/firefox/x86/
py/selenium/webdriver/remote/getAttribute.js
py/selenium/webdriver/remote/isDisplayed.js
py/docs/build/
selenium.egg-info/
third_party/java/jetty/jetty-repacked.jar
Expand Down
2 changes: 0 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,7 @@ task :javadocs => [:common, :firefox, :ie, :remote, :support, :chrome, :selenium
end

task :py_prep_for_install_release => [
"//javascript/firefox-driver:webdriver",
:chrome,
"//javascript/firefox-driver:webdriver_prefs",
"//py:prep"
]

Expand Down
12 changes: 10 additions & 2 deletions py/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,13 @@ py_install(
)

py_prep(
name = "prep"
)
name = "prep",
deps = [
"//cpp:noblur",
"//cpp:noblur64",
"//javascript/atoms/fragments:is-displayed",
"//javascript/firefox-driver:webdriver",
"//javascript/firefox-driver:webdriver_prefs",
"//javascript/webdriver/atoms:getAttribute"
])

39 changes: 12 additions & 27 deletions py/selenium/webdriver/remote/webelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import hashlib
import pkgutil
import os
import zipfile
try:
Expand Down Expand Up @@ -48,11 +49,6 @@ class WebElement(object):
``StaleElementReferenceException`` is thrown, and all future calls to this
instance will fail."""

boolean_attributes = ['default', 'typemustmatch', 'checked', 'defer', 'async', 'muted',
'reversed', 'required', 'controls', 'ismap', 'disabled', 'novalidate',
'readonly', 'allowfullscreen', 'selected', 'formnovalidate',
'multiple', 'autofocus', 'open', 'loop', 'autoplay']

def __init__(self, parent, id_, w3c=False):
self._parent = parent
self._id = id_
Expand Down Expand Up @@ -134,27 +130,10 @@ def get_attribute(self, name):

attributeValue = ''
if self._w3c :
if name == 'style':
return self.parent.execute_script("return arguments[0].style.cssText", self)
attributeValue = self.get_property(name)
if (attributeValue in [None, '', False] and name != 'value') or name in self.boolean_attributes:
# We need to check the attribute before we really set it to None
resp = self._execute(Command.GET_ELEMENT_ATTRIBUTE, {'name': name})
attributeValue = resp.get('value')

# Even though we have a value, we could be getting the browser default,
# We now need check it's there in the DOM...
resp = self.parent.execute_script("return arguments[0].hasAttribute(arguments[1])",
self, name)
if resp is False:
attributeValue = None
else:
attributeValue = "{0}".format(attributeValue)

if attributeValue is not None:
if name != 'value' and attributeValue.lower() in ('true', 'false'):
attributeValue = attributeValue.lower()

raw = pkgutil.get_data(__package__, 'getAttribute.js')
attributeValue = self.parent.execute_script(
"return (%s).apply(null, arguments);" % raw,
self, name)
else:
resp = self._execute(Command.GET_ELEMENT_ATTRIBUTE, {'name': name})
attributeValue = resp.get('value')
Expand Down Expand Up @@ -367,7 +346,13 @@ def send_keys(self, *value):
# RenderedWebElement Items
def is_displayed(self):
"""Whether the element is visible to a user."""
return self._execute(Command.IS_ELEMENT_DISPLAYED)['value']
if self._w3c :
raw = pkgutil.get_data(__package__, 'isDisplayed.js')
return self.parent.execute_script(
"return (%s).apply(null, arguments);" % raw,
self)
else:
return self._execute(Command.IS_ELEMENT_DISPLAYED)['value']

@property
def location_once_scrolled_into_view(self):
Expand Down
4 changes: 3 additions & 1 deletion rake-tasks/buck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ def buck(*args, &block)
# cases where the rule was not created by CrazyFun. Rules created by the "rule" method will
# be a FileTask, whereas those created by CrazyFun are normal rake Tasks.

if task.class == Rake::FileTask && !task.out
buck_file = task.name[/\/\/([^:]+)/, 1] + "/BUCK"

if task.class == Rake::FileTask && !task.out && File.exists?(buck_file)
task.enhance do
Buck::buck_cmd.call('build', ['--deep', task.name])
end
Expand Down
31 changes: 27 additions & 4 deletions rake-tasks/crazy_fun/mappings/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def add_all(fun)

fun.add_mapping("py_install", Python::Install.new)

fun.add_mapping("py_prep", Python::AddNormalDependencies.new)
fun.add_mapping("py_prep", Python::Prep.new)
end
end
Expand Down Expand Up @@ -235,15 +236,35 @@ def handle(fun, dir, args)
end
end

class AddDependencies < PyTask
def handle(fun, dir, args)
(args[:browsers] || [:ff]).each do |browser|
target = Rake::Task[task_name(dir, "#{args[:name]}_#{browser}")]
add_dependencies(target, dir, args[:deps])
resources = get_resources(browser, args)
add_dependencies(target, dir, resources)
end
end
end

class AddNormalDependencies < PyTask
def handle(fun, dir, args)
target = Rake::Task[task_name(dir, "#{args[:name]}")]
add_dependencies(target, dir, args[:deps])
end
end

class Prep < Tasks
def handle(fun, dir, args)
task Tasks.new.task_name(dir, args[:name]) do
remote_py_home = "py/selenium/webdriver/remote/"
firefox_py_home = "py/selenium/webdriver/firefox/"
firefox_build_dir = 'build/javascript/firefox-driver/'
x86 = firefox_py_home + "x86/"
amd64 = firefox_py_home + "amd64/"

if (windows?) then
remote_py_home = remote_py_home.gsub(/\//, "\\")
firefox_build_dir = firefox_build_dir.gsub(/\//, "\\")
firefox_py_home = firefox_py_home .gsub(/\//, "\\")
x86 = x86.gsub(/\//,"\\")
Expand All @@ -253,11 +274,13 @@ def handle(fun, dir, args)
mkdir_p x86 unless File.exists?(x86)
mkdir_p amd64 unless File.exists?(amd64)

cp "cpp/prebuilt/i386/libnoblur.so", x86+"x_ignore_nofocus.so", :verbose => true
cp "cpp/prebuilt/amd64/libnoblur64.so", amd64+"x_ignore_nofocus.so", :verbose => true
cp Rake::Task['//cpp:noblur'].out, x86+"x_ignore_nofocus.so", :verbose => true
cp Rake::Task['//cpp:noblur64'].out, amd64+"x_ignore_nofocus.so", :verbose => true
cp Rake::Task['//javascript/atoms/fragments:is-displayed'].out, remote_py_home+"isDisplayed.js", :verbose => true
cp Rake::Task['//javascript/webdriver/atoms:getAttribute'].out, remote_py_home+"getAttribute.js", :verbose => true

cp firefox_build_dir + "webdriver.xpi" , firefox_py_home, :verbose => true
cp firefox_build_dir + "webdriver_prefs.json" , firefox_py_home, :verbose => true
cp Rake::Task['//javascript/firefox-driver:webdriver'].out, firefox_py_home, :verbose => true
cp Rake::Task['//javascript/firefox-driver:webdriver_prefs'].out, firefox_py_home, :verbose => true
end
end
end
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@
'selenium.webdriver.support', ],
'package_data': {
'selenium.webdriver.firefox': ['*.xpi', 'webdriver_prefs.json'],
'selenium.webdriver.remote': ['getAttribute.js', 'isDisplayed.js'],
},
'data_files': [('selenium/webdriver/firefox/x86', ['py/selenium/webdriver/firefox/x86/x_ignore_nofocus.so']),
('selenium/webdriver/firefox/amd64', ['py/selenium/webdriver/firefox/amd64/x_ignore_nofocus.so'])],
('selenium/webdriver/firefox/amd64', ['py/selenium/webdriver/firefox/amd64/x_ignore_nofocus.so']),
('selenium/webdriver/remote', ['py/selenium/webdriver/remote/getAttribute.js']),
('selenium/webdriver/remote', ['py/selenium/webdriver/remote/isDisplayed.js'])],
'include_package_data': True,
'zip_safe': False
}
Expand Down

0 comments on commit 4c75ef0

Please sign in to comment.