Selecting a field in Protractor - protractor

<hs-details-item>
<hs-label>Location</hs-label>
<hs-value-block>
<hs>
<hs-text-box ng-class="{'disabled': isAmenityPosting }" class="required" input-control="{title:'Location', okCallback:setJobSite, value:jobSiteName,
autocomplete:{ values:getJobSiteList, reload: true }, ss:'location'}">
<i class="icon-room"></i><span hs-placeholder="Select Location" class="ng-binding"></span>
</hs-text-box>
</hs>
<hs>
<!-- ngIf: isBarcodeShow() --><hs-button ng-class="{'disabled': soCreating }" class="barcode-special-btn smaller ng-scope" ng-if="isBarcodeShow()" hs-gesture="{handler:startScan, param: onBarcodeScanCompleted}"><i class="icon-br-code"></i></hs-button><!-- end ngIf: isBarcodeShow() -->
</hs>
</hs-value-block>
</hs-details-item>
Scenario: click on “Location” field...
What would be the best way to come up with a command in Protractor to select "location" field from the above Snippet Code?
Can it be done by not using Xpath?

Multiple options here. A sort of a non-welcomed, but short and readable way, would be to use an XPath expression and check the preceding label:
var locationTextBox = element(by.xpath("//hs-label[. = 'Location']/following::hs-text-box"));
locationTextBox.click();

Related

bg-url in tailwindcss is not working for me

i get some problem that when i use add to extend / use as arbitary values ->> bg-url is not working
\Arbirtary Values
bg-[url('../../images/product/model-s.jpg')]
-- Module not found: Error: Can't resolve '../../images/product/model-s.jpg' in '....\MAIN PROJECT\0.PORTOFOLIO\tesla-clone\client\src' --
\Extend
backgroundImage: {"model-s": "url('./src/images/product/model-s.jpg')", },
-- Module not found: Error: Can't resolve './src/images/product/model-s.jpg' in ''....\MAIN PROJECT\0.PORTOFOLIO\tesla-clone\client\src' --
### BUT.......
when i import it i can use it as <img />
import models from "../../images/product/model-s.jpg";
<img src={models} alt="model S" className="w-full h-full object-cover bg-center bg-no-repeat" />
Can you help me ? please....
Here you have making the mistake while using the image in component. Since you already defined the image in tailwind.config.js like
.
.
extend: {
backgroundImage: {
'model_s': "url('./src/images/product/model-s.jpg')"
}
}
.
.
You can simply use it like
<div className="bg-model_s" ></div>
Note : I had change the name from model-s to model_s

Protractor css locator for md-select

I'm new to protractor and need to know how can i get the text i.e. Connections in the below code block. I need to click this "Connections". Anyhelp would be really appreciated. Thanks in advance
<md-option ng-repeat="worksite in vmSplashController.worksites track by $index" id="option_worksite_TRANSFER" ng-value="worksite" tabindex="0" class="ng-scope" role="option" aria-selected="false" value="[object Object]">
<div class="md-text ng-binding">
Connections
</div>
</md-option>
Full code
<md-dialog ng-cloak aria-span="" id="splashDialog" class="asui-popup-container splashContainer">
<form name="splash">
<md-dialog-content class="agentDetails" flex>
</md-dialog-content>
<md-dialog-content class="agentOptions" flex layout="row">
<md-input-container class="md-input-has-placeholder" id="nav_worksite" ng-if="vmSplashController.worksites.length >= 1" flex="50" layout="column">
<label class="select-lable">Worksite</label>
<md-select md-no-ink name="nav_worksite" required ng-model="vmSplashController.worksites.selected" ng-model-options="{trackBy: '$value.locationCode'}" aria-label="Select Worksite" md-container-class="md-select-custom nav-worksite-selectbox" ng-change="vmSplashController.onWorksiteChange(vmSplashController.worksites.selected)">
<md-option ng-repeat="worksite in vmSplashController.worksites track by $index" id="option_worksite_{{worksite.locationCode}}" ng-value="worksite">
{{**Here that Div is being created i.e. Connections along with other two options**}}
</md-option>
</md-select>
</md-input-container>
</md-dialog-content>
<md-dialog-actions layout="row">
<md-button md-no-ink class="md-primary nobg-btn" ng-click="vmSplashController.onConfirm()" ng-disabled="splash.$invalid">
CONFIRM
</md-button>
</md-dialog-actions>
</form>
</md-dialog>
I treid this
element(by.cssContainingText('.option_worksite_TRANSFER > div.md-text', 'Connections')).click();
but getting the below error.
Message:
Failed: No element found using locator: by.cssContainingText(".option_worksite_TRANSFER > div.md-text", "Connections")
First - I'm a bit confused. In example you are trying to select class option_worksite_TRANSFER, but in error message it has an id.
If you are trying to select value from dropdown, try this solution:
https://stackoverflow.com/a/39047319/6331748
Try this using xpath:
element(by.xpath("//div[text()='Connections']")).click();
Try using the below code:
element(by.cssContainingText('[id^="option_worksite"] > div.md-text', 'Connections')).click();
Adding waits:
var EC = protractor.ExpectedConditions;
var ele = element(by.cssContainingText('[id^="option_worksite"] > div.md-text', 'Connections'));
browser.wait(EC.visibilityOf(ele), 5000).then(function(){
ele.click();
});

