Groovy Syntax for multiple list element declaration


Ooh look! Now I get to use “Find a specialist”! (Like I didn’t already know them :wink: )

Callout to @Brandon_Hein @kazurayam @Marek_Melocik @Mate_Mrse (re Java/Groovy)

Is there a groovy-way to do this?

List myList = [“first”, “item” * 3, “last”]

The multiplier is (of course) bound to the string, producing “itemitemitem”. Is there a way to get [“first”, “item”, “item”, “item”, “last”] such that this notional method could be coded and get what I wish?

def thing(int mult) {
  List myList = ["first", "item" * mult, "last"]

assert ['item'] * 3 == ['item', 'item', 'item']

assert ['first', ['middle'], 'last'].flatten() == ['first', 'middle', 'last']

def thing(int mult) {
	List myList = ['first', ['item'] * mult, 'last'].flatten()

assert thing(3) == ['first', 'item', 'item', 'item', 'last']





Dang, kaz beat me to it…


Yei! :slightly_smiling_face:


For posterity (and anyone wondering what the hell I wanted that for) …

   * Select an item from an ACE dropdown.
   * @param selector (String) CSS selector of the target control containing the ACE.
   * @param count (int) The number of downarrow keys to send to the ACE.
   * @param filter (String) Optional prefix to filter the ACE. (e.g. "Wayne").
  void chooseACEItem(String selector, int count, String filter = "") {
    WebDriver driver = DriverFactory.getWebDriver()
    WebElement elem = driver.findElement(By.cssSelector(selector))
    List keys = [Keys.RIGHT, [Keys.DOWN] * count, Keys.ENTER].flatten();
    type(selector, filter)
    for(def key in keys) { 

ACE = AutoComplete Extender



groovy way:

keys.each {