33import com .vaadin .testbench .TestBenchElement ;
44import com .vaadin .testbench .commands .TestBenchCommandExecutor ;
55import com .vaadin .testbench .elementsbase .Element ;
6+ import java .util .Arrays ;
67import java .util .List ;
78import org .openqa .selenium .WebElement ;
89
@@ -18,14 +19,14 @@ public class XTermElement extends TestBenchElement {
1819 protected void init (WebElement element , TestBenchCommandExecutor commandExecutor ) {
1920 super .init (element , commandExecutor );
2021 input = (WebElement ) waitUntil (
21- driver -> executeScript ("return arguments[0] .terminal.textarea" , this ));
22+ driver -> executeScript ("return this .terminal.textarea" ));
2223 }
2324 public void write (String text ) {
24- executeScript (String .format ("arguments[0] .terminal.write('%s')" , text ), this );
25+ executeScript (String .format ("this .terminal.write('%s')" , text ));
2526 }
2627
2728 public int getColumnWidth () {
28- return ((Long ) executeScript ("return arguments[0] .terminal.cols" , this )).intValue ();
29+ return ((Long ) executeScript ("return this .terminal.cols" )).intValue ();
2930 }
3031
3132 final String currentLine () {
@@ -34,15 +35,15 @@ final String currentLine() {
3435
3536 public String lineAtOffset (int offset ) {
3637 return ((String ) executeScript (
37- "buffer=arguments[0] .terminal._core._inputHandler._bufferService.buffer;"
38- + "line=buffer.lines.get(buffer.ybase+buffer.y+(arguments[1 ]));"
38+ "buffer=this .terminal._core._inputHandler._bufferService.buffer;"
39+ + "line=buffer.lines.get(buffer.ybase+buffer.y+(arguments[0 ]));"
3940 + "return line.translateToString().substr(0,line.getTrimmedLength());" ,
40- this , offset ));
41+ offset ));
4142 }
4243
4344 public Position cursorPosition () {
4445 int [] pos = intArray (executeScript (
45- "buffer=arguments[0] .terminal.buffer.active; return [buffer.cursorX, buffer.cursorY]" ,
46+ "buffer=this .terminal.buffer.active; return [buffer.cursorX, buffer.cursorY]" ,
4647 this ));
4748 return new Position (pos [0 ], pos [1 ]);
4849 }
@@ -63,4 +64,15 @@ public void setPrompt(String value) {
6364 public void sendKeys (CharSequence ... keysToSend ) {
6465 input .sendKeys (keysToSend );
6566 }
67+
68+ @ Override
69+ public Object executeScript (String script , Object ... arguments ) {
70+ script = String .format (
71+ "return function(arguments){arguments.pop(); %s}.bind(arguments[arguments.length-1])([].slice.call(arguments))" ,
72+ script );
73+ arguments = Arrays .copyOf (arguments , arguments .length + 1 );
74+ arguments [arguments .length - 1 ] = this ;
75+ return getCommandExecutor ().executeScript (script , arguments );
76+ }
77+
6678}
0 commit comments