Can I record video without using junit? - cucumber

Good day!
Can I record video without using junit? I use cucumber
public static target BrowserWebDriverContainer <?> container = new BrowserWebDriverContainer <> () .withCapabilities (en.sbtqa.tag.pagefactory.drivers.Capabilities.getFirefoxOptions ())
.withRecordingMode (VncRecordingMode.RECORD_ALL, new file ("target"), VncRecordingFormat.MP4) .withStartupTimeout (Duration.ofMinutes (2)). withNetwork (Network.newNetwork ());
container.start();
use cucumber.api.java.Before

You don't have to use JUnit integration with Testcontainers.
Testcontainers allows you to control lifecycle of the containers manually if you want: https://www.testcontainers.org/test_framework_integration/manual_lifecycle_control/
You need to create the container:
public static BrowserWebDriverContainer <?> container = new BrowserWebDriverContainer<>()
.withCapabilities (en.sbtqa.tag.pagefactory.drivers.Capabilities.getFirefoxOptions())
.withRecordingMode (VncRecordingMode.RECORD_ALL, new File("target"), VncRecordingFormat.MP4)
.withStartupTimeout(Duration.ofMinutes(2))
.withNetwork(Network.newNetwork());
Then start it:
container.start();
You can also manually stop the container using container.stop(),
But you don't have to stop the container yourself, by default it'll be stopped after the JVM process finishes.

Related

Magnolia Groovy Access Taskmanager

I'd like to access the taskmanager in Magnolia CMS from within a Groovy script. Reason is to archive old tasks in the system (half automatically).
What I tried is something like this:
import info.magnolia.task.*
import info.magnolia.jcr.predicate.NodeTypePredicate;
import info.magnolia.importexport.DataTransporter
repository = "tasks"
nodeType = "mgnl:task"
session = ctx.getJCRSession(repository)
collection = NodeUtil.collectAllChildren(session.getRootNode(), new NodeTypePredicate(nodeType))
collection.each { node->
println(node)
println(node.name)
taskManager.archiveTask(node.name);
println "node done"
}
But taskmanager is of course not known. How can I get access to it using Groovy?
All the components such as managers, registries and others are usually injected and available in Magnolia via guice containers.
Either you can turn your script to class and let guice instantiate it for you or you can use shortcut to get the instance of component you want from guice container like:
tasksManager = Components.getComponent(TasksManager.class)

Windsor Castle Equivalent of Autofac's IStartable

I'd like to be able to implement this in my windsor castle container set up:
"For all types that implement IStartable in the current assembly register them and run the Start method for them."
Similar to what you can do using Autofac for things like registering Automapper mappings. eg
public class MyBlahViewModelMapper : IStartable
{
public void Start()
{
Mapper.CreateMap<MyBlahEntity, MyBlahViewModel>();
}
}
Autofac does it automagically.... I'm thinking Windsor can't help me here?
Windsor has its own IStartable interface. If you want Windsor to register your objects and create/run them immediately after that you'd use Startable Facility for that.
To clarify, there are two concepts here:
IStartable interface, which provides Start and Stop methods. This is a lifecycle interfaces that provide lifecycle callbacks: Start being called right after a component instance gets created (after the constructor runs)
Startable Facility, which forces your IStartable components to be instantiated and started immediately after installers have ran.
Here's what the code would look like:
container.AddFacility<StartableFacility>(f => f.DeferredStart());
container.Install(FromAssembly.This());
// by here all startable are started
If you're on Windsor 3.3 or later you can also manually trigger the startables to start (which is useful if you need to do some extra setup for them)
var flag = new StartFlag();
container.AddFacility<StartableFacility>(f => f.DeferredStart(flag));
container.Install(FromAssembly.This());
// do whatever else set up your app needs
// when ready, signal the flag
flag.Signal();
// by here all startable are started
The closest is Castle Windows Installers - they can trivially scanned from an assembly and installed (or 'started'). Installers are usually used to register components, but they can be used for other initialization as well.
Windsor uses installers (that is types implementing IWindsorInstaller interface) to encapsulate and partition your registration logic .. FromAssembly [makes] working with installers a breeze.
After creating an installer use one of the fluent configurations in the main IoC bootstrap, eg:
container.Install(
FromAssembly.This());
Note that the order is unspecified; installers that must occur in an order must be specified with an explicit order to Install, possibly through a modified assembly reflector.

Jenkins Script to Restrict all builds to a given node

