Last active
June 1, 2018 07:03
-
-
Save enochchu/16b4267d18bd328add76e9c066144c7a to your computer and use it in GitHub Desktop.
Pseudo Code Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Test | |
def selectNode(shoeSize) | |
# Let's assume the cells is on a web page. And we are using | |
# selenium to parse the boxes. | |
# Here are some boilerplate code I found | |
driver = Selenium::WebDriver.for :firefox | |
driver.navigate.to "http://127.0.0.1/boxes" | |
# http://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/SearchContext.html#find_elements-instance_method | |
boxElements = driver.find_elements(:id,"boxes") | |
# Lets iterate the boxes. Let's use this nifty each_with_index because we can assume the index represents the position of the box. | |
# https://ruby-doc.org/core-2.5.1/Enumerable.html#method-i-each_with_index | |
# Let's create a map too for a simple mapping of the value since the boxElements are not aware of the text inside. | |
shoeSizeMap = Hash.new | |
boxElements.each_with_index do |box, index| | |
# Let's assume the element is dead simple. It's just a text inside | |
# http://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/Element.html#text-instance_method | |
shoeSizeMap[box.text] = index | |
end | |
# The setup with mapping is complete. Ideally this should be done in setUp. | |
# Let's actually do the test. | |
return shoeSizeMap[shoeSize] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment