@@ -11,7 +11,8 @@ test.describe('Add API Backend', function() {
1111 var driver ;
1212 var newUser = {
1313 added : false ,
14- email : ""
14+ email : "" ,
15+ password : ""
1516 } ;
1617 test . before ( function ( ) {
1718 driver = CommonUtils . buildDriver ( ) ;
@@ -20,9 +21,13 @@ test.describe('Add API Backend', function() {
2021 driver . quit ( ) ;
2122 } ) ;
2223 test . afterEach ( function ( ) {
24+ //TODO: after adding a new api, must delete it too as a new user
2325 CommonUtils . dashBoardSignOut ( driver ) ;
2426 if ( newUser . added ) {
25- CommonUtils . deleteNewUser ( driver , newUser . email ) ;
27+ var mainPage = CommonUtils . deleteNewUser ( driver , newUser . email , newUser . password ) ;
28+ mainPage . getText ( ) . then ( function ( text ) {
29+ assert . equal ( 'Latest APIs' , text ) ;
30+ } ) ;
2631 }
2732 } ) ;
2833 test . it ( '8.1 should add/publish api backend as a new user' , function ( ) {
@@ -32,76 +37,109 @@ test.describe('Add API Backend', function() {
3237 userName = faker . internet . userName ( ) ;
3338 }
3439 var email = faker . internet . email ( ) ;
40+ var password = faker . internet . password ( ) ;
3541 newUser . added = true ;
3642 newUser . email = email ;
37- CommonUtils . fillSignUpForm ( driver , userName , email , faker . internet . password ( ) ) ;
43+ newUser . password = password ;
44+ CommonUtils . fillSignUpForm ( driver , userName , email , password ) ;
3845 CommonUtils . goToDashboard ( driver ) ;
3946 AddAPIBackendUtil . addNewBackend ( driver , {
40- backendName : 'NewBackend' ,
41- description : 'Test Description' ,
42- hostName : 'google.com' ,
43- portNumber : '80' ,
44- frontendPrefix : '/test' ,
45- backendPrefix : '/test'
47+ apiName : 'NewBackend v2' ,
48+ apiDescription : 'Test Description' ,
49+ apiURL : 'http://google.com'
4650 } ) ;
47- var publishedAPIHostElement = driver . findElement ( By . xpath ( '//*[@class="page-title"]' ) ) ;
51+ // Get API name in an api page
52+ var publishedAPIHostElement = driver . findElement ( By . id ( 'api-header' ) ) ;
4853 publishedAPIHostElement . getText ( ) . then ( function ( text ) {
49- assert . equal ( text , 'NewBackend' ) ;
54+ assert . equal ( text , 'NewBackend v2 ' ) ;
5055 } ) ;
5156 } ) ;
5257 test . it ( '8.2 should add/publish api backend as a registered user who doesn\'t own any api' , function ( ) {
5358 newUser . added = false ;
5459 CommonUtils . signIn ( driver ) ;
55- CommonUtils . fillSignInForm ( driver , 'test @test.test ' , 'testuser ' ) ;
60+ CommonUtils . fillSignInForm ( driver , 'robot @test.com ' , 'robottest ' ) ;
5661 CommonUtils . goToDashboard ( driver ) ;
5762 AddAPIBackendUtil . addNewBackend ( driver , {
58- backendName : 'NewBackend' ,
59- description : 'Test Description' ,
60- hostName : 'google.com' ,
61- portNumber : '80' ,
62- frontendPrefix : '/test' ,
63- backendPrefix : '/test'
63+ apiName : 'NewBackend' ,
64+ apiDescription : 'Test Description' ,
65+ apiURL : 'http://google.com'
6466 } ) ;
65- var publishedAPIHostElement = driver . findElement ( By . xpath ( '//*[@class="page-title"] ') ) ;
67+ var publishedAPIHostElement = driver . findElement ( By . id ( 'api-header ') ) ;
6668 publishedAPIHostElement . getText ( ) . then ( function ( text ) {
6769 assert . equal ( text , 'NewBackend' ) ;
6870 } ) ;
6971 } ) ;
70- test . it ( '8.3 should not add/publish api backend with missing fields' , function ( ) {
72+ test . it ( '8.3.1 should not add/publish api backend with missing API name field' , function ( ) {
73+ newUser . added = false ;
74+ CommonUtils . signIn ( driver ) ;
75+ CommonUtils . fillSignInForm ( driver , 'robot@test.com' , 'robottest' ) ;
76+ CommonUtils . goToDashboard ( driver ) ;
77+ var values = {
78+ apiDescription : 'Test Description' ,
79+ apiURL : 'http://google.com'
80+ } ;
81+ AddAPIBackendUtil . clickAddNewBackend ( driver ) ;
82+ AddAPIBackendUtil . fillApiDescription ( driver , values ) ;
83+ AddAPIBackendUtil . fillApiURL ( driver , values ) ;
84+ AddAPIBackendUtil . savingInformation ( driver ) ;
85+ // Get the API Name field in form
86+ var hostRequiredErrorElement = driver . findElement ( By . xpath ( '//*[@id="addApiForm"]/fieldset/div[1]/span' ) ) ;
87+ hostRequiredErrorElement . getText ( ) . then ( function ( text ) {
88+ assert . equal ( text , 'API Name is required' ) ;
89+ } ) ;
90+ } ) ;
91+ test . it ( '8.3.2 should not add/publish api backend with missing URL field' , function ( ) {
7192 newUser . added = false ;
7293 CommonUtils . signIn ( driver ) ;
73- CommonUtils . fillSignInForm ( driver , 'test @test.test ' , 'testuser ' ) ;
94+ CommonUtils . fillSignInForm ( driver , 'robot @test.com ' , 'robottest ' ) ;
7495 CommonUtils . goToDashboard ( driver ) ;
7596 var values = {
76- backendName : 'NewBackend' ,
77- description : 'Test Description' ,
78- hostName : '' ,
79- portNumber : '80' ,
97+ apiName : 'NewBackend' ,
98+ apiDescription : 'Test Description'
8099 } ;
81100 AddAPIBackendUtil . clickAddNewBackend ( driver ) ;
82- AddAPIBackendUtil . fillBaseInformation ( driver , values ) ;
83- AddAPIBackendUtil . fillBackendInformation ( driver , values ) ;
84- var hostRequiredErrorElement = driver . findElement ( By . xpath ( '//*[@id="backend-information-form"]/div[2]/span' ) ) ;
101+ AddAPIBackendUtil . fillApiName ( driver , values ) ;
102+ AddAPIBackendUtil . fillApiDescription ( driver , values ) ;
103+ AddAPIBackendUtil . savingInformation ( driver ) ;
104+ // Get the URL field in form
105+ var hostRequiredErrorElement = driver . findElement ( By . xpath ( '//*[@id="addApiForm"]/fieldset/div[3]/span' ) ) ;
85106 hostRequiredErrorElement . getText ( ) . then ( function ( text ) {
86- assert . equal ( text , 'Host is required' ) ;
107+ assert . equal ( text , 'URL is required' ) ;
87108 } ) ;
88109 } ) ;
89110 test . it ( '8.4 should not add/publish api backend with invalid host name' , function ( ) {
90111 newUser . added = false ;
91112 CommonUtils . signIn ( driver ) ;
92- CommonUtils . fillSignInForm ( driver , 'test @test.test ' , 'testuser ' ) ;
113+ CommonUtils . fillSignInForm ( driver , 'robot @test.com ' , 'robottest ' ) ;
93114 CommonUtils . goToDashboard ( driver ) ;
94115 AddAPIBackendUtil . addNewBackend ( driver , {
95- backendName : 'NewBackend' ,
96- description : 'Test Description' ,
97- hostName : 'google' ,
98- portNumber : '80' ,
99- frontendPrefix : '/test' ,
100- backendPrefix : '/test'
116+ apiName : 'NewBackend' ,
117+ apiDescription : 'Test Description' ,
118+ apiURL : 'google.com'
119+ } ) ;
120+ // Get the URL field in form
121+ var errorElement = driver . findElement ( By . xpath ( '//*[@id="addApiForm"]/fieldset/div[3]/span' ) ) ;
122+ errorElement . getText ( ) . then ( function ( text ) {
123+ assert . equal ( text , 'URL must be a valid URL' ) ;
101124 } ) ;
102- var errorElement = driver . findElement ( By . xpath ( '//*[@class="s-alert-box-inner"]/p' ) ) ;
125+ } ) ;
126+ test . it ( '8.5 should not add/publish api with no unique name' , function ( ) {
127+ newUser . added = false ;
128+ CommonUtils . signIn ( driver ) ;
129+ CommonUtils . fillSignInForm ( driver , 'robot@test.com' , 'robottest' ) ;
130+ CommonUtils . goToDashboard ( driver ) ;
131+ var values = {
132+ apiName : 'NewBackend' ,
133+ apiDescription : 'Test Description' ,
134+ apiURL : 'http://google.com'
135+ } ;
136+ AddAPIBackendUtil . addNewBackend ( driver , values ) ;
137+ // Wait a moment for span is available
138+ driver . sleep ( 1000 ) ;
139+ // Get the API Name field in form
140+ var errorElement = driver . findElement ( By . xpath ( '//*[@id="addApiForm"]/fieldset/div[1]/span' ) ) ;
103141 errorElement . getText ( ) . then ( function ( text ) {
104- assert . include ( text , 'Could not resolve host: no address for google ' ) ;
142+ assert . equal ( text , 'API Name must be unique ' ) ;
105143 } ) ;
106144 } ) ;
107145} ) ;
0 commit comments