Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.51 KB | None | 0 0
  1. const puppeteer = require('puppeteer');
  2. const expect = require('expect');
  3.  
  4. (() => {
  5.  
  6. describe('Test of Currency Page: ', () => {
  7.  
  8. let browser;
  9. let page;
  10. let screenshots = {
  11. width: 1920,
  12. height: 1080
  13. };
  14. let currencyImage;
  15. let loginAddress;
  16. let username;
  17. let password;
  18. let loginButton;
  19. let currencyAddress;
  20.  
  21. it('Puppeteer should be opened in the browser', async () => {
  22.  
  23. try {
  24. browser = await puppeteer.launch({
  25. headless: false,
  26. ignoreHTTPSErrors: true
  27. });
  28. expect(browser).toExist();
  29. } catch (e) {
  30. console.log(e.message);
  31. }
  32.  
  33. });
  34.  
  35. it('New page should be created in the browser', async () => {
  36.  
  37. try {
  38. page = await browser.newPage();
  39. expect(page).toExist();
  40. } catch (e) {
  41. console.log(e.message);
  42. }
  43.  
  44. });
  45.  
  46. it('Screenshots settings should be created', async () => {
  47.  
  48. try {
  49. await page.setViewport(screenshots);
  50. expect(page).toExist();
  51. } catch (e) {
  52. console.log(e.message);
  53. }
  54.  
  55. });
  56.  
  57. it('Screenshots should be created', async () => {
  58.  
  59. try {
  60. currencyImage = {
  61. path: './test/images/currency/currency1.png'
  62. };
  63. await page.screenshot(currencyImage);
  64. expect(page).toExist();
  65. } catch (e) {
  66. console.log(e.message);
  67. }
  68.  
  69. });
  70.  
  71. it('Login Page should be loaded', async () => {
  72.  
  73. try {
  74. loginAddress = 'https://localhost:8150/login';
  75. await page.goto(loginAddress);
  76. expect(loginAddress).toBeA('string');
  77. } catch (e) {
  78. console.log(e.message);
  79. }
  80.  
  81. });
  82.  
  83. it('Screenshots should be created', async () => {
  84.  
  85. try {
  86. currencyImage = {
  87. path: './test/images/currency/currency2.png'
  88. };
  89. await page.screenshot(currencyImage);
  90. expect(page).toExist();
  91. } catch (e) {
  92. console.log(e.message);
  93. }
  94.  
  95. });
  96.  
  97. it('Username should be string', async () => {
  98.  
  99. try {
  100. username = 'kris';
  101. await page.type('#username', username);
  102. expect(username).toBeA('string');
  103. } catch (e) {
  104. console.log(e.message);
  105. }
  106.  
  107. });
  108.  
  109. it('Screenshots should be created', async () => {
  110.  
  111. try {
  112. currencyImage = {
  113. path: './test/images/currency/currency3.png'
  114. };
  115. await page.screenshot(currencyImage);
  116. expect(page).toExist();
  117. } catch (e) {
  118. console.log(e.message);
  119. }
  120.  
  121. });
  122.  
  123. it('Password should be string', async () => {
  124.  
  125. try {
  126. password = 'test';
  127. await page.type('#password', password);
  128. expect(password).toBeA('string');
  129. } catch (e) {
  130. console.log(e.message);
  131. }
  132.  
  133. });
  134.  
  135. it('Screenshots should be created', async () => {
  136.  
  137. try {
  138. currencyImage = {
  139. path: './test/images/currency/currency4.png'
  140. };
  141. await page.screenshot(currencyImage);
  142. expect(page).toExist();
  143. } catch (e) {
  144. console.log(e.message);
  145. }
  146.  
  147. });
  148.  
  149. it('Login Button should be clicked', async () => {
  150.  
  151. try {
  152. loginButton = '#loginButton';
  153. await page.click(loginButton);
  154. expect(loginButton).toBeA('string');
  155. } catch (e) {
  156. console.log(e.message);
  157. }
  158.  
  159. });
  160.  
  161. it('Screenshots should be created', async () => {
  162.  
  163. try {
  164. currencyImage = {
  165. path: './test/images/currency/currency5.png'
  166. };
  167. await page.screenshot(currencyImage);
  168. expect(page).toExist();
  169. } catch (e) {
  170. console.log(e.message);
  171. }
  172.  
  173. });
  174.  
  175. it('Currency Page should be loaded', async () => {
  176.  
  177. try {
  178. currencyAddress = 'https://localhost:8150/dashboard/currency';
  179. await page.goto(currencyAddress);
  180. expect(currencyAddress).toBeA('string');
  181. } catch (e) {
  182. console.log(e.message);
  183. }
  184.  
  185. });
  186.  
  187. it('Screenshots should be created', async () => {
  188.  
  189. try {
  190. currencyImage = {
  191. path: './test/images/currency/currency6.png'
  192. };
  193. await page.screenshot(currencyImage);
  194. expect(page).toExist();
  195. } catch (e) {
  196. console.log(e.message);
  197. }
  198.  
  199. });
  200.  
  201. it('JSON Currency Page should be loaded', async () => {
  202.  
  203. try {
  204. await page.goto(`${currencyAddress}/1`);
  205. let innerText = await page.evaluate(() => {
  206. return JSON.parse(document.querySelector("body").innerText);
  207. });
  208. // console.log(innerText);
  209. expect(innerText.success[0].id).toEqual(1).toBeA('number');
  210. } catch (e) {
  211. console.log(e.message);
  212. }
  213.  
  214. });
  215.  
  216. it('Screenshots should be created', async () => {
  217.  
  218. try {
  219. currencyImage = {
  220. path: './test/images/currency/currency7.png'
  221. };
  222. await page.screenshot(currencyImage);
  223. expect(page).toExist();
  224. } catch (e) {
  225. console.log(e.message);
  226. }
  227.  
  228. });
  229.  
  230. it('Browser should be closed', async () => {
  231.  
  232. try {
  233. page = await browser.close();
  234. expect(page).toNotExist();
  235. } catch (e) {
  236. console.log(e.message);
  237. }
  238.  
  239. });
  240.  
  241. });
  242.  
  243. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement