Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void electronTest() throws Exception {
- //select electron-chromedriver
- System.setProperty("webdriver.chrome.driver", "/Users/username/work/node_modules/electron-chromedriver/bin/chromedriver");
- ChromeOptions options = new ChromeOptions();
- // path for Electron
- options.setBinary("/Users/username/work/app/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron");
- // I have tried both the folder and the app
- options.addArguments("/Users/username/work/app/out/packages/mac/electronApplication.app");
- DesiredCapabilities capabilities = new DesiredCapabilities();
- capabilities.setCapability("chromeOptions", options);
- capabilities.setBrowserName("chrome");
- driver = new ChromeDriver(capabilities);
- // have also tried...
- //driver = new RemoteWebDriver(new URL("http://localhost:9515"), capabilities);
- // Electron page appears, but doesn't launch the Electron app
- // driver is pointing to the electron page elements even if I drag the app to launch it
- String screenText = " [" + driver.findElement(By.tagName("BODY")).getText().replace("n", "][") + "]";
- System.out.println("screenText " + screenText);
- }
- public void electronTest()
- {
- System.setProperty("webdriver.chrome.driver","path to the chromedriver");// You can skip this if chromedriver is already included in the PATH.
- ChromeOptions options = new ChromeOptions();
- options.setBinary("/Applications/YourApp.app/Contents/MacOS/YourApp");
- DesiredCapabilities capabilities = new DesiredCapabilities();
- capabilities.setCapability(ChromeOptions.CAPABILITY, options);
- driver = new ChromeDriver(capabilities);
- // Now, your electron app would have been opened.
- // 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.
- for (String handle : driver.getWindowHandles())
- {
- 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.
- }
- // Let's navigate to a page
- driver.navigate().to(URL);
- // If you inspect using the Dev Tools, you would notice the second window Dev Tools corresponds to actual page you have opened.
- // From here you can write the usual selenium script and it will work.
- }
- System.setProperty("webdriver.chrome.driver", "ChromeDriverPath");
- ChromeOptions options = new ChromeOptions();
- options.setBinary(binaryPath);
- options.addArguments("--app=" + argPath);
- options.setCapability("chromeOptions", options);
- options.setCapability("browserName", "chrome");
- driver = new ChromeDriver(options);
- WebDriver Rdriver;
- @Test
- public void launch() throws InterruptedException, IOException {
- System.setProperty("webdriver.chrome.driver","D:\work\grid\chromedriver.exe"); // chromedriver path
- ChromeOptions options = new ChromeOptions();
- options.setBinary("D:\Users\myol\AppData\Local\Programs\ConnectMe_S4B2015\Connect Me S4B2015.exe");
- DesiredCapabilities capabilities = new DesiredCapabilities();
- capabilities.setCapability(ChromeOptions.CAPABILITY, options);
- capabilities.setBrowserName("chrome");
- capabilities.setPlatform(Platform.WINDOWS);
- WebDriver Rdriver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
- for (String hand : Rdriver.getWindowHandles()) {
- Rdriver.switchTo().window(hand);
- }
- Rdriver.findElement(By.id("username-kandy")).sendKeys("2311");
- }
Add Comment
Please, Sign In to add comment