Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Add ability to test app using selenium #90

Closed
vidmed opened this issue Mar 28, 2018 · 5 comments
Closed

Add ability to test app using selenium #90

vidmed opened this issue Mar 28, 2018 · 5 comments
Assignees

Comments

@vidmed
Copy link
Contributor

vidmed commented Mar 28, 2018

In the current implementation of go-astilectron there is no way to test application via selenium.
What is happening now:

  • TCP server starts and wait for connections.
  • You start electron command which starts astilectron. Then astilectron connects to the TCP server.
    The idea is add some test flag and when it is set the logic will be:
  • TCP server starts and wait for connections.
  • We don't start astilectron. Instead of that we create some bash file containing the command that runs astilectron. So.etching like
    electron /path/to/astilectron/main.js 127.0.0.1:1111 flags
    After that we will have ability to start selenium web driver using this bash file. When the driver starts and bash file executes TCP connection accepts and the app starts in normal way.
    Actually in this way we are testing our app which uses astilectron.
    What do you think about that?
@asticode
Copy link
Owner

asticode commented Mar 29, 2018

@vidmed I'm not familiar with Selenium therefore I can't say what's the best approach to test an astilectron app with it. However if what you're saying is true, this is totally feasible, the only downside being you won't be able to captur stdout/stderr in GO anymore but I guess you'll be able to capture both of them in Selenium so this should be fine.

My first instinct would be to do the following:

  • add an Executer type like this:
type Executer func(a *astilectron.Astilectron, cmd *exec.Cmd)
  • add a DefaultExecuter that would be:
func(a *astilectron.Astilectron, cmd *exec.Cmd) {
    // Start command
    astilog.Debugf("Starting cmd %s", strings.Join(cmd.Args, " "))
    if err = cmd.Start(); err != nil {
        err = errors.Wrapf(err, "starting cmd %s failed", strings.Join(cmd.Args, " "))
        return
    }

    // Watch command
    go a.watchCmd(cmd)
}
  • add an executer attribute of type Executer to Astilectron that would default to DefaultExecuter and a developer could set with a method SetExecuter
  • this Executer would be called in executeCmd like this:
func (a *Astilectron) executeCmd(cmd *exec.Cmd) (err error) {
	var e = synchronousFunc(a.canceller, a, func() {
		a.executer(a, cmd)
	}, EventNameAppEventReady)

	// Update display pool
	if e.Displays != nil {
		a.displayPool.update(e.Displays)
	}
	return
}

What do you think? Did you have something else in mind?

If this sounds fine, would you be willing to do a PR?

Cheers

@vidmed
Copy link
Contributor Author

vidmed commented Mar 29, 2018

Yeah, that is really cool.
Also I would like this interval
go a.watchNoAccept(30*time.Second, chanAccepted)
in istenTCP method to be configurable by user. Sometimes we have to wait more than 30 seconds for tcp connections. and hardcoding this inteval is not very good for me.
After your answer I`ll start realisation and send a PR

@asticode
Copy link
Owner

sure, you can add it in the Options. Don't forget to add a default value in the New function though. I look forward to reviewing your PR.

@vidmed
Copy link
Contributor Author

vidmed commented Mar 29, 2018

@asticode view my PR please
#91

@chinenual
Copy link

@vidmed - this PR appears to have added support for testing astilectron applications via Selenium but I'm not clear what needs to be done to actually use Selenium.

Do you have an example project or short README that explains what needs to be configured on the astillectron side and how you have configured Selenium on the test harness side?

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants