Skip to content

Instantly share code, notes, and snippets.

View abhinaba-ghosh's full-sized avatar

Abhinaba Ghosh abhinaba-ghosh

View GitHub Profile
@abhinaba-ghosh
abhinaba-ghosh / detect-playwright.js
Last active June 14, 2020 07:59
playwright detect browser and os settings using userAgent
const uaParser = require('ua-parser-js');
const playwright = require('playwright');
const expect = require('chai').expect;
let userAgentInfo;
let browser;
describe('Test browser information', () => {
before(async () => {
browser = await playwright['chromium'].launch();
node {
TESTCAFE_DOCKER_PATH = 'docker/Dockerfile'
}
pipeline {
agent {
dockerfile {
filename "${TESTCAFE_DOCKER_PATH}"
args '--net=host -e DISPLAY=":0"'
FROM testcafe/testcafe
# See https://github.com/DevExpress/testcafe/tree/master/docker
# We need root privileages to install new deps:
USER root
ENV LANG C.UTF-8
# add a simple script that can auto-detect the appropriate JAVA_HOME value
describe('It should validate cypress react selector', () => {
before(() => {
cy.visit('https://ahfarmer.github.io/calculator/');
cy.waitForReact();
});
it('should calculate 7 * 6', () => {
cy.react('t', { name: '7' }).click();
cy.react('t', { name: 'x' }).click();
cy.react('t', { name: '6' }).click();
/// <reference types="cypress" />
import 'cypress-react-selector'
import { mount } from 'cypress-react-unit-test'
import React from 'react'
import ProductsList from './ProductsList.jsx'
// test similar to
// https://github.com/softchris/react-book/blob/7bd767bb39f59977b107d07f383a8f4e32a12857/Testing/test-demo/src/Components/__tests__/ProductsList.js
it('renders without crashing', () => {
cy.stub(window, 'fetch')
import React from 'react'
import { getProducts } from '../products'
class AProduct extends React.Component {
constructor(props) {
super(props)
this.state = {
name: props.name,
}
}
before(() => {
cy.visit('/');
cy.waitForReact();
});
it('enter data into the fields', () => {
cy.react('MyTextInput', { field: { name: 'email' } }).type('bugs.bunny@test.com');
cy.react('MyTextInput', { field: { name: 'password' } }).type('SUPER SECRET STUFFZ');
});
import React, { useState } from "react";
import { Formik, Field, Form, ErrorMessage } from "formik";
const MyTextInput = (props) => {
const { field, type } = props;
return <input {...field} type={type} placeholder={field.name} />;
};
function App() {
import React, { useState } from "react";
import { Formik, Field, Form, ErrorMessage } from "formik";
const MyTextInput = (props) => {
const { field, type } = props;
return <input {...field} type={type} placeholder={field.name} />;
};
function App() {
interface Chainable {
/**
* Get react elements by component, props and states
* @see https://github.com/abhinaba-ghosh/cypress-react-selector/blob/master/cypress/integration/react-selector.spec.js
* @example
* cy.react(`MyComponent`).should('have.length', 10)
* cy.react('MyComponent',{name:'Bill'}).should('have.length', 1)
*/
react(component: string, props?: {}, state?: {}): Chainable<any>;