lefthandedgoat / canopy

f# web automation and testing library, built on top of Selenium (friendly to c# also)
http://lefthandedgoat.github.io/canopy/
MIT License
505 stars 117 forks source link

Default Reporter no longer working due to GitHub subdomain deprecation #515

Closed jamesaslett1985 closed 3 years ago

jamesaslett1985 commented 3 years ago

Description

The default reporter (https://lefthandedgoat.github.com/canopy/reporttemplatep.html) no longer works as GitHub have deprecated subdomains as of 15/04/21 - see https://github.blog/changelog/2021-01-29-github-pages-will-stop-redirecting-pages-sites-from-github-com-after-april-15-2021/

Untitled

lefthandedgoat commented 3 years ago

Thanks I will work on fixing this and releasing a new build

lefthandedgoat commented 3 years ago

Until I get a build out for this, you can set the property here:

https://github.com/lefthandedgoat/canopy/blob/master/src/canopy/reporters.fs#L238

http://lefthandedgoat.github.io/canopy/reporttemplatep.html is the working address

lefthandedgoat commented 3 years ago

Here is a way to set the value:

let htmlReporter = new LiveHtmlReporter(Chrome, chromeDir)
htmlReporter.reportTemplateUrl <- "http://lefthandedgoat.github.io/canopy/reporttemplatep.html"
reporter <- htmlReporter :> IReporter
fischgeek commented 3 years ago

Here is a way to set the value:

let htmlReporter = new LiveHtmlReporter(Chrome, chromeDir)
htmlReporter.reportTemplateUrl <- "http://lefthandedgoat.github.io/canopy/reporttemplatep.html"
reporter <- htmlReporter :> IReporter

@lefthandedgoat, After doing this, my HTML report page doesn't update; only the console has the output. The html report has the elements but all are zero.

lefthandedgoat commented 3 years ago

@fischgeek can you share a snippet of your code and a screenshot?

fischgeek commented 3 years ago

Sure. It's just two of the defaults from the Getting Started page.

namespace CanopyTestingScoreboards

open canopy.runner.classic
open canopy.configuration
open canopy.classic
open canopy.configuration
open canopy.reporters
open canopy.types
open canopy

module CanopyTestingScoreboards = 
    [<EntryPoint>]
    let main argv =
        canopy.configuration.chromeDir <- System.AppContext.BaseDirectory

        //reporter <- new reporters.LiveHtmlReporter(BrowserStartMode.Chrome, System.Environment.CurrentDirectory) :> IReporter

        let htmlReporter = new LiveHtmlReporter(Chrome, chromeDir)
        htmlReporter.reportTemplateUrl <- "http://lefthandedgoat.github.io/canopy/reporttemplatep.html"
        reporter <- htmlReporter :> IReporter

        //start an instance of chrome
        start chrome

        "taking canopy for a spin" &&& fun _ ->
            //this is an F# function body, it's whitespace enforced

            //go to url
            url "http://lefthandedgoat.github.io/canopy/testpages/"

            //assert that the element with an id of 'welcome' has
            //the text 'Welcome'
            "#welcome" == "Welcome"

            //assert that the element with an id of 'firstName' has the value 'John'
            "#firstName" == "John"

            //change the value of element with
            //an id of 'firstName' to 'Something Else'
            "#firstName" << "Something Else"

            //verify another element's value, click a button,
            //verify the element is updated
            "#button_clicked" == "button not clicked"
            click "#button"
            "#button_clicked" == "button clicked"
        "taking canopy for a spin 2" &&& fun _ ->
            //this is an F# function body, it's whitespace enforced

            //go to url
            url "http://lefthandedgoat.github.io/canopy/testpages/"

            //assert that the element with an id of 'welcome' has
            //the text 'Welcome'
            "#welcome" == "Welcome"

            //assert that the element with an id of 'firstName' has the value 'John'
            "#firstName" == "John"

            //change the value of element with
            //an id of 'firstName' to 'Something Else'
            "#firstName" << "fischgeek"

            //verify another element's value, click a button,
            //verify the element is updated
            "#button_clicked" == "button not clicked"
            click "#button"
            "#button_clicked" == "button clicked"

        //run all tests
        run()
        printfn "press [enter] to exit"
        System.Console.ReadLine() |> ignore
        quit()
        0

https://www.dropbox.com/s/zz8w3iaq5v5a9ss/2021-06-10_14-29-15.png?raw=1

lefthandedgoat commented 3 years ago

@fischgeek Ah yes there is a subtle bug/issue where if you don't have a test context for your tests I guess the html reporter does not work correctly.

Add this above start chrome

context "canopy example"

That will make the #s correct

fischgeek commented 3 years ago

Thanks! I'll follow up later!

fischgeek commented 3 years ago

Working with the added context line. Thanks!

manishdube commented 3 years ago

` namespace Main

module Program =

open canopy.runner.classic
open canopy.configuration
open canopy.classic
open canopy.reporters
open canopy.types

open System
open TestRunner
open ArguParser

[<EntryPoint>]
let main argv =
    // Parse all the args into the types that we use in the rest of the code
    let args = Args.parse argv

    let reportPath = sprintf "%s" <| Common.Functions.getLogDirectory ()
    let driverPath = Common.Functions.getDriverDirectory ()

    let chromeOptions = OpenQA.Selenium.Chrome.ChromeOptions ()
    let ffOptions = OpenQA.Selenium.Firefox.FirefoxOptions ()

    /// Set timeout used by selenium during test runs
    elementTimeout <- 30.0
    compareTimeout <- 30.0

    /// If "stop" then skip remaining tests on failure
    skipRemainingTestsInContextOnFailure <- 
        match args.ContinueOnFailure with
        | Common.Types.ContinueOnFailure.Stop -> true
        | Common.Types.ContinueOnFailure.Continue -> false

    /// Screenshots are enabled on failure for enabled mode and failonly
    failureScreenshotsEnabled <- 
        match args.Screenshot with
        | Common.Types.Screenshot.Enabled 
        | Common.Types.Screenshot.OnFailOnly -> true
        | Common.Types.Screenshot.Disabled -> false

    /// Assign driver paths
    firefoxDriverDir <- driverPath
    edgeDir <- driverPath
    chromeDir <- driverPath     

    /// Set up the reporter based on the CLI arguments
    reporter <- 
        match args.LogOutput with
        | Common.Types.LogOutput.Console -> 
            ConsoleReporter() :> IReporter     
        | Common.Types.LogOutput.TeamCity ->
            TeamCityReporter() :> IReporter       
        | Common.Types.LogOutput.File -> 
            /// Set up file reporter options for different browsers
            match args.Browser with
            | canopy.types.BrowserStartMode.Chrome 
            | canopy.types.BrowserStartMode.ChromeHeadless ->    
                chromeOptions.AddAdditionalCapability ("useAutomationExtension", false)
            | canopy.types.BrowserStartMode.Firefox
            | canopy.types.BrowserStartMode.FirefoxHeadless -> 
                ffOptions.SetPreference ("dom.disable_beforeunload", true)
            | canopy.types.BrowserStartMode.EdgeBETA -> ()
            | _ -> failwith "Unsupported browser option."

            let reporter' = canopy.reporters.LiveHtmlReporter (args.Browser, driverPath) 
            reporter'.reportPath <- Some(reportPath)               
            reporter' :> IReporter

    /// Define the environment based on the CLI arguments
    reporter.setEnvironment <| 
        match args.Environment with
        | Common.Types.Environment.Debug -> "TEST"
        | Common.Types.Environment.Release -> "RELEASE"

    /// Register the tests for the engine to run based on the CLI arguments
    RegisterTests.register args.Tag args.TestType

    /// Start the browser with the options as needed
    canopy.classic.start <|
        match args.Browser with
        | canopy.types.BrowserStartMode.Firefox -> 
            FirefoxWithOptions ffOptions
        | canopy.types.BrowserStartMode.Chrome -> 
            ChromeWithOptions chromeOptions
        | canopy.types.BrowserStartMode.FirefoxHeadless -> 
            ffOptions.AddArgument "--headless"
            FirefoxWithOptions ffOptions
        | canopy.types.BrowserStartMode.ChromeHeadless -> 
            chromeOptions.AddArgument "--headless"
            ChromeWithOptions chromeOptions
        | canopy.types.BrowserStartMode.EdgeBETA -> 
            EdgeBETA           
        | _ -> 
            failwith "Unsupported browser option."

    /// Maximize the running browser window (optional)
    browser.Manage().Window.Maximize()

    /// Run tests
    canopy.runner.classic.run ()

    /// Quit all browsers
    canopy.classic.quit ()

    /// Return code
    canopy.runner.classic.failedCount`
manishdube commented 3 years ago

where do i insert the fix to make the above work. suggested fix below:

let htmlReporter = new LiveHtmlReporter(Chrome, chromeDir) htmlReporter.reportTemplateUrl <- "http://lefthandedgoat.github.io/canopy/reporttemplatep.html" reporter <- htmlReporter :> IReporter

manishdube commented 3 years ago

says "Error FS0001 All branches of a pattern match expression must return values of the same type as the first branch, which here is 'IReporter'. This branch returns a value of type 'unit'. GenesisTestFramework C:\Users\manish.dube\Documents\src\IntegrationTesting\GenesisTestFramework\GenesisTestFramework\Program.fs 76 Active "

manishdube commented 3 years ago

` let reporter' = canopy.reporters.LiveHtmlReporter (args.Browser, driverPath) //reporter'.reportPath <- Some(reportPath)
//reporter' :> IReporter

            //let htmlReporter = new LiveHtmlReporter(Chrome, chromeDir)
            let htmlReporter = new LiveHtmlReporter(args.Browser, driverPath)

            htmlReporter.reportTemplateUrl <- "http://lefthandedgoat.github.io/canopy/reporttemplatep.html"
            reporter' <- htmlReporter :> IReporter`
lefthandedgoat commented 3 years ago

@manishdube I believe you want to change this part:

            let reporter' = canopy.reporters.LiveHtmlReporter (args.Browser, driverPath) 
            reporter'.reportPath <- Some(reportPath)               
            reporter' :> IReporter

to

            let reporter' = canopy.reporters.LiveHtmlReporter (args.Browser, driverPath) 
            reporter'.reportPath <- Some(reportPath)      
            reporter'.reportTemplateUrl <- "http://lefthandedgoat.github.io/canopy/reporttemplatep.html"         
            reporter' :> IReporter
manishdube commented 3 years ago

Works !!