Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to connect Edge driver from Winium driver on same port? #358

Open
smartxel opened this issue Sep 29, 2022 · 0 comments
Open

Not able to connect Edge driver from Winium driver on same port? #358

smartxel opened this issue Sep 29, 2022 · 0 comments

Comments

@smartxel
Copy link

I am trying to automate an application on Windows11. We have .exe to run and need to create shortcut file on desktop to run. I have to click on that .lnk file to process further execution. So I am using winium driver to start .lnk application on port 9999. Now I have to continue automation on open application edge browser. i.e. When I click on .lnk file present on desktop, will open in Edge browser (IE Mode On). Then I will have to same session to login application.

Application is opening through winium driver but not able to login to application since driver session not working

ChromeTest.Java

import java.io.File;
import java.io.IOException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriverService;
import org.openqa.selenium.edge.EdgeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.winium.DesktopOptions;
import org.openqa.selenium.winium.WiniumDriver;
import org.openqa.selenium.winium.WiniumDriverService;

public class ChromeTest {

    public static void main(String[] args) throws IOException, InterruptedException {
        // TODO Auto-generated method stub

        WebDriver browser = null;
        DesktopOptions option;
        WiniumDriver windriver = null;
        WiniumDriverService service = null;
        String applicationPath = "C:\\Users\\My\\Desktop\\172.20.1.4.lnk";
        
        // user profile path = C:\Users\My\AppData\Local\Microsoft\Edge\User Data\Default

        try {

            option = new DesktopOptions();

            option.setApplicationPath(applicationPath);
            option.setDebugConnectToRunningApp(false);

            File driverPath = new File(System.getProperty("user.dir") + File.separator + "drivers" + File.separator
                    + "Winium.Desktop.Driver.exe");

            service = new WiniumDriverService.Builder().usingDriverExecutable(driverPath).usingPort(9999)
                    .withVerbose(true).withSilent(false).buildDesktopService();

            try {
                service.start();
            } catch (IOException e) {
                System.out.println("Exception while starting WINIUM service");
                e.printStackTrace();
            }
            windriver = new WiniumDriver(service, option);

            Thread.sleep(10000);
            
            
            // creating instance of edge using port 
            System.out.println("1");
            EdgeDriverService edgeservice = new EdgeDriverService.Builder()
                    .usingDriverExecutable(new File("D:\\My_Workspace\\ChromeTest\\drivers\\msedgedriver.exe")).usingPort(9999).build();
            System.out.println("2");
            edgeservice.start();
            System.out.println("3");
            System.out.println("URL :: "+edgeservice.getUrl());
            
            
            
            browser = new RemoteWebDriver(edgeservice.getUrl(), new EdgeOptions());
            System.out.println("4");
            System.out.println("TITLE :: "+browser.getTitle());
            Thread.sleep(20000);

        } catch (Exception e) {

            System.out.println(e);

        }
        Thread.sleep(20000);


        Thread.sleep(20000);
        // browser.quit();
//      edgeDriverservice.stop();
        service.stop();
        // windriver.quit();

    }

}

POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ChromeTest.com</groupId>
    <artifactId>ChromeTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    
    <dependencies>

        <dependency>

            <groupId>com.github.2gis.winium</groupId>
            <artifactId>winium-webdriver</artifactId>
            <version>0.1.0-1</version>

        </dependency> 
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.1.0</version>
            <scope>test</scope>
        </dependency>

    <!--    <dependency>
            <groupId>io.appium</groupId>
            <artifactId>java-client</artifactId>
            <version>7.3.0</version>
        </dependency> -->

         <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency> 

        <!--  <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>4.0.0</version>
        </dependency>  -->
         <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>23.0</version>
        </dependency>

        <!-- <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.9.1</version>
        </dependency> -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.3.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>5.0.8</version>
        </dependency>

        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.1.5</version>
        </dependency>

        <dependency>
            <groupId>tech.grasshopper</groupId>
            <artifactId>extentreports-cucumber6-adapter</artifactId>
            <version>2.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.14.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.14.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>4.1.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-examples -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-examples</artifactId>
            <version>4.1.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-excelant -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-excelant</artifactId>
            <version>4.1.0</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>4.1.0</version>
        </dependency>


        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
            <version>4.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-scratchpad</artifactId>
            <version>4.1.0</version>
        </dependency>


        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>9.4.1.jre8</version>
        </dependency>



        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>

        </dependency>
        <dependency>
            <groupId>com.relevantcodes</groupId>
            <artifactId>extentreports</artifactId>
            <version>2.41.2</version>
        </dependency>

        <dependency>
            <groupId>com.sikulix</groupId>
            <artifactId>sikulixapi</artifactId>
            <version>2.0.4</version>
        </dependency>



        <dependency>

            <groupId>commons-io</groupId>

            <artifactId>commons-io</artifactId>

            <version>2.5</version>

        </dependency>

        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>


    </dependencies>
    <profiles>
        <profile>
            <id>if-suite-exists</id>
            <activation>
                <property>
                    <name>!env.SUITES</name>
                </property>
            </activation>
            <properties>
                <suites>GlobalSuite</suites>
            </properties>
        </profile>
        <!-- browsers -->
        <profile>
            <id>firefox</id>
            <properties>
                <capabilities>/firefox.capabilities</capabilities>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>chrome</id>
            <properties>
                <capabilities>/chrome.capabilities</capabilities>
            </properties>
        </profile>
        <profile>
            <id>ie</id>
            <properties>
                <capabilities>/ie.capabilities</capabilities>
            </properties>
        </profile>

    </profiles>

    <properties>
        <suites>${env.SUITES}</suites>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <build>

        <resources>
            <resource>
                <directory>src/main/java/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <testResources>
            <testResource>
                <directory>src/test/java/resources</directory>
                <filtering>true</filtering>
            </testResource>
        </testResources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>

                <!--<inherited>true</inherited> -->
                <configuration>
                    <!--<testFailureIgnore>false</testFailureIgnore> -->
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/resources/suites/${suites}.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.2</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

        </plugins>
    </build>


