Cannot create new live template in RubyMine7.1.4 - ruby

I'm using rubymine 7.1.4 and I found that I could not create new live template. I tried to create the live template with the following steps
1. Go to Preferences -> Editors -> Live template
2. I select the "user" group and click the "+" icon in the top-right corner, then select "1. Live template"
3. I fill in the "Abbreviation" field with mmfd and "Description field with "method_missing for decorators", then the "Template text" field with
def method_missing?(method_name, *args, &block)
#tweet.send(method_name, *args, &block)
end
def respond_to_missing?(method_name, include_private=false)
#tweet.respond_to?(method_name, include_private=false) || super
end
I click the "Define" and select Ruby as the context. Then I click the OK button.
Then I went to a ruby file editor and type the abbreviation "mmfd", and nothing happened.
I reopen the "live template" preference page and the template I created was gone.
I also tried select the code in the editor and then perform "Save as live template", fill in the abbreviation, and this way does not work neither.

Related

How to get content from field

I'm totally new to Base. I have different forms but in one named F_STRUCT of them I'm trying to make a macro which will allow the user to autofill another field when he select a zipcode.
so the database looks like this.
ID_ZIP ZIP CITY
1 97425 Les Avirons
2 82289 Toto
In my forms, I have a select which allows to select the ZIP code. It's label and name is ZipCode.
So I don't really know where to find the API reference for all the methods and chill methods, I followed examples from internet.
I tried this
Sub getZip
Dim Doc As Object
Dim DrawPage As Object
Dim Form As Object
Doc = StarDesktop.CurrentComponent
DrawPage = Doc.DrawPage
Form = DrawPage.Forms.GetByIndex(0)
Toto = Form.GetByName("ZipCode")
Print "hey"
End Sub
But it returns an error on the Toto = Form.GetByName("ZipCode") line.
The code works, so the problem must be how you created the form or control. Follow these instructions to set up a correct example:
Create Form in Design View
Use the List Box tool (is that what you mean by "select"?) and create a control.
Cancel out of the wizard if it pops up.
Right-click on the control and select Control Properties (not Name, which would modify the shape name instead of the control's name).
Set the Name to "ZipCode" (without quotes).
Save and close the form.
Open the form. In the window of that form (the CurrentComponent) go to Tools -> Macros -> Run Macro.
A list of documentation links for Base is at https://ask.libreoffice.org/en/question/80972/to-learn-libreoffice-base-are-there-introductions-or-tutorials/?answer=80973#post-id-80973.

How can I iterate through an array of links and check information on the page to which each refers?

I have a page that lists job openings at my company. I want to use Capybara tests to click on each of the links and determine if the target page contains certain content.
I have the step below. The next step in the process checks for the content on the new page.
When("I click on each job title") do
page.all('.job-box').each do |item|
within(item) do
find('a').click
end
end
end
Once the first link is clicked the browser goes to a different page. At that point, I would like to check the content on that page, then return to the previous step to check the next link. What actually happens is that the code clicks the first link, and then attempts to click the second link. Since the first link sent it to another page, the second link is no longer present, so it returns a stale element error.
Obviously, I need a way to deal with multiple pages before continuing with the next step in the iteration, but I haven't found any documentation that addresses that problem.
You probably want to use page.go_back (or page.driver.go_back depending on the driver you're using). Something like this:
When("I click on each job title") do
page.all('.job-box').each do |item|
within(item) do
find('a').click
# do stuff
end
# roll back (granting you went but one click away)
page.go_back
end
end
As you've recognized the issue here is that the elements are stale when you return to the previous page. Depending on what limitations you're willing to accept there are multiple ways to deal with this. The bigger issue you have is that you're doing this in Cucumber which really doesn't have support for scoping/looping in its test structure. If you're willing for this to only work on a specific browser/platform you can use the respective key modifiers on click to have the browser open a new tab for each job entry and then your next step could run through all the open tabs checking those
When("I click on each job title") do
page.all('.job-box').each do |item|
item.find('a').click(:alt, :cmd) # alt,cmd click in Chrome MacOS opens in new tab
end
end
But really you're going to be better off doing something like
When("I click on each job title and verify info") do
page.all('.job-box').each do |item|
window = page.window_opened_by do
item.find('a').click(:alt, :cmd)
end
page.within_window(window) do
# verify whatever needs to be verified
end
window.close
end
end
Thomas Walpole's answer got me close enough to figure it out. Here is what ended up working:
When("I click on each job title and verify info") do
page.all('.job-box').each do |item|
new_window = window_opened_by do
url = item.find('a')[:href]
within_window open_new_window do
visit url
end
end
page.within_window(new_window) do
# do stuff
end
end
end
It doesn't close each new tab after it checks it, which could be a problem if you are working with a lot of links. I only have about 15, so it wasn't an issue for me. They all closed when the browser closed after the test finished.

How to click on a button that can only be identified by a custom attribute?

I'm just getting into automated testing and I've been writing some code for a fake site that a friend set up for me for testing. The test I'm writing is meant to click on an "Add to Cart" button, however each of the button have the same exact class and the only way to really identify them is through the custom attributes.
This is the code for the button i'm trying to click
<a class="btn btn-success btn-block addItem" data-id="1" data-name="Chocolate Cups" data-price="1.00">Add to Cart</a>
(I'm trying to click on the button by using the data-id attribute)
Each of the buttons have the same class so they can't be identified that way otherwise an error pops up saying that the result is "Ambiguous" and thus can't do it.
I used the code below and managed to identify a specific button however I'm not sure how I would now click the button.
Given("I'm on the sweets list page") do
visit("https://sweetshop.netlify.com/sweets.html")
end
When("I click {string} button") do |string|
page.should have_css("*[data-id='1']")
end
Then("add the item to cart") do
end
You can try something like:
Then("add the item to cart") do
find(:css, "*[data-id='1']").click
end
or
Then("add the item to cart") do
find(:xpath, "//*[#data-id='1']").click
end
Similar post: Cucumber/Capybara Selecting Button from Specific Class?

How can I tell which project I'm using in Sublime Text?

I often have multiple copies of the same Git repository on my machine. I usually have multiple Sublime Text windows open, each with the opened project for one of the Git repo copies.
Is there any setting that will show the project file's path on the status or title bar, or some other way of easily distinguishing otherwise similar projects from each other? As it is, I have no easy way of distinguishing which Sublime Text window is using which project file.
The title bar of Sublime will show you the file name portion of the project currently associated with a window by default; it's the text to the right of the name of the currently selected file inside round brackets. For example, here I have the OverrideAudit project currently open:
There's no way (currently) to display other information in the caption bar, but using some plugin code you can display text in the status bar instead.
[Edit] There is an open feature request on the issue tracker to add the ability to configure the title bar which you may want to weigh in on. [/Edit]
Here is an example of a plugin that replicates putting the project name from the window caption into the status bar. If desired you could modify the code in show_project that isolates only the project name to e.g. include the path if desired.
To use this, you can select Tools > Developer > New Plugin... from the menu and replace the default stub with this code, modifying as needed.
This code is also available on GitHub.
import sublime
import sublime_plugin
import os
# Related Reading:
# https://forum.sublimetext.com/t/displaying-project-name-on-the-rite-side-of-the-status-bar/24721
# This just displays the filename portion of the current project file in the
# status bar, which is the same text that appears by default in the window
# caption.
def plugin_loaded ():
"""
Ensure that all views in all windows show the associated project at startup.
"""
# Show project in all views of all windows
for window in sublime.windows ():
for view in window.views ():
show_project (view)
def show_project(view):
"""
If a project file is in use, add the name of it to the start of the status
bar.
"""
if view.window() is None:
return
project_file = view.window ().project_file_name ()
if project_file is not None:
project_name = os.path.splitext (os.path.basename (project_file))[0]
view.set_status ("00ProjectName", "[" + project_name + "]")
class ProjectInStatusbar(sublime_plugin.EventListener):
"""
Display the name of the current project in the status bar.
"""
def on_new(self, view):
show_project (view)
def on_load(self, view):
show_project (view)
def on_clone(self, view):
show_project (view)

How to handle windows pop up in IE using Ruby

Please help me how to handle this pop ups.
Based on your last question, I assume you are using Watir-Classic (even though you have also listed Watir-Webdriver).
As #orde mentioned in the comments, Watir has an Alert class for handling these types of dialogs. Unfortunately, in terms of clicking buttons, Watir-Classic only has an #ok method defined:
# Press the "OK" button on the JavaScript dialog.
def ok
dialog.button(:value => "OK").click
wait_until_not_exists
end
This will not work for this dialog as there is a "Yes" and "No" button rather than an "OK" button. You will need to duplicate this functionality with the right value.
Note that the dialog is a RAutomation window and no longer Watir specific code. As a result, the button values are not always intuitive - it is not always just the text you see. To get the right values, you should ask the dialog what values it sees:
browser.alert.send(:dialog).buttons.map(&:value)
#=> ["&Yes", "&No"]
We can then make the same calls as the #ok method, but with the correct value:
alert = browser.alert
alert.send(:dialog).button(:value => '&Yes').click
alert.wait_while_present
This code is working fine to handle this type of pop ups:
save_dialog = WIN32OLE.new("AutoItX3.Control") save_dialog.ControlClick("Windows Internet Explorer", "Yes", "[CLASS:Button;INSTANCE:1]")

Resources