Preparation for testing. Add tests for issue 1599. (#1983)

* Automate test preparation(mandatory operations for each test cases)

- Add test for creating an annotation task.
- Add automate for creating superuser.

* Add tests for issue 1599.

* Run Cypress from Travis CI.

Remove Cypress installation command from Dockerfile.ci
Remove the unnecessary docker-compose.ci.yml

* Replase image for creation an annotation task.

Change name of imsge in the Cypress test create_new_task.js

* Temporarily deleting the annotation task creation functionality

* Image generarion functionality

Add Cypress module for auto generation images
Add package files.

* Add custome commands for create an annotation task and a shape.

* Applying comments.

* /tasks instead of /task in the tests (applying comments)

Co-authored-by: Dmitry Kruchinin <dmitryx.kruchinin@intel.com>
main
Dmitry Kruchinin 6 years ago committed by GitHub
parent d6ca864d51
commit ca4b320d23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,12 +5,29 @@ language: python
python:
- "3.5"
cache:
npm: true
directories:
- ~/.cache
addons:
apt:
packages:
- libgconf-2-4
services:
- docker
env:
- CONTAINER_COVERAGE_DATA_DIR="/coverage_data"
HOST_COVERAGE_DATA_DIR="${TRAVIS_BUILD_DIR}"
DJANGO_SU_NAME="admin"
DJANGO_SU_EMAIL="admin@localhost.company"
DJANGO_SU_PASSWORD="12qwaszx"
NODE_VERSION="12"
before_install:
- nvm install ${NODE_VERSION}
before_script:
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml build
@ -20,8 +37,13 @@ script:
# FIXME: Git package and application name conflict in PATH and try to leave only one python test execution
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'coverage run -a manage.py test cvat/apps && coverage run -a manage.py test --pattern="_test*.py" cvat/apps/dataset_manager/tests cvat/apps/engine/tests utils/cli && coverage run -a manage.py test datumaro/ && mv .coverage ${CONTAINER_COVERAGE_DATA_DIR}'
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'cd cvat-data && npm install && cd ../cvat-core && npm install && npm run test && coveralls-lcov -v -n ./reports/coverage/lcov.info > ${CONTAINER_COVERAGE_DATA_DIR}/coverage.json'
# Run cypress tests
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'cd ~/tests && ./node_modules/.bin/cypress run --headless --browser chrome --config-file=cypress_ci.json'
# Up all containers
- docker-compose up -d
# Create superuser
- docker exec -it cvat bash -ic "echo \"from django.contrib.auth.models import User; User.objects.create_superuser('${DJANGO_SU_NAME}', '${DJANGO_SU_EMAIL}', '${DJANGO_SU_PASSWORD}')\" | python3 ~/manage.py shell"
# Install Cypress and run tests
- cd ./tests && npm install
- $(npm bin)/cypress run --headless --browser chrome && cd ..
after_success:
# https://coveralls-python.readthedocs.io/en/latest/usage/multilang.html

@ -14,7 +14,6 @@ RUN curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - &
nodejs \
python3-dev \
ruby \
xvfb \
&& \
rm -rf /var/lib/apt/lists/*;
@ -24,10 +23,4 @@ RUN gem install coveralls-lcov
COPY .coveragerc .
# RUN all commands below as 'django' user
USER ${USER}
RUN mkdir -p tests && cd tests && CI=true npm install cypress; \
echo "export PATH=~/tests/node_modules/.bin:${PATH}" >> ~/.bashrc;
ENTRYPOINT []

@ -1,3 +1,10 @@
{
"baseUrl": "http://localhost:8080"
"video": false,
"baseUrl": "http://localhost:8080",
"viewportWidth": 1300,
"viewportHeight": 960,
"testFiles": [
"auth_page.js",
"issue_*.js"
]
}

@ -7,27 +7,27 @@
/// <reference types="cypress" />
describe('Check server availability', () => {
it('Server web interface is available', () => {
cy.visit('/')
})
it('Server web interface is available', () => {
cy.visit('/')
})
it('"/auth/login" contains in the URL', () => {
cy.url().should('include', '/auth/login')
})
it('"/auth/login" contains in the URL', () => {
cy.url({ timeout: 8000 }).should('include', '/auth/login')
})
it('"Sign in" button is exists', () => {
cy.get('[type="submit"]')
})
it('"Sign in" button is exists', () => {
cy.get('[type="submit"]')
})
it('Check plaseholder "Username"', () => {
cy.get('input').invoke('attr', 'placeholder').should('contain', 'Username')
})
it('Check placeholder "Username"', () => {
cy.get('input').invoke('attr', 'placeholder').should('contain', 'Username')
})
it('Check plaseholder "Password"', () => {
cy.get('[type="password"]')
})
it('Check placeholder "Password"', () => {
cy.get('[type="password"]')
})
it('Click to "Sign in" button', () => {
cy.get('[type="submit"]').click()
})
it('Click to "Sign in" button', () => {
cy.get('[type="submit"]').click()
})
})

@ -0,0 +1,50 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/
/// <reference types="cypress" />
context('Issue 1599 (Chinese alphabet).', () => {
before(() => {
cy.visit('auth/register')
cy.url().should('include', '/auth/register')
})
describe('User registration using the Chinese alphabet.', () => {
it('Filling in the placeholder "First name"', () => {
cy.get('[placeholder="First name"]').type('测试者')
.should('not.have.class', 'has-error')
})
it('Filling in the placeholder "Last name"', () => {
cy.get('[placeholder="Last name"]').type('测试')
.should('not.have.class', 'has-error')
})
it('Filling in the placeholder "Username"', () => {
cy.get('[placeholder="Username"]').type('Testuser_ch')
})
it('Filling in the placeholder "Email address"', () => {
cy.get('[placeholder="Email address"]').type('Testuser_ch@local.local')
})
it('Filling in the placeholder "Password"', () => {
cy.get('[placeholder="Password"]').type('Qwerty123!')
})
it('Filling in the placeholder "Confirm password"', () => {
cy.get('[placeholder="Confirm password"]').type('Qwerty123!')
})
it('Click to "Submit" button', () => {
cy.get('[type="submit"]').click()
})
it('Successful registration', () => {
cy.url().should('include', '/tasks')
})
})
})

@ -0,0 +1,50 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/
/// <reference types="cypress" />
context('Issue 1599 (Polish alphabet).', () => {
before(() => {
cy.visit('auth/register')
cy.url().should('include', '/auth/register')
})
describe('User registration using the Polish alphabet.', () => {
it('Filling in the placeholder "First name"', () => {
cy.get('[placeholder="First name"]').type('Świętobor')
.should('not.have.class', 'has-error')
})
it('Filling in the placeholder "Last name"', () => {
cy.get('[placeholder="Last name"]').type('Сzcić')
.should('not.have.class', 'has-error')
})
it('Filling in the placeholder "Username"', () => {
cy.get('[placeholder="Username"]').type('Testuser_pl')
})
it('Filling in the placeholder "Email address"', () => {
cy.get('[placeholder="Email address"]').type('Testuser_pl@local.local')
})
it('Filling in the placeholder "Password"', () => {
cy.get('[placeholder="Password"]').type('Qwerty123!')
})
it('Filling in the placeholder "Confirm password"', () => {
cy.get('[placeholder="Confirm password"]').type('Qwerty123!')
})
it('Click to "Submit" button', () => {
cy.get('[type="submit"]').click()
})
it('Successful registration', () => {
cy.url().should('include', '/tasks')
})
})
})

@ -0,0 +1,31 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/
exports.imageGenerator = imageGenerator
const jimp = require('jimp')
const path = require('path')
function imageGenerator(args) {
const directory = args.directory
const fileName = args.fileName
const width = args.width
const height = args.height
const color = args.color
const posX = args.posX
const posY = args.posY
const message = args.message
const file = path.join(directory, fileName)
const image = new jimp(width, height, color, function (err, image) {
if (err) throw err
jimp.loadFont(jimp.FONT_SANS_64_BLACK, function (err, font) {
if (err) throw err
image.print(font, Number(posX), Number(posY), message)
.write(file)
})
})
return file
}

@ -0,0 +1,25 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/
Cypress.Commands.add('imageGenerator', (directory,
fileName,
width,
height,
color,
posX,
posY,
message) => {
return cy.task('imageGenerator', {
directory: directory,
fileName: fileName,
width: width,
height: height,
color: color,
posX: posX,
posY: posY,
message: message
})
})

@ -0,0 +1,13 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/
/// <reference types="cypress" />
const {imageGenerator} = require('../plugins/imageGenerator/addPlugin')
module.exports = (on) => {
on('task', {imageGenerator})
}

@ -0,0 +1,47 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/
/// <reference types="cypress" />
require('cypress-file-upload')
require('../plugins/imageGenerator/imageGeneratorCommand')
Cypress.Commands.add('login', (username='admin', password='12qwaszx') => {
cy.get('[placeholder="Username"]').type(username)
cy.get('[placeholder="Password"]').type(password)
})
Cypress.Commands.add('createAnnotationTask', (taksName='New annotation task',
labelName='Some label',
attrName='Some attr name',
textDefaultValue='Some default value for type Text',
image='image.png') => {
cy.contains('button', 'Create new task').click()
cy.url().should('include', '/tasks/create')
cy.get('[id="name"]').type(taksName)
cy.contains('button', 'Add label').click()
cy.get('[placeholder="Label name"]').type(labelName)
cy.contains('button', 'Add an attribute').click()
cy.get('[placeholder="Name"]').type(attrName)
cy.get('div[title="Select"]').click()
cy.get('li').contains('Text').click()
cy.get('[placeholder="Default value"]').type(textDefaultValue)
cy.contains('button', 'Done').click()
cy.get('input[type="file"]').attachFile(image, { subjectType: 'drag-n-drop' });
cy.contains('button', 'Submit').click()
cy.contains('The task has been created', {timeout: '8000'})
cy.get('button[value="tasks"]').click()
cy.url().should('include', '/tasks?page=')
})
Cypress.Commands.add('createShape', (ferstX, ferstY, lastX, lastY) => {
cy.get(':nth-child(8) > svg').trigger('mousemove').click()
cy.get(':nth-child(6) > :nth-child(1) > .ant-btn').click()
cy.get('.cvat-canvas-container')
.click(ferstX, ferstY)
cy.get('.cvat-canvas-container')
.click(lastX, lastY)
})

@ -0,0 +1,7 @@
/*
* Copyright (C) 2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*/
import './commands'

@ -1,4 +0,0 @@
{
"video": false,
"baseUrl": "http://cvat_ui"
}

2270
tests/package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,9 @@
{
"devDependencies": {
"cypress": "^4.12.1",
"cypress-file-upload": "^4.0.7"
},
"dependencies": {
"jimp": "^0.14.0"
}
}
Loading…
Cancel
Save