</project>

Console Log :

Starting Windows Desktop Driver on port 9999

15:44:32 [DEBUG] Waiting for a connection...
15:44:32 [WARN] ACCEPTED EMPTY REQUEST
15:44:32 [DEBUG] Client closed

15:44:32 [DEBUG] Waiting for a connection...
15:44:32 [DEBUG] ACCEPTED REQUEST GET /status HTTP/1.1
15:44:32 [INFO] COMMAND status
{}
15:44:32 [DEBUG] RESPONSE:
OK: {
  "sessionId": "AwesomeSession",
  "status": 0,
  "value": {
    "build": {
      "version": "1.2.0.0"
    },
    "os": {
      "arch": "x64",
      "name": "windows",
      "version": "Microsoft Windows NT 6.2.9200.0"
    }
  }
}
15:44:32 [DEBUG] Client closed

15:44:32 [DEBUG] Waiting for a connection...
15:44:32 [DEBUG] ACCEPTED REQUEST POST /session HTTP/1.1
15:44:32 [INFO] COMMAND newSession
{
  "desiredCapabilities": {
    "app": "C:\\Users\\My\\Desktop\\172.20.1.4.lnk",
    "debugConnectToRunningApp": false
  },
  "capabilities": {
    "firstMatch": [
      {}
    ]
  }
}
15:44:32 [DEBUG] Current keyboard simulator: BasedOnInputSimulatorLib
15:44:32 [DEBUG] RESPONSE:
OK: {
  "sessionId": "AwesomeSession",
  "status": 0,
  "value": {
    "app": "C:\\Users\\My\\Desktop\\172.20.1.4.lnk",
    "args": "",
    "debugConnectToRunningApp": false,
    "innerPort": 9998,
    "keyboardSimulator": 1,
    "launchDelay": 0
  }
}
15:44:32 [DEBUG] Client closed

15:44:32 [DEBUG] Waiting for a connection...
Sep 28, 2022 3:44:32 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
1
15:44:43 [DEBUG] ACCEPTED REQUEST GET /status HTTP/1.1
15:44:43 [INFO] COMMAND status
{}
2
3
URL :: http://localhost:9999
15:44:43 [DEBUG] RESPONSE:
OK: {
  "sessionId": "AwesomeSession",
  "status": 0,
  "value": {
    "build": {
      "version": "1.2.0.0"
    },
    "os": {
      "arch": "x64",
      "name": "windows",
      "version": "Microsoft Windows NT 6.2.9200.0"
    }
  }
}
15:44:43 [DEBUG] Client closed

15:44:43 [DEBUG] Waiting for a connection...
15:44:43 [DEBUG] ACCEPTED REQUEST POST /session HTTP/1.1
15:44:43 [INFO] COMMAND newSession
{
  "desiredCapabilities": {
    "browserName": "MicrosoftEdge"
  },
  "capabilities": {
    "firstMatch": [
      {
        "browserName": "MicrosoftEdge"
      }
    ]
  }
}
15:44:43 [DEBUG] RESPONSE:
OK: {
  "sessionId": "AwesomeSession",
  "status": 13,
  "value": {
    "error": "unknown error",
    "stacktrace": "   at Winium.Cruciatus.Application.Start(String arguments)\r\n   at Winium.Desktop.Driver.CommandExecutors.NewSessionExecutor.InitializeApplication(Boolean debugDoNotDeploy)\r\n   at Winium.Desktop.Driver.CommandExecutors.NewSessionExecutor.DoImpl()\r\n   at Winium.Desktop.Driver.CommandExecutors.CommandExecutorBase.Do()",
    "message": "Path \"D:\\My_Workspace\\ChromeTest\" doesn't exists"
  }
}
15:44:43 [DEBUG] Client closed

15:44:43 [DEBUG] Waiting for a connection...
org.openqa.selenium.WebDriverException: Path "D:\My_Workspace\ChromeTest" doesn't exists (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 6 milliseconds
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'QAMACHINE20', ip: '172.20.1.4', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2'
Driver info: driver.version: RemoteWebDriver
Starting Microsoft Edge WebDriver 105.0.1343.25 (d3a25e9da89eba5d55f1ab48fced0ccd321e4ba8) on port 9999
To submit feedback, report a bug, or suggest new features, please visit https://github.com/MicrosoftEdge/EdgeWebDriver

Only local connections are allowed.
Please see https://aka.ms/WebDriverSecurity for suggestions on keeping Microsoft Edge WebDriver safe.

Microsoft Edge WebDriver was started successfully.
15:45:23 [DEBUG] ACCEPTED REQUEST GET /shutdown HTTP/1.1
15:45:23 [WARN] Unknown command recived: http://localhost:9999/shutdown
15:45:23 [DEBUG] Client closed

15:45:23 [DEBUG] Waiting for a connection...
@smartxel smartxel reopened this Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant