Codeception + Reusable utility helper functions - codeception

I'd like to reuse a function that retrieves some info from the database. I am able to add it in the Helper class that Codeception builds and it works, but it feels like I may not be putting this function in the proper place because Codeception "reads" it out in the list of steps.
I want to have something like
$price = $I->getProductPriceFromDatabase($productIdentifier,$arg2,$arg3);
in the steps. This works but I end up with
I get product price from db 13,4,19,9,1
in the output. Is there a better way to set up this helper function so that it is not part of the "output"?

All methods of $I are steps and so they are printed in the steps output.
The only way to hide helper function is to call it from another helper function which looks better in the steps output.

Related

Pyhtml - Print the order in the order in which it is run

Have been working with pytest for sometime, (and really like it, I must say). I have been able to generate a self contained html with additional columns etc. What I need is either:
Have the results displayed in the order in which they are run (not Failed first as it normally appears in the self contained html output)
OR
Print the order in which the tests are run. Am using #pytest.mark.run(order=123456) in my tests.
The order is important as there are dependency tests that needs to be executed in a certain sequence.
I'am not sure about pytest, but I worked with pyhtml and had a similar problem.
I would say you shuld use a "yield" operator in the function you are calling from your pyhtml part. If you are calling the pytest function direct from your pyhtml part, you shuld be able to write a new function, that calls pytest for you.

Is it possible to add tags or have multiple BeforeTestRun hooks in Specflow

So I currently have an automation pack that I have created using Selenium/Specflow.
I wanted to know whether it is possible to have multiple BeforeTestRun hooks?
I've already tried: [BeforeTestRun("example1")] but I receive an error stating BeforeTestRunAttribute does not contain a constructor that takes 1 arguments
I tried the following but that also failed:
[BeforeTestRun]
[Scope(Tag = "example1")]
And referenced the above in the .feature file like this:
#example1
Scenario: This is an example
Given...
When...
Then...
Is there a way to implement this correctly such that in one .feature file I can have two scenarios that can use different [BeforeTestRun]?
If you cannot use [BeforeScenario] like suggested, you can try to manually check for tags using if statements. To get the current tags and compare them to the ones you need, try this:
var tags = ScenarioContext.ScenarioInfo.Tags;
if (tags.Any(x => x.Equals("MyTag")))
{
DoWork();
}
More info here: https://stackoverflow.com/a/42417623/9742876

Elixir - Call method on module by String-name

