Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

121 righe
3.6 KiB

  1. var webdriver = require('selenium-webdriver');
  2. var createServer = require('http-server').createServer;
  3. var expect = require('chai').expect;
  4. var path = require('path')
  5. var dist = path.join(__dirname, '..', '..', 'dist');
  6. var specs = path.join(__dirname, '..', '..', 'test', 'specs');
  7. var DOCS_PORT = 8080;
  8. var SPEC_SERVER_PORT = 8081
  9. var headers = {
  10. 'Access-Control-Allow-Origin': '*',
  11. 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
  12. };
  13. var elements = [
  14. 'swagger-ui-container',
  15. 'resources_container',
  16. 'api_info',
  17. 'resource_pet',
  18. 'resource_store',
  19. 'resource_user',
  20. 'header'
  21. ];
  22. describe('swagger 1.x spec tests', function (done) {
  23. this.timeout(10 * 1000);
  24. var swaggerUI, specServer, driver;
  25. before(function () {
  26. swaggerUI = createServer({ root: dist, headers: headers });
  27. specServer = createServer({ root: specs, headers: headers });
  28. driver = new webdriver.Builder().
  29. withCapabilities(webdriver.Capabilities.firefox()).build();
  30. swaggerUI.listen(DOCS_PORT);
  31. specServer.listen(SPEC_SERVER_PORT);
  32. var swaggerSpecLocation = encodeURIComponent('http://localhost:' + SPEC_SERVER_PORT + '/v1.2/petstore/api-docs')
  33. driver.get('http://localhost:' + DOCS_PORT + '/index.html?url=' + swaggerSpecLocation);
  34. });
  35. afterEach(function(){
  36. it('should not have any console errors', function (done) {
  37. driver.manage().logs().get('browser').then(function(browserLogs) {
  38. var errors = [];
  39. browserLogs.forEach(function(log){
  40. // 900 and above is "error" level. Console should not have any errors
  41. if (log.level.value > 900)
  42. console.log('browser error message:', log.message); errors.push(log);
  43. });
  44. expect(errors).to.be.empty;
  45. done();
  46. });
  47. });
  48. });
  49. it('should have "Swagger UI" in title', function (done) {
  50. driver.sleep(200);
  51. driver.getTitle().then(function(title) {
  52. expect(title).to.contain('Swagger UI');
  53. done();
  54. });
  55. });
  56. elements.forEach(function (id) {
  57. it('should render element: ' + id, function (done) {
  58. var locator = webdriver.By.id(id)
  59. driver.isElementPresent(locator).then(function (isPresent) {
  60. expect(isPresent).to.be.true;
  61. done();
  62. });
  63. });
  64. });
  65. it('should find the contact name element', function(done){
  66. var locator = webdriver.By.css('.info_name');
  67. driver.isElementPresent(locator).then(function (isPresent) {
  68. expect(isPresent).to.be.true;
  69. done();
  70. });
  71. });
  72. it('should find the pet link', function(done){
  73. var locator = webdriver.By.xpath("//*[@data-id='pet']");
  74. driver.isElementPresent(locator).then(function (isPresent) {
  75. expect(isPresent).to.be.true;
  76. done();
  77. });
  78. });
  79. it('should find the pet resource description', function(done){
  80. var locator = webdriver.By.xpath("//div[contains(., 'Operations about pets')]");
  81. driver.findElements(locator).then(function (elements) {
  82. expect(elements.length).to.not.equal(0);
  83. done();
  84. });
  85. });
  86. it('should find the user link', function(done){
  87. var locator = webdriver.By.xpath("//*[@data-id='user']");
  88. driver.isElementPresent(locator).then(function (isPresent) {
  89. expect(isPresent).to.be.true;
  90. done();
  91. });
  92. });
  93. it('should find the store link', function(done){
  94. var locator = webdriver.By.xpath("//*[@data-id='store']");
  95. driver.isElementPresent(locator).then(function (isPresent) {
  96. expect(isPresent).to.be.true;
  97. done();
  98. });
  99. });
  100. after(function() {
  101. swaggerUI.close();
  102. specServer.close();
  103. driver.quit();
  104. });
  105. });