Skip to content

Move an update locators examples for ruby #1773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 58 additions & 2 deletions examples/ruby/spec/elements/locators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,62 @@

require 'spec_helper'

RSpec.describe 'Element Locators' do
let(:driver) { start_session }
RSpec.describe 'Element Locators', skip: 'These are reference following the documentation example' do
it 'finds element by class name' do
driver.find_element(class: 'information')
end

it 'finds element by css selector' do
driver.find_element(css: '#fname')
end

it 'finds element by id' do
driver.find_element(id: 'lname')
end

it 'find element by name' do
driver.find_element(name: 'newsletter')
end

it 'finds element by link text' do
driver.find_element(link_text: 'Selenium Official Page')
end

it 'finds element by partial link text' do
driver.find_element(partial_link_text: 'Official Page')
end

it 'finds element by tag name' do
driver.find_element(tag_name: 'a')
end

it 'finds element by xpath' do
driver.find_element(xpath: "//input[@value='f']")
end

context 'with relative locators' do
it 'finds element above' do
driver.find_element({relative: {tag_name: 'input', above: {id: 'password'}}})
end

it 'finds element below' do
driver.find_element({relative: {tag_name: 'input', below: {id: 'email'}}})
end

it 'finds element to the left' do
driver.find_element({relative: {tag_name: 'button', left: {id: 'submit'}}})
end

it 'finds element to the right' do
driver.find_element({relative: {tag_name: 'button', right: {id: 'cancel'}}})
end

it 'finds near element' do
driver.find_element({relative: {tag_name: 'input', near: {id: 'lbl-email'}}})
end

