Recently, I came across a UI Automation scenario where I need to validate the clipboard behavior of a field.
The scenario was: I need to click on a copy SQL button which copies a large SQL which I need to validate. Earlier, I have used the ctrl+c and ctrl+v approach, but here, there was no text field where I can paste that content.
So, at run time, I need to validate the content has been copied or not.
To automate this, I used the java clipboard class.
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Once the clipboard object is created, you can click on the element.
driver.findElement(By.cssSelector("div:nth-child(2) > .input-group .octicon-clippy")).click();
Thread.sleep(2000);
Now, you can extract this data.
Object dataFromCopyURLFeature = clipboard.getData(DataFlavor.stringFlavor);
System.out.println("Copied data is " + dataFromCopyURLFeature);
You can assert this data, with the actual data for validation purpose.
Assert.assertTrue(dataFromCopyURLFeature.equals("https://github.com/qamatters/KarateDemo.git"), "Validate the url");
Let me know if code is needed for this.
No comments:
Post a Comment