watirgrid and sikuli - can they play together? - jruby

I was wondering if watirgrid / gridinit could be used in conjunction with Sikuli. http://www.sikuli.org
I've had some success integrating Sikuli with watir-webdriver and cucumber following the examples in
http://www.software-testing.com.au/blog/2010/08/16/automating-flash-ajax-popups-and-more-using-ruby-watir-and-sikuli
It's all being done from Jruby.
The next step for me was to see if I could use watirgrid to send sikuli commands, but I haven't had success thus far.
I followed the example in http://altentee.com/blogs/2010/watirgrid-support-for-watir-webdriver/
what I entered:
irb
require 'watirgrid'
require 'watir-webdriver'
require 'java'
java_import "org.sikuli.script.SikuliScript"
java_import "org.sikuli.script.Region"
java_import "org.sikuli.script.Screen"
# setup a controller on port 12351 for your new grid
controller = Controller.new(
:ring_server_port => 12351,
:loglevel => Logger::ERROR)
controller.start
# add a provider to your grid
# :browser_type => 'webdriver' if using webdriver or
# :browser_type => 'ie' if using watir...
provider = Provider.new(
:ring_server_port => 12351,
:loglevel => Logger::ERROR, :browser_type => 'webdriver')
provider.start
# connect to the grid and take all providers from it (this time only one)
grid = Watir::Grid.new(:ring_server_port => 12351, :ring_server_host => '192.168.0.107')
screen=Screen.new
grid.start(:take_all => true)
+++++++++++++ all is fine up to this point. ++++++++++++++
+++++++++++++ this is where the wheels come off ++++++++++++++
+++++++++++++ how to get the screen method available to watirgrid ? ++++++++++++++
irb(main):029:0* grid.screen.click("StartUpAdobe\/f.png",0)
NoMethodError: undefined method `screen' for #<Watir::Grid:0x1a0283e>
from (irb):29:in `evaluate'
from org/jruby/RubyKernel.java:1088:in `eval'
from C:/jruby-1.6.2/lib/ruby/1.8/irb.rb:158:in `eval_input'
from C:/jruby-1.6.2/lib/ruby/1.8/irb.rb:271:in `signal_status'
from C:/jruby-1.6.2/lib/ruby/1.8/irb.rb:155:in `eval_input'
from org/jruby/RubyKernel.java:1419:in `loop'
from org/jruby/RubyKernel.java:1191:in `catch'
from C:/jruby-1.6.2/lib/ruby/1.8/irb.rb:154:in `eval_input'
from C:/jruby-1.6.2/lib/ruby/1.8/irb.rb:71:in `start'
from org/jruby/RubyKernel.java:1191:in `catch'
from C:/jruby-1.6.2/lib/ruby/1.8/irb.rb:70:in `start'
from C:\jruby-1.6.2\bin\irb:13:in `(root)'
We're interested in using watigrid and sikuli for performance testing a vnc-based application.

So in your code, calling .screen does not exist on the 'grid' object, it is actually a method that belongs to the Screen class, which is part of the sikuli packages I'm guessing.
It looks like from the examples, the Screen class object is instantiated locally. What you want is for this object to be instantiated remotely.
Watirgrid just exposes remote watir[-webdriver] objects via DRb. It has no knowledge of Sikuli. It looks like in the examples, you're just using watir-webdriver to start an instance of the browser and navigate to the front page. From then on I'm guessing Sikuli does most of the work.
What you really need is a Sikuligrid =) Since you're the only person that's asked I'm not about to go monkey patch Watirgrid, as there might be a better way to achieve what you're trying to do.
Using DRb you may even be able to do something very simple like this:
remote.rb
require 'drb'
require 'java'
java_import "org.sikuli.script.SikuliScript"
java_import "org.sikuli.script.Region"
java_import "org.sikuli.script.Screen"
DRb.start_service("druby://127.0.0.1:61676", Screen.new)
DRb.thread.join
local.rb
require 'drb'
screen = DRbObject.new_with_uri("druby://127.0.0.1:61676")
screen.click("StartUpAdobe\/f.png",0)
At this point my focus with watirgrid is to enable testing of watir[-webdriver] on a distributed grid network. I do however acknowledge the usefulness of things like webdriver in driving something 'other' than a web app. This is where tools like Sikuli and even nativedriver http://code.google.com/p/nativedriver/ are looking very attractive. Right now though my focus is on making watirgrid bulletproof and probably next on the list is headless browser automation with phantomjs...

As Tim posted, until someone builds a "Sikuli Grid", your best option is to create your own such Grid following Tim's suggestions.
Another simpler but yet still has development work to do alternative is presented in my blog post. It's a theoretical approach that has yet to be implemented and proven though.
http://autumnator.wordpress.com/2011/12/22/autoit-sikuli-and-other-tools-with-selenium-grid/

Related

.NET CORE 3 Upgrade CORS and Json(cycle) XMLHttpRequest Error

I had my working project written in asp.net core 2.1 for a long time, but yesterday, I was forced to upgrade it to .net core 3.0 (due to 2.1 cannot call Dll' s which are written in 3.0 already).
With that, a lot of functions were obsolete or already removed. I fixed almost all of it, but one problem with CORS.
Like many people before me, I used:
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
in Configure function. And services.AddCors() in ConfigureServices function.
I was able to fixed this quite easily with setting WithOrigins() or .SetIsOriginAllowed(_ => true) instead of AllowAnyOrigin() which does not work anymore with AllowCredentials().
After that, I was able to start the application and I thought everything is fine, but then I get stuck until now with problem I do not know, how to fix.
I have DB relation N:N and relation table which handle that, that means I have Admin entity with AdminProject list property, then I have AdminProject entity with Admin list and Project list properties and Project entity with AdminProject list property once again.
When I am listing my projects of certain admin, I am returning in Controller this return Ok(projects), where I just use getAll on AdminProject entity and then with Select return only project.
For that, I have to use[JsonIgnore] in project/admin for properties which I do not need to avoid cycling when creating json.
With that said: NOW IN .NET CORE 3.0 AND CORS SETTINGS IT DOES NOT WORK.
I am getting an error:
System.Text.Json.JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32.
when debugging in console and error Access to XMLHttpRequest at 'http://localhost:5000/api/project/adminlist/1' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. in WEB browser
I think I tried almost everything with Cors settings etc and I do not know why is this happening now. I also tried to JsonConvert.SerializeObject() before return it ---> return Ok(JsonConvert.SerializeObject(projects)) and this is working, but I am not able (mentally) to do this in every single controllers functions.
Please help! Thanks a lot!
The problem was occurring because in .NET Core 3 they change little bit the JSON politics. Json.Net is not longer supported and if you want to used all Json options, you have to download this Nuget: Microsoft.AspNetCore.Mvc.NewtonsoftJson.
After that in your Startup.cs file change/fix/add line where you are adding MVC (in the ConfigureServices method.
So: here is what I did and what fixed my issue:
services.AddMvc(option => option.EnableEndpointRouting = false)
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0)
.AddNewtonsoftJson(opt => opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore);
I hope it will help somebody else.
Cheers!
A couple other things have changed in .net core 3 and now instead of using addMVC you can use addControllers. So your code might look like the follow:
services.AddControllers().AddNewtonsoftJson(x => x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore);

Using Codeception with Laravel and subdomains

I was hoping to use Codeception to handle a subdomain declared in Laravel 5
$router->group(array('domain' => 'admin.' . Config::get('app.host')), function()
{
Codeception appears to have an amOnSubdomain method for webdriver, but not for the Laravel 4 module.
http://codeception.com/docs/modules/WebDriver#amOnSubdomain
Is there a way to integrate this functionality with Codeception on Laravel?
I tried calling the action directly
$I->amOnAction('Auth\AuthController#showRegistrationForm');
But this throws an error
Can't be on action "Auth\AuthController#showRegistrationForm":
Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
A bit confused on how to proceed.
I set an alias with the as index and it worked for me:
Route::post('/login', ['as' => 'admin.login', 'uses' => 'AuthController#postLogin']);
$I->amOnRoute('admin.login');
I also submitted an issue to the codeception repo for this method to be added. I looked into moving the method over from another module that has it already but the laravel module does some different things with it's url and history, and don't have the time at the moment to look into it more. Hopefully that method will work for you.
https://github.com/Codeception/Codeception/issues/1505

Can an embedded cocos2d-js app call back out to c++?

I'm researching the possibility of using cocos2d-js by embedding it as a view inside an existing iOS app. In order to make this work, I'm going to need 2-way communication between cocos2d and the surrounding application.
After some initial investigation, I have determined that it is possible to call in to cocos using ScriptingCore:
ScriptingCore* sc = ScriptingCore::getInstance();
jsval outVal;
sc->evalString("function()", &outVal);
My question, then, is around doing the reverse. It is possible to (e.g. in response to user input) call back out of cocos2d-js to C++? Ideally, there would be a way to register a callback with ScriptingCore which could be invoked from JavaScript.
I believe it can be done, but I have not tried myself, nor can I find a good and concise example.
All I can do is point you at SuperSuraccoon's Bluetooth example and it's git page, which apparently does both ways communication between C++ and JS code.

problems while generating java code from jruby

I have problems while generating .java files with jruby 1.7.3. Here is an example:
class Duck
def quack()
puts "quack!";
end
end
def quack_it(duck)
duck.quack
end
a = Duck.new
quack_it(a)
when I execute
jrubyc --java Test.rb I get the following compilation error:
Failure during compilation of file DuckExample_simple.rb:
undefined method `new_method' for nil:NilClass.
Therefore, I have 2 questions:
What is wrong here?
I want to generate .java files in order to see how the JRuby code is translated into the bytecode and instead of reading the bytecode itself I thought to read the java code. Does the generated java code correspond 1 to 1 to the bytecode generated by AOT jruby compiler, or it's better to read the bytecode itself? I actually want to see how jruby handles dynamic method dispatch at the bytecode level. Any hints would be appreciated.
i don't use jruby so i am not really the best guy to talk to, but here are my 2 cents anyways.
if you just put a simple class into the file, it will work. so try
class Duck
def quack()
puts "quack!"
end
end
it will create a Duck.java file as you would expect, which answeres the second question you had. there is also a nice writeup about the generated file here: http://rhnh.net/2012/10/20/guice-in-your-jruby
i guess that the command is somewhat broken. it would be best to open an issue at the jruby issue tracker: http://jira.codehaus.org/browse/JRUBY