I'm pretty new to Elixir and functional programming-languages in general.
In Elixir, I want to call one specific function on Modules, given the Module name as String.
I've got the following (very bad) code working, which pretty much does what I want to:
module_name = elem(elem(Code.eval_file("module.ex", __DIR__), 0), 1)
apply(module_name, :helloWorld, [])
This (at least as I understand it) compiles the (already compiled) module of module.ex in the current directory. I'm extracting the modules name (not as a String, don't know what data-type it actually is) out of the two tuples and run the method helloWorld on it.
There are two problems with this code:
It prints a warning like redefining module Balance. I certainly don't want that to happen in production.
AFAIK this code compiles module.ex. But as module.ex is already compiled and loaded, it don't want that to happen.
I don't need to call methods on these modules by filename, the module-name would be ok too. But it does have to by dynamic, eg. entering "Book" at the command line should, after a check whether the module exists, call the function Book.helloWorld.
Thanks.
Well, thats where asking helps: You'll figure it out yourself the minute you ask. ;)
Just using apply(String.to_existing_atom("Elixir.Module"), :helloWorld, []) now. (maybe the name "Module" isn't allowed, don't know)
Note that you always need to prefix your modules with "Elixir."
defmodule Test do
def test(text) do
IO.puts("#{text}")
end
end
apply(String.to_existing_atom("Elixir.Test"), :test, ["test"])
prints "test"
and returns {:ok}
Here is a simple explanation:
Assuming that you have a module like this:
defmodule MyNamespace.Printer do
def print_hello(name) do
IO.puts("Hello, #{name}!")
end
end
Then you have a string that hold the module name that you can pass around in your application like this:
module_name = "Elixir.MyNamespace.Printer"
Whenever you receive the string module_name, you can instantiate a module and call functions on the module like this:
module = String.to_existing_atom(module_name)
module.print_hello("John")
It will print:
Hello, John!
Another way to dynamically call the function MyNamespace.Printer.print_hello/1 is:
print_hello_func = &module.print_hello/1
print_hello_func.("Jane")
It will print:
Hello, Jane!
Or if you want to have both module_name as atom and function_name as atom, and pass them around to be executed somewhere, you can write something like this:
a_module_name = :"Elixir.MyNamespace.Printer"
a_function_name = :print_hello
Then whenever you have a_module_name and a_function_name as atoms, you can call like this:
apply(a_module_name, a_function_name, ["Jackie"])
It will print
Hello, Jackie!
Of course you can pass module_name and function_name as strings and convert them to atoms later. Or you can pass module name as atom and function as a reference to function.
Also note that the name of a module is an atom so doing String.to_existing_atom isn't usually needed. Consider this code:
defmodule T do
def first([]), do: nil
def first([h|t]), do: h
end
In this case you can simply do the apply in this fashion:
apply(T,:first,[[1,2,3]])
#=> 1
Or this example (List below is the Elixir List module):
apply(List,:first,[[1,2,3]])
#=> 1
I mean to say that if you know the name of the module, it's not necessary to pass it as a string and then convert the string to an existing atom. Simply use the name without quotation marks.

Maximo - Adding elements to a CustomMboSet using scripting

Is it possible to add to a CustomMboSet in Maximo using scripting? I am writing a custom application using a custom object called TIMESHEET. As part of the application I am writing a (Jython) script that needs to dynamically build up an MboSet (a set of TIMESHEETs). The code retrieves an existing CustomMboSet and attempts to add elements to it. It works when using an out of box MboSet, but when I try to run the same code on a custom MboSet it does not seem to work. No error is thrown, but code below the offending line is not run.
In other words, this works (LABTRANS is an out of box MBO):
myMboSet = mbo.getMboSet("LABTRANS")
newMbo = myMboSet.add()
# Set attributes on newMbo, everything is happy
But this does not (TIMESHEET is a custom MBO):
myMboSet = mbo.getMboSet("TIMESHEET")
newMbo = myMboSet.add()
# Code does not execute after the above line
Anyone have any insight as to why I am seeing this behavior? Does the Maximo scripting framework simply not support the dynamic building up of CustomMboSets? Any help is appreciated. Thanks.
You need to make sure that the relationship exists between the Current MBO and the Custom MBO in the database configuration otherwise it will not work.
Alternatively you can use the following code to create an new mboSet on the fly:
timeSheetMboSet = mxServer.getMboSet("TIMESHEET", userInfo)
mbo.getMboSet(RELATIONSHIPNAME).
LABTRANS and TIMESHEET must be the relationship names to the object in auto script.
If you want to get/add records in any object, use
mxServer.getMboSet(OBJECTNAME, userInfo)
A bit more explanation. You can create your own custom relationship from within your automation script. The trick is to make sure it's not already existing. That's why I use a dollar sign for mine.
variable = mbo.getMboSet(tempRelationshipName,Object,where clause)
previousPhaseSet = mbo.getMboSet("$wophasetranstemp1", "exitdate is null")

Creating filters for auto_html

I want to create a custom filter for auto_html. Where do I put the filter so I can use it?
The documentation doesn't touch on any of that. Thanks!
The approach I took was to add the code to an initializer file such as:
/path/to/your/application/config/initializers/auto_html.rb
Then you can just write something like:
AutoHtml.add_filter(:change_colours).with({}) do |text, options|
text.gsub("#FF0000", "#00FF00")
end
And call auto_html(input) { change_colours } in your model. The empty hash will take any options you care to pass to the filter.