We've recently added a second slave node to our Jenkins build environment running a different OS (Linux instead of Windows) for specific builds. Unsurprisingly, this means we need to restrict builds via the "Restrict where this project can be run" setting. However we have a lot of builds (100+) so the prospect of clicking through them all to change this setting manually isn't thrilling me.
Can someone provide a groovy script to achieve this via the Jenkins script console? I've used similar scripts in the past for changing other settings but I can't find any reference for this particular setting.
Managed to figure out the script for myself based on previous scripts and the Jenkins source. Script is as follows:
import hudson.model.*
import hudson.model.labels.*
import hudson.maven.*
import hudson.tasks.*
import hudson.plugins.git.*
hudsonInstance = hudson.model.Hudson.instance
allItems = hudsonInstance.allItems
buildableItems = allItems.findAll{ job -> job instanceof BuildableItemWithBuildWrappers }
buildableItems.each { item ->
boolean shouldSave = false
item.allJobs.each { job ->
job.assignedLabel = new LabelAtom('windows-x86')
}
}
Replace 'windows-x86' with whatever your node label needs to be. You could also do conditional changes based on item.name to filter out some jobs, if necessary.
You could try the Jenkins Job-DSL plugin
which would allow you to create a job to alter your other jobs. This works by providing a build step in a groovy based DSL to modify other jobs.
This one here would add a label to the job 'xxxx'. I've cheated a bit by using the job itself as a template.
job{
using 'xxxx'
name 'xxxx'
label 'Linux'
}
You might need to adjust it if some of you jobs are different types

Nashorn : how to evaluate scripts in scripting mode

Im starting to explore jdk 8 new javascript engine nashorn and wanted to build some automating task scripts. I ve an issue, ive no idea how to evaluate a js file in scripting mode from javascript, using engine.eval() eg .
p.s: im not talking about jjs -scripting which is good but only works one way. I want the other way; make the engine evaluate in scripting mode from java
The easiest way is to add -Dnashorn.args=-scripting to you java command line.
After a lot of head scratching, i came up with a trick where i can actually launch my script's execution through a command line from a hand crafted System Process :
//tricking the nashorn engine with jjs command
public void evalScriptInScriptingMode(String fileName)
{
String[] args = new String[]{"jjs", "-scripting", fileName};
//This class is used to create operating system processes
ProcessBuilder pb = new ProcessBuilder(args);
pb.directory(null);
File log = new File("jjs_log.txt");
int i = 0;
while(log.exists())
{
i++;
log = new File("jjs" + i + "_log.txt");
}
pb.redirectErrorStream(true);
pb.redirectOutput(ProcessBuilder.Redirect.appendTo(log));
Process p = null;
try
{
p = pb.start(); //start the process which remains open
}
catch(IOException e)
{
e.printStackTrace();
}
}
You can pass arguments to the script engine via the NashornScriptEngineFactory.
import jdk.nashorn.api.scripting.NashornScriptEngineFactory
new NashornScriptEngineFactory()
.getScriptEngine( "-scripting" )
.eval( "" );
You can also use new NashornScriptEngineFactory().getScriptEngine("-scripting"); which will retrieve a new Nashorn ScriptEngine in scripting mode. This method is slightly better than using a System Process mainly because this automatically adds you classes to the nashorn classpath.
Basically, you can program classes in java and then use'em in javascript. If you do not need to be able to reference your classes in javascript then the System Process should do just fine and there won't be problems, ( if the machine on which this is running has jjs in their classpath )

Using Camel Processor as custom component

I want to make a custom camel processor to behave as a custom component.I read it as it as possible from http://camel.apache.org/processor.html - section--> Turning your processor into a full component.
Here the Custom Processor created will have to do the job when i call
someComponent://action1?param1=value1&param2=value2
in the route.
For this i created a sample component using maven catalog.This created Endpoint,Consumer, Producer and Component classes.
The link says that the component should return ProcessorEndpoint which i have done.
So, Endpoint looks as below
public class SampleEndpoint extends ProcessorEndpoint{
// Automatically Generated code begins
public Producer createProducer() throws Exception{
return new SampleProducer(this, processor);
}
public Consumer createConsumer() throws Exception{
throw new UnsupportedOperationException("This operation is not permitted....");
}
// Automatically generated code ends here
//added below to make custom processor work for custom component
public Processor createProcessor(Processor processor){
return new SampleProcessor();
}
}
But, here the code in the processor is not getting executed instead the code in the SampleProducer gets executed.
Here i want the processor to be excuted.How do i do that?
When extending ProcessorEndpoint, the Producer from createProducer() will handle the exchange, i.e. Producer.process(Exchange exchange).
This is why you are seeing SampleProducer being used. But if you wanted to delegate to a processor, you could probably just change your code to be:
return new SampleProducer(this, new SampleProcessor());
My best advice would be to attach a debugger and put breakpoints in your SampleEndpoint, SampleProducer and SampleProcessor methods to see what gets called and when.

Resources