Coder Social home page Coder Social logo

martincostello / browserstack-automate Goto Github PK

View Code? Open in Web Editor NEW
8.0 6.0 6.0 3.23 MB

.NET client for the BrowserStack Automate REST API

Home Page: https://martincostello.github.io/browserstack-automate/

License: Apache License 2.0

C# 96.83% PowerShell 3.17%
browserstack browserstack-automate dotnet-core

browserstack-automate's Introduction

Alt text BrowserStack Automate REST API .NET Client

NuGet

Build Status

Build status codecov OpenSSF Scorecard

Overview

This repository contains a .NET client library/NuGet package for the BrowserStack Automate REST API.

Features include:

  • Querying the status of a BrowserStack Automate plan.
  • Querying the available browsers.
  • Querying and deleting builds.
  • Querying and deleting projects.
  • Querying and deleting sessions.
  • Querying session log.
  • Setting the status of a session.
  • Regenerating the API access key.

The assembly supports .NET Standard 2.0.

Installation

dotnet add package MartinCostello.BrowserStack.Automate

Usage Examples

The following example shows a custom xUnit.net [Fact] that checks for an available BrowserStack Automate session before running the test, otherwise it is skipped.

namespace MyApp.Tests;

using MartinCostello.BrowserStack.Automate;
using Xunit;

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class RequiresBrowserStackAutomateAttribute : FactAttribute
{
    public RequiresBrowserStackAutomateAttribute()
    {
        var userName = Environment.GetEnvironmentVariable("BrowserStack_UserName");
        var accessKey = Environment.GetEnvironmentVariable("BrowserStack_AccessKey");

        if (userName is not null && accessKey is not null)
        {
            using var client = new BrowserStackAutomateClient(userName, accessKey);
            var plan = client.GetStatusAsync().Result;

            if (plan.MaximumAllowedParallelSessions < 1 ||
                plan.ParallelSessionsRunning == plan.MaximumAllowedParallelSessions)
            {
                Skip = "No BrowserStack Automate sessions are currently available.";
            }
        }
        else
        {
            Skip = "No BrowserStack Automate credentials are available.";
        }
    }
}

Feedback

Any feedback or issues can be added to the issues for this project in GitHub.

Repository

The repository is hosted in GitHub: https://github.com/martincostello/browserstack-automate.git

License

This project is licensed under the Apache 2.0 license.

Building and Testing

To build and test the assembly run one of the following set of commands:

$env:BrowserStack_UserName  = "MyUserName"
$env:BrowserStack_AccessKey = "MyAccessKey"
./build.ps1

If you do not have a BrowserStack Automate access key you can still just run the build script and the integration tests that require credentials will be skipped.

browserstack-automate's People

Contributors

costellobot avatar costellobot[bot] avatar dependabot-preview[bot] avatar dependabot[bot] avatar martincostello avatar tompoole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

browserstack-automate's Issues

Verify API surface

After the changes made in #19, need to set up a new trial account and push some tests into it to check the responses from the API match the updated implementation before releasing it.

Hopefully everything is lined up (again) and the v3.0.0 can be published to NuGet.

How to get console logs?

Thanks for the tool! I'm trying it out as a way to get console and network logs, however, when I run it, I get 0 logs back. Do you have an idea what I'm missing?

// my driver
driver.Navigate().GoToUrl("www.google.com");


// get the session details
    Object sessionObject = ((IJavaScriptExecutor)driver).ExecuteScript(
        "browserstack_executor: {\"action\": \"getSessionDetails\"}"
    );
    // convert Object to String for parsing
    string json_resp = Convert.ToString(sessionObject);
    // parse the data
    var session_details = JObject.Parse(json_resp);
    // print the session ID on IDE's console
    Console.WriteLine(session_details["hashed_id"]);
    Console.WriteLine(session_details["build_hashed_id"]);

    var client = new BrowserStackAutomateClient(
        options.BrowserStackCredentials.UserName,
        options.BrowserStackCredentials.AccessKey
    );

    var sessionLogs = await client.GetSessionLogsAsync(
        session_details.Value<string>("build_hashed_id"),
        session_details.Value<string>("hashed_id")
    );

    Console.WriteLine(sessionLogs.Length);
    Console.Write(sessionLogs);

    var consoleLogs = await client.GetSessionConsoleLogsAsync(
        session_details.Value<string>("build_hashed_id"),
        session_details.Value<string>("hashed_id")
    );

    Console.WriteLine(consoleLogs.Length);
    Console.Write(consoleLogs);

    var networkLogs = await client.GetSessionNetworkLogsAsync(
        session_details.Value<string>("build_hashed_id"),
        session_details.Value<string>("hashed_id")
    );
    Console.WriteLine(networkLogs.Length);
    Console.Write(networkLogs);

The consoles are always printing 0 results, even though I have many messages in the BrowserStack ui.

For example, here's a session and build id:

a1cb599c1a1498b081229a271f00d94f7ae92551
8ecf06089577022d4d70ca6c33acaef98ab895ca

And here is what I see in BrowserStack:

image

image

I'm sure I'm missing something dumb in my command the get the logs :)

Thanks!

Deserialization no longer works due to API response shape change

The API used to return results similar to:

[
  {
    "item": {
    }
  },
  {
    "item": {
    }
  }
]

It has been changed, without any request versioning, to:

[
  {
  },
  {
  }
]

A major version (3.0.0) needs to be published to remove these "item" types to flatten the response hierarchy so serialization works again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.