github.com/qubitproducts/logspray@v0.2.14/server/swagger-ui/test/e2e/v2/petstore.js (about)

     1  'use strict';
     2  
     3  var expect = require('chai').expect;
     4  var webdriver = require('selenium-webdriver');
     5  var driver = require('../driver');
     6  var servers = require('../servers');
     7  var until = webdriver.until;
     8  var helpers = require('../helpers');
     9  
    10  var elements = [
    11    'swagger-ui-container',
    12    'resources_container',
    13    'api_info',
    14    'resource_pet',
    15    'resource_store',
    16    'resource_user',
    17    'header'
    18  ];
    19  
    20  var specPath = helpers.parseSpecFilename(__filename);
    21  
    22  describe('swagger 2.0 spec tests', function () {
    23    this.timeout(40 * 1000);
    24  
    25    before(function (done) {
    26      this.timeout(50 * 1000);
    27      servers.start(specPath, done);
    28    });
    29  
    30    afterEach(function(){
    31      it('should not have any console errors', function (done) {
    32        driver.manage().logs().get('browser').then(function(browserLogs) {
    33          var errors = [];
    34          browserLogs.forEach(function(log){
    35            // 900 and above is "error" level. Console should not have any errors
    36            if (log.level.value > 900) {
    37              console.log('browser error message:', log.message); errors.push(log);
    38            }
    39          });
    40          expect(errors).to.be.empty;
    41          done();
    42        });
    43      });
    44    });
    45  
    46    it('should have "Swagger UI" in title', function () {
    47      return driver.wait(until.titleIs('Swagger UI'), 1000);
    48    });
    49  
    50    elements.forEach(function (id) {
    51      it('should render element: ' + id, function (done) {
    52        var locator = webdriver.By.id(id);
    53        driver.isElementPresent(locator).then(function (isPresent) {
    54          expect(isPresent).to.be.true;
    55          done();
    56        });
    57      });
    58    });
    59  
    60    it('should find the contact name element', function(done){
    61      var locator = webdriver.By.css('.info_name');
    62      driver.isElementPresent(locator).then(function (isPresent) {
    63        expect(isPresent).to.be.true;
    64        done();
    65      });
    66    });
    67  
    68    it('should find the contact email element', function(done){
    69      var locator = webdriver.By.css('.info_email');
    70      driver.isElementPresent(locator).then(function (isPresent) {
    71        expect(isPresent).to.be.true;
    72        done();
    73      });
    74    });
    75  
    76    it('should find the contact url element', function(done){
    77      var locator = webdriver.By.css('.info_url');
    78      driver.isElementPresent(locator).then(function (isPresent) {
    79        expect(isPresent).to.be.true;
    80        done();
    81      });
    82    });
    83  
    84    it('should find the pet link', function(done){
    85      var locator = webdriver.By.xpath('//*[@data-id="pet"]');
    86      driver.isElementPresent(locator).then(function (isPresent) {
    87        expect(isPresent).to.be.true;
    88        done();
    89      });
    90    });
    91  
    92    it('should find the pet resource description', function(done){
    93      var locator = webdriver.By.xpath('//div[contains(., "Everything about your Pets")]');
    94      driver.findElements(locator).then(function (elements) {
    95        expect(elements.length).to.not.equal(0);
    96        done();
    97      });
    98    });
    99  
   100    it('should find the user link', function(done){
   101      var locator = webdriver.By.xpath('//*[@data-id="user"]');
   102      driver.isElementPresent(locator).then(function (isPresent) {
   103        expect(isPresent).to.be.true;
   104        done();
   105      });
   106    });
   107  
   108    it('should find the store link', function(done){
   109      var locator = webdriver.By.xpath('//*[@data-id="store"]');
   110      driver.isElementPresent(locator).then(function (isPresent) {
   111        expect(isPresent).to.be.true;
   112        done();
   113      });
   114    });
   115  /*
   116    // TODO: disabling for now
   117    ['root.id','root.username','root.firstName','root.lastName', 'root.email', 'root.password', 'root.phone', 'root.userStatus']
   118    .forEach(function (id) {
   119      it('should find a jsoneditor for user post with field: ' + id, function (done) {
   120        var locator = webdriver.By.xpath('//*[@id=\'user_createUser\']//*[@data-schemapath=\''+id+'\']');
   121        driver
   122          .wait(webdriver.until.elementLocated(locator),2000)
   123          .then(function() { done(); });
   124      });
   125    });
   126  
   127    // TODO JSonEditor Tests for POST/PUT
   128  */
   129    after(function(done) {
   130      servers.close();
   131      done();
   132    });
   133  });