Skip to content

Set Scan Wait Rate doesnt set scan rate properly. #189

@raider001

Description

@raider001

Hey there, thankyou for this library, so far its great!

When playing with the Set Scan Rate key word, I noticed that the set scan rate doesn't seem to apply properly.

I dont have an IDE available, nor do I have a example script to demonstrate this at the moment otherwise I would do a pull request or give the script to demonstate... But the problem is due to the following:

@RobotKeywords
public class ScreenKeywords {

    private static double DEFAULT_TIMEOUT = 3.0;
    private static Screen screen = new Screen();
    private static Region region = new Region(screen);

Note in ScreenKeywords.java, the region is created

and in SettingsKeywords.java

This is good, but this is an issue with how the Region class is then initialised in SikuliApi, which at its initialisation, it only ever calls Settings.WaitScanRate once.

public class Region extends Element {
   ...
  /**
   * set the regions individual WaitScanRate
   *
   * @param waitScanRate decimal number
   */
  public void setWaitScanRate(float waitScanRate) {
    this.waitScanRate = waitScanRate;
  }

  private float waitScanRateDefault = Settings.WaitScanRate;
  private float waitScanRate = waitScanRateDefault;

So the following logic, doesn't quite control the scan rate for the region defined in the region key words.

   @RobotKeyword("Set wait scan rate"   + "\n Specify the number of times actual search operations are performed per second while waiting for a pattern to appear or vanish.")
   @ArgumentNames({"delay"})

   public void setWaitScanRate(float scanRate) {
      Settings.WaitScanRate = scanRate;
    }

So this is where it gets a little tricky because the two classes containing the key words don't effectively work with one-another.

Could always do the lazy option and move the Set wait scan rate into ScreenKeywords.java and then do a
region.setWaitScanRate(float scanRate) instead (I wont complain, this will solve my issue ;) )

or.. if you are looking for a cleaner/ more elegant solution..

Create a settings class service, with an inbuilt observer pattern to notify settings changes made from SettingsKeywords.java to ScreenKeywords.java.

I would normally suggest DI, but being that I'm not super experienced with robot keywords yet and how that impacts keyword registration, A Singleton pattern may be better suited here even though its more of a anti-pattern.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions