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

canopy fsx only version #148

Closed
amirrajan opened this issue Apr 24, 2014 · 21 comments
Closed

canopy fsx only version #148

amirrajan opened this issue Apr 24, 2014 · 21 comments

Comments

@amirrajan
Copy link
Collaborator

Just wanted to leave a marker open with regards to a version of canopy that can be run without Visual Studio. Here is what I have so far: https://github.com/amirrajan/canopy-fsx

If you have fsi in your PATH, you should be able to clone this repo, and just runfsi program.fsx.

@lefthandedgoat
Copy link
Owner

If you want, we can put a link to it on the main gh page?

@amirrajan
Copy link
Collaborator Author

I don't think it's ready for prime time yet. Want to get an "it just works" installation for Mono/Windows up and running. Basically someone without Visual Studio should be able to clone this repo (or download the zip) and run install.bat or install.sh. Install F# runtime and supporting updates to the PATH.

@schotime
Copy link

Could the .dll of Canopy be loaded as a dll and not fsx's?
so that in theory you could do something like.

#r canopy.dll

open canopy
start firefox

"taking canopy for a spin" &&& fun _ ->
    url "http://lefthandedgoat.github.io/canopy/testpages/"
    "#welcome" == "Welcome"
    "#firstName" == "John"

run()

or even have it so I could have a runner where I could say

canopy run test.fsx

@amirrajan
Copy link
Collaborator Author

You can use nuget.exe and install the lastest canopy. I figured that I'd just make the entire source available if you're going all FSX. The directory would be placed in the room folder and you can use the #r option like so: https://github.com/amirrajan/canopy-fsx/blob/master/canopy/runner.fsx#L6

@danuma
Copy link

danuma commented Jun 8, 2016

I have a solution with .fs files and it can be run from Visual Studio , what should i do to run from command line without changing all files into fsx.

@lefthandedgoat
Copy link
Owner

If its a console app just build and run the exe. If you want to run from
REPL it will be more work
On Jun 8, 2016 5:04 PM, "danuma" notifications@github.com wrote:

I have a solution with .fs files and it can be run from Visual Studio ,
what should i do to run from command line without changing all files into
fsx.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#148 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAsQ6XsGNNnQNQqd5ga7wSDLh-LgPZXyks5qJzx5gaJpZM4B1L5R
.

@galatrash
Copy link

I've adapted a script from fsharpforfunandprofit.com as below. You need to call as fsi --noframework Script.fsx. Here is the script file which calls your DLL and tuns it:

(* ======================================================
Use F# to run unit tests without having to install NUnit
From command line run:
  fsi --noframework Script.fsx 

In my system, fsi.exe is located here:
  C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\Fsi.exe

Adapted from the article "Low risk ways to use F# at work"
  http://fsharpforfunandprofit.com/posts/low-risk-ways-to-use-fsharp-at-work/
====================================================== *)

// sets the current directory to be same as the script directory
System.IO.Directory.SetCurrentDirectory (__SOURCE_DIRECTORY__)

// Requires Nunit.Runners under script directory 
//    nuget install NUnit.Runners -o Packages -ExcludeVersion 

#r @"..\Packages\NUnit.Runners.2.6.4\tools\lib\nunit.core.dll"
#r @"..\Packages\NUnit.Runners.2.6.4\tools\lib\nunit.core.interfaces.dll"

open System
open NUnit.Core

module Setup = 
    open NUnit.Core

    let configureTestRunner path (runner:TestRunner) = 
        let package = TestPackage("MyTestApp")
        package.Assemblies.Add(path) |> ignore
        runner.Load(package) |> ignore

    let createListener logger =
        let replaceNewline (s:string) = 
            s.Replace(Environment.NewLine, "")

        // This is an example of F#'s "object expression" syntax.
        // You don't need to create a class to implement an interface
        {new NUnit.Core.EventListener
            with
            member this.RunStarted(name:string, testCount:int) =
                logger "Run started "

            member this.RunFinished(result:TestResult ) = 
                logger ""
                logger "-------------------------------"
                result.ResultState
                |> sprintf "Overall result: %O" 
                |> logger 

            member this.RunFinished(ex:Exception) = 
                ex.StackTrace 
                |> replaceNewline 
                |> sprintf "Exception occurred: %s" 
                |> logger 

            member this.SuiteFinished(result:TestResult) = ()
            member this.SuiteStarted(testName:TestName) = ()

            member this.TestFinished(result:TestResult)=
                result.ResultState
                |> sprintf "Result: %O" 
                |> logger 

            member this.TestOutput(testOutput:TestOutput) = 
                testOutput.Text 
                |> replaceNewline 
                |> logger 

            member this.TestStarted(testName:TestName) = 
                logger ""

                testName.FullName 
                |> replaceNewline 
                |> logger 

            member this.UnhandledException(ex:Exception) = 
                ex.StackTrace 
                |> replaceNewline 
                |> sprintf "Unhandled exception occurred: %s"
                |> logger 
            }

// run all the tests in the DLL
do 
    // replace with the DLL that is created by your code with proper path
    let dllPath = @".\bin\debug\MyTestApp.dll"
    CoreExtensions.Host.InitializeService();
    use runner = new NUnit.Core.SimpleTestRunner()
    Setup.configureTestRunner dllPath runner
    let logger = printfn "%s"
    let listener = Setup.createListener logger
    let result = runner.Run(listener, TestFilter.Empty, true, LoggingThreshold.All)

    // if running from the command line, wait for user input
    Console.ReadLine() |> ignore