IoC container that can register everything (non generic) automatically without configuration (assembly to assembly)

the idea is that I have a Core project with lots of interfaces, also Data and Service project with implementations (everything 1-to-1), e.g.:
Core { IFooRepo, IBarRepo, IFooService, IBarService}
Data {FooRepo: IFooRepo, BarRepo : IBarRepo}
Service {FooService : IFooService, BarService : IBarService}
so I would like something like
register(Core, Data);
register(Core, Service);
there are lots of IoC containers and I don't know which one of them can do this, or is closer to this solution, anybody knows ?
You are talking about auto-registration. Many IoC containers support this.
StructureMap
http://structuremap.net/structuremap/ScanningAssemblies.htm
Castle Windsor (see bottom of 2nd page of the article)
http://www.code-magazine.com/article.aspx?quickid=0906051
Autofac
http://code.google.com/p/autofac/wiki/Scanning
Ninject
Looks like you can do it via Kernel.Scan(), though I couldn't find docs. (Server was unavailable.)
How to use Ninject Conventions extension without referencing Assembly (or Types within it)
Last I looked, Unity did not support auto-registration, though that may have changed with a recent release.
UPDATE: Thanks to Mauricio for noticing that I incorrectly identified the desired feature as auto-wiring. Corrected and updated the links.
In Autofac the simplest way to achieve this is:
var builder = new ContainerBuilder();
var data = typeof(BarRepo).Assembly();
builder.RegisterAssemblyTypes(data).AsImplementedInterfaces();
var service = typeof(BarService).Assembly();
builder.RegisterAssemblyTypes(service).AsImplementedInterfactes();
var container = builder.Build();
Now this will not be selective about the service interfaces being from the Core assembly. If this really matters (it probably shouldn't) then vary the above registrations along these lines:
var core = typeof(IBarRepo).Assembly();
builder.RegisterAssemblyTypes(data)
.As(t => t.GetInterfaces()
.Where(i => i.Assembly == core)
.Select(i => new TypedService(i)));
Cheers,
Nick
Windsor lets you easily register classes as interfaces they expose, either all of them or, selectively. (see the documentation).
It does not have OOTB support for your scenario (filtering implemented interfaces to only include those from specific assembly) but (as for everything in Windsor) there's a hook you can use to easily have that.
container.Register(
AllTypes.FromAssemblyContaining<SomeClass>()
WithService.Select((type, #base) =>
type.GetAllInterfaces()
.Where(i => i.Assembly == yourInterfacesAssembly)))
);