Is there method to check in Groove availability of object in global scope? My script runs on dev machine and CI. When it runs on CI there is teamcity object but on dev not. Next method throws exception on dev machine.
def isTeamCityAvailable(){
tc = this['teamcity']
if(tc == null){
return false;
}else{
return true;
}
}
If this is in a build.gradle file, you should be able to do:
def isTeamCityAvailable() {
hasProperty( 'teamcity' )
}
Related
I want to detect if my extension has been installed from a normal browser or with an automation tool. in Manifest v2 it was possible because we could access the window object from the background and we use navigator.webdriver property but now in Manifest v3 we can't anymore because of Service Worker.
Is there any alternative solution?
Update:
Here I got the solution in other way. Like we can detect if extension crx file is loaded locally from below method-
const self = await browserType.management.getSelf();
if(self.installType === "normal"){
console.log("extension installed locally");
}
else if(self.installType === "development"){
console.log("extension installed from store"); }
Method one
let id = chrome.runtime.id
if (id)
console.log("id found, not headless")
Method Two
let checkIfheadless = navigator.language || navigator.userLanguage || navigator.browserLanguage || navigator.systemLanguage if (checkIfheadless) console.log("not headless")
Method Three
const phantomJsCheck = function () {
if (!Function.prototype.bind) {
console.log("PhantomJS environment detected. #1");
return;
}
if (Function.prototype.bind.toString().replace(/bind/g, 'Error') != Error.toString()) {
console.log("PhantomJS environment detected. #2");
return;
}
if (Function.prototype.toString.toString().replace(/toString/g, 'Error') != Error.toString()) {
console.log("PhantomJS environment detected. #3");
return;
}
console.log("PhantomJS environment not detected.");
}
I've got a problem with testing Java code using Groovy/Spock.
I wrote a short lambda-expression for filtering a list:
public List<myVO> getMeSomething() {
return RequestUtils.getRequestAttribut("somestuff", () -> getList().stream().filter(mt ->
!mt.isArchived()).filter(mt -> !mt.isSomething()).collect(toList()));
}
I used this to test it:
when:
2 * contextData.getList() >> [item1, item2]
List<myVO> list = context.getMeSomething()
then:
list.contains(item1)
!list.contains(item2)
This worked when run as single test. When I executed all tests in the project this one failed. I tried to extract the "getList()" into a local variable but it had no effect.
Then I changed the method to:
public List<myVO> getMeSomething() {
List<myVO> result = new ArrayList<>();
for (myVO vo : Objects.requireNonNull(getList())) {
if (!vo.isSomething() && !vo.isArchived()) {
result.add(vo);
}
}
return result;
}
And suddenly the test worked where it failed before. Is there any reason for this behavior? Is there a problem with testing a lambda with Spock?
Thanks!
My problem is that server process doesn't get shut down after the last integration test.
In integration.rs, I have:
lazy_static! {
static ref SERVER: Arc<Mutex<duct::ReaderHandle>> = {
println!("Starting server");
Arc::new(Mutex::new(
cmd!("cargo", "run", "--", "13000")
.reader()
.expect("Valid server"),
))
};
}
async fn wait_for_server() {
lazy_static::initialize(&SERVER);
// Code to wait
}
#[tokio::test]
async fn integration_test_query_amount() -> Result<()> {
wait_for_server().await;
let client = reqwest::Client::new();
// Etc...
}
The tests work, but the server stays running after the cargo test invocation finishes. Is there a nice recipe for starting up and shutting down a server like this?
You can make a Drop wrapper for a process which will kill it when it goes out of scope. Something along the lines of:
struct KillOnDrop(std::process::Child);
impl Drop for KillOnDrop {
fn drop(&mut self) {
self.0.kill()
}
}
Alternatively, as it looks like you're using tokio already, tokio::process supports this out of the box.
I am using Microsoft Automation UI framework to develop my automation test cases. The problem I faced with is related to interaction with static text control. I am just trying to get the control's text. The test work perfect when I run the test on my local machine. The problem is when I run the test via Test Controler on the (no matter which) Test Agent. The error which appear is that the static control text can not be found.
Theis is the part of my code where I am trying to initialize the control I want to interact with:
private void Init(TreeScope treeScope, params Condition[] properties)
{
try
{
List<Condition> propertiesList = properties.ToList();
propertiesList.Add(Condition.TrueCondition);
bool controlFound = Wait.ForCondition(
() =>
{
try
{
TestControl = Parent.FindFirst(treeScope,
new System.Windows.Automation.AndCondition(propertiesList.ToArray()));
return !TestControl.Current.IsOffscreen;
}
catch
{
return false;
}
});
if (!controlFound)
{
throw new ElementNotAvailableException(DescriptiveName + "Control is NOT found");
}
this.GetItAsUITestControl().WaitForControlReady(Playback.PlaybackSettings.WaitForReadyTimeout);
if (TestControl.Current.IsKeyboardFocusable)
{
TestControl.SetFocus();
}
string controlFullName = this.TestControl.Current.ControlType.ProgrammaticName;
DescriptiveName = "< " + DescriptiveName + " " + controlFullName.Substring(controlFullName.LastIndexOf(".")) + " >";
}
catch (ElementNotAvailableException ex)
{
Report.Error(ex.Message);
}
catch (Exception ex)
{
Report.Error(ex.Message);
}
}
Any ideas?
I am using Microsoft System Center Virtual Machine Manager 2008 R2 for managing my virtual machines (I think all machines are vmware). But from my prespective the problem is not in the virtual machine because all of the tests are executed without any problems on the VM except the one which verify the Static Text Control content. I am 100% sure that the desctop of the VM where the tests are executed is active because I am able to look at it using VMWare Remote Console.
In terms of execution of the tests on the remote machine I am using Test Controlers and Test Agents which comes with Visual Studio.
I'm writing some JVM instance related application and looking at open source to see how it's solve some problems. The JConsole from JDK7 collects running VMs in two ways (look at source licensed by GPL2 in jdk/src/share/classes/sun/tools/jconsole/LocalVirtualMachine.java). The first is jvmstat way, code like this:
private static void getMonitoredVMs(Map<Integer, LocalVirtualMachine> map) {
MonitoredHost host;
Set vms;
try {
host = MonitoredHost.getMonitoredHost(new HostIdentifier((String)null));
vms = host.activeVms();
} catch (java.net.URISyntaxException sx) {
throw new InternalError(sx.getMessage());
} catch (MonitorException mx) {
throw new InternalError(mx.getMessage());
}
for (Object vmid: vms) {
if (vmid instanceof Integer) {
int pid = ((Integer) vmid).intValue();
String name = vmid.toString(); // default to pid if name not available
boolean attachable = false;
String address = null;
try {
MonitoredVm mvm = host.getMonitoredVm(new VmIdentifier(name));
// use the command line as the display name
name = MonitoredVmUtil.commandLine(mvm);
attachable = MonitoredVmUtil.isAttachable(mvm);
address = ConnectorAddressLink.importFrom(pid);
mvm.detach();
} catch (Exception x) {
// ignore
}
map.put((Integer) vmid,
new LocalVirtualMachine(pid, name, attachable, address));
}
}
}
Second is attach way, and looks like this:
private static void getAttachableVMs(Map<Integer, LocalVirtualMachine> map) {
List<VirtualMachineDescriptor> vms = VirtualMachine.list();
for (VirtualMachineDescriptor vmd : vms) {
try {
Integer vmid = Integer.valueOf(vmd.id());
if (!map.containsKey(vmid)) {
boolean attachable = false;
String address = null;
try {
VirtualMachine vm = VirtualMachine.attach(vmd);
attachable = true;
Properties agentProps = vm.getAgentProperties();
address = (String) agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP);
vm.detach();
} catch (AttachNotSupportedException x) {
// not attachable
} catch (IOException x) {
// ignore
}
map.put(vmid, new LocalVirtualMachine(vmid.intValue(),
vmd.displayName(),
attachable,
address));
}
} catch (NumberFormatException e) {
// do not support vmid different than pid
}
}
}
My question: why it uses two different tools for retrieving virtual machines list? I know that through attach api you can list VMs running by this same JRE only, but jvmstat can give you list of all VMs running with any JRE versions. I have tested JRE/JDK 7 32 and 64-bit only because theys and newer are my target, sadly on windows only. Is not suffiecient to use jvmstat only? Is there any case when some VM is visible by attach api, but jvmstat can't see it?
Usually, for finding all jvm process, attach api is equal to jvmstat. But in some customized circumstances, it's diffrent. And the diffrent is com.sun.tools.attach.spi.AttachProvider.
e.g. in Windows platform, jvmstat finds java process by listing all files in the directory %TEMP%/hsperfdata_caoxudong(In linux, it is /tmp/hsperfdata_caoxudong). And attach api finds java processes by AttachProvider instance. jdk provides a default an AttachProvider implementation, which depends on your OS platform. In Windows Platform, the implementation is sun.tools.attach.WindowsAttachProvider. In its listVirtualMachines method, if isTempPathSecure method return false, it will iterate all processes, and find all processes, which loaded library "jvm.dll". You can install your own AttachProvider implementation to find java processes with your own ways, and the result may be diffrent with jvmstat.
The installation of AttachProvider is here.