@danuma
Copy link

danuma commented Jun 8, 2016

Thank you for the reply. Yes i did execute the exe but I am trying to do it through a script fsx file. My tests are in tests.fs and im running run() them from Program.fs . Now , I want to create a script and run it with F# interactive. Do you have any example code in this kind of scenario.

@danuma
Copy link

danuma commented Jun 8, 2016

Thank you . I will try this.

@galatrash
Copy link

AFAIK, .fs files can't be run interactively; they need to be compiled in an exe or dll to be executed.

@vbop9834
Copy link
Collaborator

vbop9834 commented Dec 21, 2016

.fs files can be executed interactively in a .fsx file by loading the .fs file as a dependency in the script

Place the script script.fsx in the same folder as Program.fs

#I __SOURCE_DIRECTORY__
#load "Program.fs"

//Load canopy here as well
#I "path_to_directory_containing_canopy_dll"
#I "path_to_directory_containing_webdriver_dll"
#r "canopy.dll"
#r "WebDriver.dll"

open canopy
open YourNamespace.ProgramModule

run ()

@navmed
Copy link
Contributor

navmed commented Dec 29, 2016

I'm trying to run this: https://github.com/amirrajan/canopy-demo/blob/master/LightingTalk/Sandbox.fsx from the same project. It used to work fine, but it looks like a chrome or chromedriver update broke it. Now I get:

OpenQA.Selenium.WebDriverException: A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:58450/session/5c27d8a2d45c51d7853215774bdb82c7/window/current/size. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

@lefthandedgoat
Copy link
Owner

https://github.com/amirrajan/canopy-demo/blob/master/LightingTalk/Sandbox.fsx#L2-L3

Looks like its using an older version of Selenium. Update that to the latest, with latest chrome and chrome driver and it should work.

@navmed
Copy link
Contributor

navmed commented Dec 29, 2016

I've updated Selenium.Webdriver and Selenium,Support to 3.0.0, ChromeDriver updated to 2.2.7, Canopy to 1.0.6. This is my current fsx file and I've double-checked to make sure the references are pointing to the right versions.

#I @"C:\Projects\CanopyFalcon\packages\Selenium.WebDriver.3.0.0\lib\net40\"
#I @"C:\Projects\CanopyFalcon\packages\Selenium.Support.3.0.0\lib\net40\"
#I @"C:\CanopyPackages\SizSelCsZzz.0.3.36.0\lib\"
#I @"C:\CanopyPackages\Newtonsoft.Json.6.0.8\lib\net40\"
#I @"C:\Projects\CanopyFalcon\packages\canopy.1.0.6\lib"

#r "WebDriver.Support.dll"
#r "WebDriver.dll"
#r @"C:\Projects\CanopyFalcon\packages\canopy.1.0.6\lib\canopy.dll"

open canopy
open runner
//open OpenQA.Selenium

start chrome

I still get the same error.

@lefthandedgoat
Copy link
Owner

Can you clone this and see if it works for you?

https://github.com/lefthandedgoat/canopyStarterKit

run build.cmd from the root folder

@lefthandedgoat
Copy link
Owner

lefthandedgoat commented Dec 29, 2016

BTW this works for me

#I @"C:\projects\fsxCanopy\packages\Selenium.WebDriver.3.0.0\lib\net40\"
#I @"C:\projects\fsxCanopy\packages\canopy.1.0.6\lib"

#r "WebDriver.dll"
#r "canopy.dll"
    

open canopy
open runner
//open OpenQA.Selenium

start chrome

quit()
--> Referenced 'C:\Projects\fsxCanopy\packages\Selenium.WebDriver.3.0.0\lib\net40\WebDriver.dll'

> 

--> Referenced 'C:\Projects\fsxCanopy\packages\canopy.1.0.6\lib\canopy.dll'

> 
> 
Binding session to 'C:\Projects\fsxCanopy\packages\Selenium.WebDriver.3.0.0\lib\net40\WebDriver.dll'...
Starting ChromeDriver 2.25.426923 (0390b88869384d6eb0d5d09729679f934aab9eed) on port 53173
Only local connections are allowed.
val it : unit = ()

Also for latest chrome driver:

Starting ChromeDriver 2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9) on port 53235
Only local connections are allowed.
val it : unit = ()
> 
val it : unit = ()

@lefthandedgoat
Copy link
Owner

Did you put your chrome driver in root c:\ (thats the default location)

@navmed
Copy link
Contributor

navmed commented Dec 30, 2016

It was the last thing - I had a chromedriver.exe in c:\ AND in bin/debug for some reason. I had updated the one in bin/debug but it was using the one in the c:\ . Once I updated the one in c:\ it started working. Thank you some much for your help!

@vbop9834
Copy link
Collaborator

Insert this line of code in your script right before start chrome or run ()

canopy.configuration.chromeDir <- __SOURCE_DIRECTORY__

The above code looks for the chromedriver in the same folder as the script.

@navmed
Copy link
Contributor

navmed commented Dec 30, 2016

Thanks Jeremy, that's good info to have.

@vbop9834
Copy link
Collaborator

Anytime! 😀

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

No branches or pull requests

7 participants