Guest User

Untitled

a guest
Oct 20th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. private void electronTest() throws Exception {
  2.  
  3. //select electron-chromedriver
  4. System.setProperty("webdriver.chrome.driver", "/Users/username/work/node_modules/electron-chromedriver/bin/chromedriver");
  5.  
  6. ChromeOptions options = new ChromeOptions();
  7. // path for Electron
  8. options.setBinary("/Users/username/work/app/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron");
  9. // I have tried both the folder and the app
  10. options.addArguments("/Users/username/work/app/out/packages/mac/electronApplication.app");
  11.  
  12. DesiredCapabilities capabilities = new DesiredCapabilities();
  13. capabilities.setCapability("chromeOptions", options);
  14. capabilities.setBrowserName("chrome");
  15.  
  16. driver = new ChromeDriver(capabilities);
  17. // have also tried...
  18. //driver = new RemoteWebDriver(new URL("http://localhost:9515"), capabilities);
  19.  
  20. // Electron page appears, but doesn't launch the Electron app
  21.  
  22. // driver is pointing to the electron page elements even if I drag the app to launch it
  23. String screenText = " [" + driver.findElement(By.tagName("BODY")).getText().replace("n", "][") + "]";
  24. System.out.println("screenText " + screenText);
  25. }
  26.  
  27. public void electronTest()
  28. {
  29. System.setProperty("webdriver.chrome.driver","path to the chromedriver");// You can skip this if chromedriver is already included in the PATH.
  30.  
  31. ChromeOptions options = new ChromeOptions();
  32. options.setBinary("/Applications/YourApp.app/Contents/MacOS/YourApp");
  33. DesiredCapabilities capabilities = new DesiredCapabilities();
  34. capabilities.setCapability(ChromeOptions.CAPABILITY, options);
  35. driver = new ChromeDriver(capabilities);
  36.  
  37.  
  38. // Now, your electron app would have been opened.
  39. // Now if you open the dev tools using CMD+ALT+I you would notice two dev tools and first one being for the electron shell. We need to switch to the second window handle. Let's do that.
  40.  
  41. for (String handle : driver.getWindowHandles())
  42. {
  43. driver.switchTo().window(handle); // Since there are two window handles this would switch to last one(which is second one). You can also explicitly provide the window number.
  44. }
  45.  
  46. // Let's navigate to a page
  47. driver.navigate().to(URL);
  48. // If you inspect using the Dev Tools, you would notice the second window Dev Tools corresponds to actual page you have opened.
  49. // From here you can write the usual selenium script and it will work.
  50. }
  51.  
  52. System.setProperty("webdriver.chrome.driver", "ChromeDriverPath");
  53. ChromeOptions options = new ChromeOptions();
  54. options.setBinary(binaryPath);
  55. options.addArguments("--app=" + argPath);
  56. options.setCapability("chromeOptions", options);
  57. options.setCapability("browserName", "chrome");
  58.  
  59. driver = new ChromeDriver(options);
  60.  
  61. WebDriver Rdriver;
  62. @Test
  63. public void launch() throws InterruptedException, IOException {
  64.  
  65. System.setProperty("webdriver.chrome.driver","D:\work\grid\chromedriver.exe"); // chromedriver path
  66.  
  67. ChromeOptions options = new ChromeOptions();
  68. options.setBinary("D:\Users\myol\AppData\Local\Programs\ConnectMe_S4B2015\Connect Me S4B2015.exe");
  69. DesiredCapabilities capabilities = new DesiredCapabilities();
  70. capabilities.setCapability(ChromeOptions.CAPABILITY, options);
  71. capabilities.setBrowserName("chrome");
  72. capabilities.setPlatform(Platform.WINDOWS);
  73.  
  74. WebDriver Rdriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
  75.  
  76. for (String hand : Rdriver.getWindowHandles()) {
  77.  
  78. Rdriver.switchTo().window(hand);
  79. }
  80.  
  81. Rdriver.findElement(By.id("username-kandy")).sendKeys("2311");
  82.  
  83.  
  84.  
  85.  
  86. }
Add Comment
Please, Sign In to add comment