Coder Social home page Coder Social logo

muhammad-mahir157 / automation-using-codecept-and-jest Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 10.94 MB

Automating MetaBase using CodeceptJS and Jest

TypeScript 4.57% Gherkin 5.82% JavaScript 58.49% CSS 18.38% HTML 12.68% Shell 0.06%
automation codeceptjs jest metabase pupeeter

automation-using-codecept-and-jest's Introduction

UI Automation In Metabase:

Entity Loaders: Metabase frontend uses Entity Loaders in their framework. Entity loaders are used to abstract away calling the API, handling loading and error state, cache previously loaded objects, invalidating the cache (in some cases) and let you easily perform updates, or create new items. Metabase used entity loaders to create their new features and also helful in loading certain data on the frontend. For example below code is going to load information about a specific database for a new page.

import React from "react";
import Databases from "metabase/entities/databases";

@Databases.load({ id: 4 })
class MyNewPage extends React.Component {
  render() {
    const { database } = this.props;
    return (
    );
  }
}

Forms Framework: Metabase used custom React and reduc-form library in their frontend. This is a helpful library used for creating and validating different in UI. For example in below code name and password field is validated using validate API.

import Form, { FormField, FormFooter } from "metabase/containers/Form";

<Form onSubmit={values => alert(JSON.stringify(values))}>
  <FormField
    name="email"
    placeholder="[email protected]"
    validate={validate.required()}
  />
  <FormField
    name="password"
    type="password"
    validate={validate.required().passwordComplexity()}
  />
  <FormFooter />
</Form>;

Api Automation In Metabase:

The API is tightly coupled with the front end and is subject to change between releases, it can change version to version. So that's the reason you have to change code of API of Metabase after every update. Metabase API accepts the HTTP verbs and parameters. Following is the framework that how metabase API interaction takes place:

Authentication: The authentication end point is POST /api/session, which accepts a username and password. The response will be a JSON dict with an id key {"id": "abcd"} where the value is the session key.

let response = await got.post("http://localhost:3000/api/session", {
  json: { username: "[email protected]", password: "database1" },
  responseType: "json",
});
session_id = response.body.id;
headers = { "X-Metabase-Session": session_id };

Getting Data: To retrieve data we use GET /api/database. You can easily extract data according to your requirements in CSV, JSON, XLSX. You have to provide filter according to the way you want your data.For example to get results as CSV, send to /api/dataset/csv, for JSON /api/dataset/json, for XLSX /api/dataset/xlsx.

response = await got.get("http://localhost:3000/api/card", {
  responseType: "json",
  headers: headers,
});
// filter for public questions
questions = response.body.filter((q) => q.public_uuid);
console.log(`${questions.length} public of ${response.body.length} questions`);

automation-using-codecept-and-jest's People

Contributors

m-mahad12 avatar mohamad-hammad avatar muhammad-mahir157 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.