Pulling Data from Google spreadsheet

I am having difficulty pulling data from Google spreadsheet
I have added following gem files
gem 'roo'
gem 'google_drive'
gem 'google-spreadsheet-ruby'
My jobs file is
require 'roo'
require 'rubygems'
def fetch_spreadsheet_data()
google_user = "MY EMAIL ADDRESS"
google_password = "MY PASSWORD"
workbook = Roo::Google.new("https://docs.google.com/spreadsheet/ccc?key=1hdwnrDsuJId1FLE0yWICYP1HGqYNu2NHH2IcoPyAzOQ#gid=0",user: google_user, password: google_password)
send_event('catchup_data', {current: s.cell('B',2) })
send_event('Bounced_back', {current: s.cell('B',3) )
end
SCHEDULER.every '5m' do
fetch_spreadsheet_data()
end
My dashboard.erb file has following html
<li data-row="2" data-col="3" data-sizex="1" data-sizey="1">
<div data-id="bounce_back" data-view="Number" data-title="Triage - Work in Progress" style="background-color:#5AC352;"></div>
</li>
<li data-row="2" data-col="4" data-sizex="1" data-sizey="1">
<div data-id="catchup_data" data-view="Number" data-title="Squad catchup sessions last month" style="background-color:#DBA901;"></div>
</li>
Not sure what am I missing that the data is not coming through. Can anyone please help me?
There are a few things wrong that I can see:
You're sending 'Bounced_back' but binding to the id of 'bounce_back'
You are trying to get the cell data from 's' but 's' is undefined
Looking at the Roo docs, I believe you have copied 's' from there. Just above that, they use sheet instead so I believe you have to grab the sheet from the workbook before using it.
I googled a bit and found this: http://etzelstorfer.com/en/dashing-graph-from-google-spreadsheet/
In summary, this should work for you:
def fetch_spreadsheet_data()
google_user = "MY EMAIL ADDRESS"
google_password = "MY PASSWORD"
workbook = Roo::Google.new("https://docs.google.com/spreadsheet/ccc?key=1hdwnrDsuJId1FLE0yWICYP1HGqYNu2NHH2IcoPyAzOQ#gid=0",user: google_user, password: google_password)
s = workbook.sheets[0] # assuming first sheet in workbook
send_event('catchup_data', {current: s.cell('B',2) })
send_event('bounce_back', {current: s.cell('B',3) )
end
SCHEDULER.every '5m' do
fetch_spreadsheet_data()
end

Capybara choose method Unable to find radio button

I have a form which is generated by simple form:
TL TR
<div class="form-group radio_buttons required user_register_temp_package">
<label class="radio_buttons required control-label">
<abbr title="zorunlu">
*
</abbr>
Paket
</label>
<label class="radio">
<input class="radio_buttons required" id="user_register_temp_attributes_domain_package_id_1" name="user[register_temp_attributes][domain_package_id]" type="radio" value="1">
Small
</label>
<label class="radio">
<input checked="checked" class="radio_buttons required" id="user_register_temp_attributes_domain_package_id_2" name="user[register_temp_attributes][domain_package_id]" type="radio" value="2">
Medium
</label>
<label class="radio">
<input class="radio_buttons required" id="user_register_temp_attributes_domain_package_id_3" name="user[register_temp_attributes][domain_package_id]" type="radio" value="3">
Large
</label>
</div>
TL TR
I have a simple spec like this:
# encoding: UTF-8
require 'spec_helper'
feature 'Register' do
background do
visit new_user_registration_path
end
scenario 'fill register form and register' do
# TL TR
choose('user_register_temp_attributes_domain_package_id_1')
# TL TR
end
end
My spec_helper.rb is
ENV['RAILS_ENV'] ||= 'test'
require File
.expand_path('../../config/environment', __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rspec'
Capybara.javascript_driver = :webkit
Capybara.default_selector = :css
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
RSpec.configure do |config|
# ## Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = 'random'
# Capybara DSL
config.include Capybara::DSL
# Factory girl
config.include FactoryGirl::Syntax::Methods
end
The Capybara API for the choose method says:
"Find a radio button and mark it as checked. The radio button can be found via name, id or label text."
But when I run spec with choose('user_register_temp_attributes_domain_package_id_1'), I get
Capybara::ElementNotFound: Unable to find radio button "user_register_temp_attributes_domain_package_id_1"
I've tried code below but got Capybara::ElementNotFound: Unable to find css "user_register_temp_attributes_domain_package_id_1" error:
find('#user_register_temp_attributes_domain_package_id_1[value=1]').set(true)
It seems there is no problem with fill_in, check or click_button methods.
Regards.
Most likely underlying driver thinks that this radio button is invisible. By default Capybara finds only visible elements (as Capybara.ignore_hidden_elements is true by default) so it didn't find that element.
Try:
choose('user_register_temp_attributes_domain_package_id_1', visible: false)
You can improve error message by submitting a pull request to Capybara.

Grails Form Select Options

The "select" form component in grails can have the form:
<g:select name="user.age" from="${0..59}" value="${age}" noSelection="['':'-All-']"/>
But if I need to add other options aside from the numbers, how would I do that (example options are: 0..59, All, "/5", "/10", etc,...)
Thanks
<g:select from="${(0..59) + [ "All", "/5", "/10"]}" ... />
how about this?