order.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. import { expect } from "../setup";
  2. import { loginAsCustomer, addAddress } from "../utils/customer";
  3. import {
  4. generateName,
  5. generateSKU,
  6. generateDescription,
  7. generateHostname,
  8. } from "../utils/faker";
  9. export async function generateOrder(page) {
  10. /**
  11. * Customer login.
  12. */
  13. await loginAsCustomer(page);
  14. /**
  15. * Fill customer default address.
  16. */
  17. await addAddress(page);
  18. /**
  19. * Go to the shop to buy a product.
  20. */
  21. await page.goto("");
  22. await page.waitForLoadState("networkidle");
  23. await page
  24. .locator("#main div")
  25. .filter({ hasText: "New Products View All New" })
  26. .locator("button")
  27. .first()
  28. .waitFor({ state: "visible" });
  29. await page
  30. .locator("#main div")
  31. .filter({ hasText: "New Products View All New" })
  32. .locator("button")
  33. .first()
  34. .click();
  35. await expect(page.locator("#app")).toContainText("Item Added Successfully");
  36. await page.waitForTimeout(2000);
  37. await page.getByRole("button", { name: "Shopping Cart" }).click();
  38. await page.getByRole("link", { name: "Continue to Checkout" }).click();
  39. await page
  40. .locator(
  41. 'span[class="icon-checkout-address text-6xl text-navyBlue max-sm:text-5xl"]'
  42. )
  43. .nth(0)
  44. .click();
  45. await page.getByRole("button", { name: "Proceed" }).click();
  46. await page.waitForTimeout(2000);
  47. /**
  48. * Choose shipping method.
  49. */
  50. await page.waitForSelector("text=Free Shipping");
  51. await page.getByText("Free Shipping").first().click();
  52. await page.waitForTimeout(2000);
  53. /**
  54. * Choose payment option.
  55. */
  56. await page.waitForSelector("text=Cash On Delivery");
  57. await page.getByText("Cash On Delivery").first().click();
  58. await page.waitForTimeout(2000);
  59. /**
  60. * Place order.
  61. */
  62. await page.getByRole("button", { name: "Place Order" }).click();
  63. await page.waitForTimeout(2000);
  64. await page.waitForSelector("text=Thank you for your order!");
  65. await expect(page.locator("text=Thank you for your order!")).toBeVisible();
  66. }
  67. export async function downloadableOrder(page) {
  68. /**
  69. * Main product data which we will use to create the product.
  70. */
  71. const product = {
  72. name: generateName(),
  73. sku: generateSKU(),
  74. productNumber: generateSKU(),
  75. shortDescription: generateDescription(),
  76. description: generateDescription(),
  77. price: "199",
  78. };
  79. /**
  80. * Reaching to the create product page.
  81. */
  82. await page.goto("admin/catalog/products");
  83. await page.waitForSelector(
  84. 'button.primary-button:has-text("Create Product")'
  85. );
  86. await page.getByRole("button", { name: "Create Product" }).click();
  87. /**
  88. * Opening create product form in modal.
  89. */
  90. await page.locator('select[name="type"]').selectOption("downloadable");
  91. await page.locator('select[name="attribute_family_id"]').selectOption("1");
  92. await page.locator('input[name="sku"]').fill(generateSKU());
  93. await page.getByRole("button", { name: "Save Product" }).click();
  94. /**
  95. * After creating the product, the page is redirected to the edit product page, where
  96. * all the details need to be filled in.
  97. */
  98. await page.waitForSelector(
  99. 'button.primary-button:has-text("Save Product")'
  100. );
  101. /**
  102. * Waiting for the main form to be visible.
  103. */
  104. await page.waitForSelector('form[enctype="multipart/form-data"]');
  105. /**
  106. * General Section.
  107. */
  108. await page.locator("#product_number").fill(product.productNumber);
  109. await page.locator("#name").fill(product.name);
  110. const name = await page.locator('input[name="name"]').inputValue();
  111. /**
  112. * Description Section.
  113. */
  114. await page.fillInTinymce(
  115. "#short_description_ifr",
  116. product.shortDescription
  117. );
  118. await page.fillInTinymce("#description_ifr", product.description);
  119. /**
  120. * Meta Description Section.
  121. */
  122. await page.locator("#meta_title").fill(product.name);
  123. await page.locator("#meta_keywords").fill(product.name);
  124. await page.locator("#meta_description").fill(product.shortDescription);
  125. /**
  126. * Image Section.
  127. */
  128. // Will add images later.
  129. /**
  130. * Price Section.
  131. */
  132. await page.locator("#price").fill(product.price);
  133. /**
  134. * Downloadable Links Section.
  135. */
  136. await page.getByText("Add Link").first().click();
  137. await page.waitForSelector(".min-h-0 > div > div");
  138. await page.locator('input[name="title"]').fill(generateName());
  139. const linkTitle = await page.locator('input[name="title"]').inputValue();
  140. await page.locator('input[name="price"]').first().fill("100");
  141. await page.locator('input[name="downloads"]').fill("10");
  142. await page.locator('select[name="type"]').selectOption("url");
  143. await page.waitForSelector('input[name="url"]');
  144. await page.locator('input[name="url"]').fill(generateHostname());
  145. await page.locator('select[name="sample_type"]').selectOption("url");
  146. await page.waitForSelector('input[name="sample_url"]');
  147. await page.locator('input[name="sample_url"]').fill(generateHostname());
  148. /**
  149. * Saving the Downloadable Link.
  150. */
  151. await page.getByText("Link Save").click();
  152. await page.getByRole("button", { name: "Save", exact: true }).click();
  153. await expect(page.getByText(`${linkTitle}`)).toBeVisible();
  154. /**
  155. * Saving the product.
  156. */
  157. await page.getByRole("button", { name: "Save Product" }).click();
  158. /**
  159. * Expecting for the product to be saved.
  160. */
  161. await expect(page.locator("#app")).toContainText(
  162. "Product updated successfully"
  163. );
  164. /**
  165. * Checking the product in the list.
  166. */
  167. await page.goto("admin/catalog/products");
  168. await expect(
  169. page.locator("p.break-all.text-base").filter({ hasText: product.name })
  170. ).toBeVisible();
  171. /**
  172. * Customer login.
  173. */
  174. await loginAsCustomer(page);
  175. /**
  176. * Fill customer default address.
  177. */
  178. await addAddress(page);
  179. /**
  180. * customer to buy a product
  181. */
  182. await page.goto("");
  183. await page.getByRole("textbox", { name: "Search products here" }).click();
  184. await page
  185. .getByRole("textbox", { name: "Search products here" })
  186. .fill(product.name);
  187. await page
  188. .getByRole("textbox", { name: "Search products here" })
  189. .press("Enter");
  190. await page.waitForTimeout(2000);
  191. await page.getByRole("button", { name: "Add To Cart" }).click();
  192. await page.waitForTimeout(2000)
  193. await page.locator('#main label').nth(1).click();
  194. await page.getByRole("button", { name: "Add To Cart" }).click();
  195. await expect(
  196. page
  197. .getByRole("paragraph")
  198. .filter({ hasText: "Item Added Successfully" })
  199. ).toBeVisible();
  200. await page.getByRole("button", { name: "Shopping Cart" }).click();
  201. await page.getByRole("link", { name: "Continue to Checkout" }).click();
  202. await page
  203. .locator(
  204. 'span[class="icon-checkout-address text-6xl text-navyBlue max-sm:text-5xl"]'
  205. )
  206. .nth(0)
  207. .click();
  208. await page.getByRole("button", { name: "Proceed" }).click();
  209. await page.waitForTimeout(2000);
  210. /**
  211. * Choose payment option.
  212. */
  213. await expect(
  214. page.locator("label").filter({ hasText: "Money Transfer" })
  215. ).toBeVisible();
  216. await page.locator(".relative > .icon-radio-unselect").first().click();
  217. await page.waitForTimeout(2000);
  218. /**
  219. * Place order.
  220. */
  221. await page.getByRole("button", { name: "Place Order" }).click();
  222. await page.waitForTimeout(2000);
  223. await page.waitForSelector("text=Thank you for your order!");
  224. await expect(page.locator("text=Thank you for your order!")).toBeVisible();
  225. /**
  226. * completing the order.
  227. */
  228. await page.goto("admin/sales/orders");
  229. await page.locator(".row > div:nth-child(4) > a").first().click();
  230. await page.getByText("Invoice", { exact: true }).click();
  231. await page.locator("#can_create_transaction").nth(1).click();
  232. await page.getByRole("button", { name: "Create Invoice" }).click();
  233. await expect(
  234. page.getByText("Invoice created successfully Close")
  235. ).toBeVisible();
  236. return product.name;
  237. }