Why it's showing underline eventhough I import necessary package in Katalon Studio? - point

import org.openqa.selenium.Point
// Define the two TestObjects to be swapped
TestObject firstObject = new TestObject("firstObject")
firstObject.addProperty("xpath", ConditionType.EQUALS, "//div[#id='firstObject']")
TestObject secondObject = new TestObject("secondObject")
secondObject.addProperty("xpath", ConditionType.EQUALS, "//div[#id='secondObject']")
// Get the locations of the TestObjects before the swap
Point firstLocationBefore = firstObject.getLocation()
Point secondLocationBefore = secondObject.getLocation()
Eventhough I import necessary package at top: import org.openqa.selenium.Point
But it's still showing underline for getLocation() in the code.
Why it's showing underline eventhough I import necessary package in Katalon Studio?

The getLocation() method is a member of the WebElement class in the Selenium library. Therefore, in order to use getLocation(), I need to create a WebElement object and then call getLocation() on that object. My code only have two TestObjects, so I can't use getLocation() method.
To fix this code, I need to create a WebElement object and then call the getLocation() method on it:
WebElement element = DriverFactory.getWebDriver().findElement(By.xpath("//div[#id='firstObject']"));`
Point firstLocationBefore = element.getLocation();

Related

Groovy to validate if Node exists or not

I'm trying to validate in Groovy if a node came from an external system, if the external system has a value the node comes with a value, if the system dont have a value the node doesn't come in the payload.
Based on this i need to change/correct if its a NEW or UPDATE process for that record in an existing node.
Incoming XML is:
<urn:ExternalReqForApprovalImportRequest xmlns:urn="urn:Ariba:Buyer:vrealm_1" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" partition="" variant="">
<urn:ExternalReqForApprovalInput_Item>
<urn:item>
<urn:Name>TEST</urn:Name>
<urn:Operation>XXXXXX</urn:Operation>
<urn:HeaderExtrinsics>
<Extrinsics>
<Extrinsic name="PRRefID">THIS IS THE NODE THAT MAY OR NOT MAY COME</Extrinsic>
<Extrinsic name="XXXXXXX">Value</Extrinsic>
<Extrinsic name="AnotherField">TValue</Extrinsic>
</Extrinsics>
</urn:HeaderExtrinsics>
</urn:item>
</urn:ExternalReqForApprovalInput_Item>
</urn:ExternalReqForApprovalImportRequest>
I created this groovy:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.lang.String;
def Message processData(Message message) {
map = message.getProperties();
value = map.get("PRRefID");
Reader reader = message.getBody(Reader)
def FG = new XmlParser().parse(reader)
if(value == null) {
FG.'urn:ExternalReqForApprovalInput_Item'.'urn:item'.'urn:HeaderExtrinsics'.Operation = "NEW"
} else {
FG.'urn:ExternalReqForApprovalInput_Item'.'urn:item'.'urn:HeaderExtrinsics'.Operation = "UPDATE"
}
message.setBody(FG);
return message;
}
What i want to achieve is validate if Extrinsic with name PRRefID comes in the xml, if it comes i need to update the Operation to UPDATE, if it doesnt come i need to set NEW as the value.
I tried to map the xpath as a Property (probably there is a cleaner way to map this from the direct xpath), but my issue right now is changing the value, since its a extrinsic with a specific name, apparently that is nor the right format for the assignation, so which should it be?
Thank you.
Just needs some syntax tweaks,
FG.'urn:ExternalReqForApprovalInput_Item'.'urn:item'.'urn:HeaderExtrinsics'.Extrinsics.Extrinsic[0].value = "NEW"
You have to specify the namespace wherever necessary
Note that when you parse, FG becomes root of the document so don't specify urn:ExternalReqForApprovalImportRequest again
I assumed you are trying to update the text node value
Note also that Extrinsic will be an array of nodes, so you have to refer to it by index
I finally solved it following your recommendation in the namespace!
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import java.lang.String;
import groovy.util.XmlSlurper
import groovy.xml.XmlUtil
def Message processData(Message message) {
map = message.getProperties();
value = map.get("PRRefID");
Reader reader = message.getBody(Reader)
def root = new XmlParser().parse(reader)
if(value == "") {
root.'urn:ExternalReqForApprovalInput_Item'.'urn:item'.'urn:Operation'[0].value = "NEW"
}
message.setBody(XmlUtil.serialize(root))
return message;
}
Thank you.

Eclipse Plugin development showing and hiding menuContribution when opening and closing perspective

I am developing my Eclipse Plugin using E4 2020-09 version. I created a Perspective and a menuContribution using Model Fragments. I have searched several tutorials but I have not seen any that showing how to make a menuContribution appear/disappear when opening/closing a Perspective in E4 during development. What I found was these examples: https://github.com/vogellacompany/codeexamples-eclipse but this function is implemented for E3 and I want to implement it in E4.
Can you give me some hints/advices about this technique and how it is called or where to start with it?
Thanks and best regards.
You can do this in the 'Visible-When Expression' for the menu items.
Set the expression to be 'ImperativeExpression'. And create a class to handle the expression. This class just has a single method annotated with #Evaluate which is called each time the menu item might be displayed:
#Evaluate
public boolean evaluate(EModelService modelService, .... other parameters)
{
// TODO determine if menu item should be visible
}
This class can then use the getActivePerspective method of EModelService to check if the menu item should be visible.
449,
Thank you for you answer, I finally made it according to your instruction. I will leave my reference code here in case there are people asking about this:
Create MenuContributionsHandler class
package com.catto.ide.dev.handlers;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Evaluate;
import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
public class MenuContributionsHandler
{
#Inject MWindow window;
#Evaluate
public boolean evaluate(EModelService modelService)
{
// TODO determine if menu item should be visible (return true)
MPerspective currentPerspective = modelService.getActivePerspective(window);
if (null != currentPerspective)
{
return currentPerspective.getLabel().equals("SnowCatto");
}
return false;
}
}
Add this class to the Imperative Expression to MenuContribution Class URI.
Best regards.

Haxe - Why can I not access a child's attribute without getting an error that the parent does not have the given attribute?

I've recently been getting into Haxe and just started to use HaxeFlixel to load a Tiled .TMX file.
I am creating a TiledMap object and passing it the TMX file path, then I want to iterate over the layers in that object to add them to the game scene. However when I try to access .tileArray (which is a property of TiledTileLayer) I get the following error :-
flixel.addons.editors.tiled.TiledLayer has no field tileArray
Here is the code:
package;
import flixel.FlxState;
import flixel.tile.FlxTilemap;
import flixel.addons.editors.tiled.TiledMap;
import openfl.Assets;
class PlayState extends FlxState
{
private var _tiled_map:TiledMap;
override public function create():Void
{
_tiled_map = new TiledMap("assets/data/Map1.tmx");
for(layer in _tiled_map.layers){
var layerData:Array<Int> = layer.tileArray;
}
super.create();
}
override public function update(elapsed:Float):Void
{
super.update(elapsed);
}
}
I've found the following example - http://coinflipstudios.com/devblog/?p=182 which seems to work fine for people.
So I wanted to check whether the layer object was a TiledTileLayer as it should be, or TiledLayer, with the following:
trace(Type.typeof(layer));
Which sure enough yields:
PlayState.hx:24: TClass([class TiledTileLayer])
So if it is a TiledTileLayer which has the field tileArray why is it moaning?
I had a look at the source code (https://github.com/HaxeFlixel/flixel-addons/blob/dev/flixel/addons/editors/tiled/TiledMap.hx#L135) and TiledTileLayer inherits from TiledLayer. Layers is an array of type TiledLayer, so I think this is why it is moaning. I can clearly see that the array is storing child objects of TiledLayer, but as soon as I access any props/methods of those children, it complains that the parent does not have that field? Very confusing!
To run I'm using this command: C:\HaxeToolkit\haxe\haxelib.exe run lime test flash -debug -Dfdb
Thank you!
So if it is a TiledTileLayer which has the field tileArray why is it moaning?
It may be a TiledTileLayer in this case, but that may not always be the case. layers is an Array<TileLayer> after all, so it could be a TiledObjectLayer or a TiledImageLayer as well (which don't have a tileArray field). This can nicely be seen in the code you linked. The concrete type can only be known at runtime, but the error you get happens at compile-time.
If you know for sure there won't be any object or image layers, you can just cast it to a TiledTileLayer. However, just to be safe, it's good practice to check the type beforehand anyway:
for (layer in _tiled_map.layers) {
if (Std.is(layer, TiledTileLayer)) {
var tileLayer:TiledTileLayer = cast layer;
var layerData:Array<Int> = tileLayer.tileArray;
}
}
It works without this for the tutorial you linked because it was made for an older version of flixel-addons.

How do you pass constructor parameters using a builder like SwingBuilder?

I want to access JFrame(GraphicsConfiguration) using SwingBuilder.frame(), but I can't set it via the attributes, since it's unavailable. How do you pass constructor parameters using the Groovy Builders?
UPDATE: As requested, including the solution.
The value parameter for the FrameFactory.newInstance(builder, name, value, attrs) method is checked first to see if it's a JFrame itself. If not, it's ignored, and a new JFrame is created. It is then passed to a post-init method to handle the attributes.
This maps to the following syntax:
builder.name(value, attrs){}
where attrs is your map of attributes in the standard key:value format.
So, to complete with an example:
SwingBuilder swing = new SwingBuilder()
// pass the title to the valueFrame, even though we can pass as attr, for the example
JFrame valueFrame = new JFrame("Value Frame Title")
JFrame myFrame = swing.frame(valueFrame,
pack:true,
defaultCloseOperation:JFrame.DISPOSE_ON_CLOSE) {
... add your panels, etc here
}
assert myFrame == valueFrame
You should be able to pass in a JFrame as the value argument, according to the SwingBuilder.frame docs; maybe try that.

How to pass a String from a SWF into another SWF

hoping this is an easy enough question :)
Some details:
I am using Flash CS5, never touched Flex. Also the SWF that is doing the loading will be a client SWF, so hoping for a solution that could work with a simple couple of lines.
Basically inside the SWF I am working on contains just a simple string:
var theString = "theString";
trace("theString = "+theString);
Now I've been working on a test loader SWF that will load my String SWF and get the variable in the simplest way. Any thoughts? Below is my current broken code:
function loaderComplete(event:Event)
{
trace("... in loaderComplete");
getString = loader.content.toString();
trace("loader.content = "+loader.content);
trace("... getString = "+getString);
}
This is my output window:
theString = theString
... in loaderComplete
loader.content = [object MainTimeline]
... getString = [object MainTimeline]
I've searched on Stack and found similar questions, but none are exactly what I need:
tracking video files - embedding flv to swf
^ Basically what I'm trying to do as well, no answers yet
to pass variable from one swf to another swf in as3
^ sounded just like my problem, but answer was a Flex application example
pass var values from one swf to another swf who is loaded inside the firts one in AS3
^ This was close, but am not sure how to implement the chosen answer, also seems a bit more intricate then I need
Please help!
Let's clarify a bit:
1. The loader swf, we will call the parent.
2. The swf loaded by the parent we will call the child.
The Child contains a string, and you want the parent to be able to read that string>
So...
The Child must define a public variable for the string. (This means you have to use a Class file for it, since you cannot declare a property public on the timeline.)
Finally, the parent will try and get that property. You may want to wrap that in a try/catch to handle cases where the string will not be present.
Here is an example Child Class.
package
{
import flash.display.Sprite;
/**
* ...
* #author Zach Foley
*/
public class Child extends Sprite
{
public var value:String = "This is the child Value";
public function Child()
{
trace("Child Loaded");
}
}
}
And here is the parent loader class:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
/**
* ...
* #author Zach Foley
*/
public class Parent extends Sprite
{
private var loader:Loader;
public function Parent()
{
trace("PArent Init");
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("child.swf"));
}
private function onLoaded(e:Event):void
{
trace("Child Loaded");
trace(loader.content['value']);
}
}
}
The Output will be:
PArent Init
Child Loaded
Child Loaded
This is the child Value
you can access variables and code from the loaded swf. First, make sure that both the loader and the loaded content use the same AVM, this means that both project use the same version of language (both as3 or both as2)
Thank in the loader complete handler:
loaderComplete(evt:Event):void{
var mc:MovieClip = loader.content as MovieClip;
if(!mc){
trace("Error loading");
return;
}
trace("Your string: " + mc.theString);
}
I haven't tested this code but it should works

Resources