it 'chains relative locators' do
driver.find_element({relative: {tag_name: 'button', below: {id: 'email'}, right: {id: 'cancel'}}})
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,8 @@ available in Selenium.
var driver = new ChromeDriver();
driver.FindElement(By.ClassName("information"));
{{< /tab >}}
{{< tab header="Ruby" >}}
driver = Selenium::WebDriver.for :chrome
driver.find_element(class: 'information')
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L7" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let driver = await new Builder().forBrowser('chrome').build();
Expand Down Expand Up @@ -123,10 +122,9 @@ textbox, using css.
var driver = new ChromeDriver();
driver.FindElement(By.CssSelector("#fname"));
{{< /tab >}}
{{< tab header="Ruby" >}}
driver = Selenium::WebDriver.for :chrome
driver.find_element(css: '#fname')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L11" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let driver = await new Builder().forBrowser('chrome').build();
const loc = await driver.findElement(By.css('#fname'));
Expand Down Expand Up @@ -156,10 +154,9 @@ We will identify the Last Name field using it.
var driver = new ChromeDriver();
driver.FindElement(By.Id("lname"));
{{< /tab >}}
{{< tab header="Ruby" >}}
driver = Selenium::WebDriver.for :chrome
driver.find_element(id: 'lname')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L15" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let driver = await new Builder().forBrowser('chrome').build();
const loc = await driver.findElement(By.id('lname'));
Expand Down Expand Up @@ -190,10 +187,9 @@ We will identify the Newsletter checkbox using it.
var driver = new ChromeDriver();
driver.FindElement(By.Name("newsletter"));
{{< /tab >}}
{{< tab header="Ruby" >}}
driver = Selenium::WebDriver.for :chrome
driver.find_element(name: 'newsletter')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L19" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let driver = await new Builder().forBrowser('chrome').build();
const loc = await driver.findElement(By.name('newsletter'));
Expand Down Expand Up @@ -222,10 +218,9 @@ In the HTML snippet shared, we have a link available, let's see how will we loca
var driver = new ChromeDriver();
driver.FindElement(By.LinkText("Selenium Official Page"));
{{< /tab >}}
{{< tab header="Ruby" >}}
driver = Selenium::WebDriver.for :chrome
driver.find_element(link_text: 'Selenium Official Page')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L23" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let driver = await new Builder().forBrowser('chrome').build();
const loc = await driver.findElement(By.linkText('Selenium Official Page'));
Expand Down Expand Up @@ -255,10 +250,9 @@ In the HTML snippet shared, we have a link available, lets see how will we locat
var driver = new ChromeDriver();
driver.FindElement(By.PartialLinkText("Official Page"));
{{< /tab >}}
{{< tab header="Ruby" >}}
driver = Selenium::WebDriver.for :chrome
driver.find_element(partial_link_text: 'Official Page')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L27" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let driver = await new Builder().forBrowser('chrome').build();
const loc = await driver.findElement(By.partialLinkText('Official Page'));
Expand Down Expand Up @@ -286,10 +280,9 @@ From the above HTML snippet shared, lets identify the link, using its html tag "
var driver = new ChromeDriver();
driver.FindElement(By.TagName("a"));
{{< /tab >}}
{{< tab header="Ruby" >}}
driver = Selenium::WebDriver.for :chrome
driver.find_element(tag_name: 'a')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L31" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let driver = await new Builder().forBrowser('chrome').build();
const loc = await driver.findElement(By.tagName('a'));
Expand Down Expand Up @@ -323,10 +316,9 @@ first name text box. Let us create locator for female radio button using xpath.
var driver = new ChromeDriver();
driver.FindElement(By.Xpath("//input[@value='f']"));
{{< /tab >}}
{{< tab header="Ruby" >}}
driver = Selenium::WebDriver.for :chrome
driver.find_element(xpath: '//input[@value='f']')
{{< /tab >}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L35" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let driver = await new Builder().forBrowser('chrome').build();
const loc = await driver.findElement(By.xpath('//input[@value='f']'));
Expand Down Expand Up @@ -377,8 +369,8 @@ email_locator = locate_with(By.TAG_NAME, "input").above({By.ID: "password"})
{{< tab header="CSharp" >}}
var emailLocator = RelativeBy.WithLocator(By.TagName("input")).Above(By.Id("password"));
{{< /tab >}}
{{< tab header="Ruby" >}}
email_locator = {relative: {tag_name: 'input', above: {id: 'password'}}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L40" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let emailLocator = locateWith(By.tagName('input')).above(By.id('password'));
Expand All @@ -404,8 +396,8 @@ password_locator = locate_with(By.TAG_NAME, "input").below({By.ID: "email"})
{{< tab header="CSharp" >}}
var passwordLocator = RelativeBy.WithLocator(By.TagName("input")).Below(By.Id("email"));
{{< /tab >}}
{{< tab header="Ruby" >}}
password_locator = {relative: {tag_name: 'input', below: {id: 'email'}}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L44" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let passwordLocator = locateWith(By.tagName('input')).below(By.id('email'));
Expand All @@ -431,8 +423,8 @@ cancel_locator = locate_with(By.TAG_NAME, "button").to_left_of({By.ID: "submit"}
{{< tab header="CSharp" >}}
var cancelLocator = RelativeBy.WithLocator(By.tagName("button")).LeftOf(By.Id("submit"));
{{< /tab >}}
{{< tab header="Ruby" >}}
cancel_locator = {relative: {tag_name: 'button', left: {id: 'submit'}}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L48" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let cancelLocator = locateWith(By.tagName('button')).toLeftOf(By.id('submit'));
Expand All @@ -458,8 +450,8 @@ submit_locator = locate_with(By.TAG_NAME, "button").to_right_of({By.ID: "cancel"
{{< tab header="CSharp" >}}
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).RightOf(By.Id("cancel"));
{{< /tab >}}
{{< tab header="Ruby" >}}
submit_locator = {relative: {tag_name: 'button', right: {id: 'cancel'}}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L52" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let submitLocator = locateWith(By.tagName('button')).toRightOf(By.id('cancel'));
Expand Down Expand Up @@ -487,8 +479,8 @@ email_locator = locate_with(By.TAG_NAME, "input").near({By.ID: "lbl-email"})
{{< tab header="CSharp" >}}
var emailLocator = RelativeBy.WithLocator(By.tagName("input")).Near(By.Id("lbl-email"));
{{< /tab >}}
{{< tab header="Ruby" >}}
email_locator = {relative: {tag_name: 'input', near: {id: 'lbl-email'}}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L56" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let emailLocator = locateWith(By.tagName('input')).near(By.id('lbl-email'));
Expand All @@ -513,8 +505,8 @@ submit_locator = locate_with(By.TAG_NAME, "button").below({By.ID: "email"}).to_r
{{< tab header="CSharp" >}}
var submitLocator = RelativeBy.WithLocator(By.tagName("button")).Below(By.Id("email")).RightOf(By.Id("cancel"));
{{< /tab >}}
{{< tab header="Ruby" >}}
submit_locator = {relative: {tag_name: 'button', below: {id: 'email'}, right: {id: 'cancel'}}}
{{< tab header="Ruby" text=true >}}
{{< gh-codeblock path="examples/ruby/spec/elements/locators_spec.rb#L60" >}}
{{< /tab >}}
{{< tab header="JavaScript" >}}
let submitLocator = locateWith(By.tagName('button')).below(By.id('email')).toRightOf(By.id('cancel'));
Expand Down
Loading
Loading