From 2e5055e05a361dd76e27cf5f660a1c5d6def9b24 Mon Sep 17 00:00:00 2001
From: BryceLTaylor <brycet@media.mit.edu>
Date: Wed, 18 Aug 2021 10:22:16 -0400
Subject: [PATCH] Create sign in function in selenium helpers for integration
 tests

---
 test/integration/selenium-helpers.js  | 14 +++++++++++++
 test/integration/studios-page.test.js | 30 +++++----------------------
 2 files changed, 19 insertions(+), 25 deletions(-)

diff --git a/test/integration/selenium-helpers.js b/test/integration/selenium-helpers.js
index 5b7fe163d..e3bfcde88 100644
--- a/test/integration/selenium-helpers.js
+++ b/test/integration/selenium-helpers.js
@@ -29,6 +29,7 @@ class SeleniumHelper {
             'getDriver',
             'getLogs',
             'getSauceDriver',
+            'signIn',
             'urlMatches',
             'waitUntilGone'
         ]);
@@ -148,6 +149,19 @@ class SeleniumHelper {
         });
     }
 
+    // must be used on a www page
+    async signIn (username, password, driver) {
+        await this.clickXpath('//li[@class="link right login-item"]/a');
+        let name = await this.findByXpath('//input[@id="frc-username-1088"]');
+        await name.sendKeys(username);
+        let word = await this.findByXpath('//input[@id="frc-password-1088"]');
+        await word.sendKeys(password);
+        await driver.sleep(500);
+        await this.clickXpath('//button[contains(@class, "button") and ' +
+            'contains(@class, "submit-button") and contains(@class, "white")]');
+        // await this.findByXpath('//span[contains(@class, "profile-name")]');
+    }
+
     urlMatches (regex) {
         return this.driver.wait(until.urlMatches(regex), 1000 * 5);
     }
diff --git a/test/integration/studios-page.test.js b/test/integration/studios-page.test.js
index 479ae52f8..f9a633d72 100644
--- a/test/integration/studios-page.test.js
+++ b/test/integration/studios-page.test.js
@@ -6,7 +6,8 @@ const {
     findByXpath,
     buildDriver,
     clickXpath,
-    clickText
+    clickText,
+    signIn
 } = new SeleniumHelper();
 
 let remote = process.env.SMOKE_REMOTE || false;
@@ -84,14 +85,7 @@ describe('studio management', () => {
         // sign in as user2
         await driver.get(rootUrl);
         await driver.sleep(1000);
-        await clickXpath('//li[@class="link right login-item"]/a');
-        let name2 = await findByXpath('//input[@id="frc-username-1088"]');
-        await name2.sendKeys(username2);
-        let word2 = await findByXpath('//input[@id="frc-password-1088"]');
-        await word2.sendKeys(password);
-        await driver.sleep(500);
-        await clickXpath('//button[contains(@class, "button") and ' +
-            'contains(@class, "submit-button") and contains(@class, "white")]');
+        await signIn(username2, password, driver);
         await findByXpath('//span[contains(@class, "profile-name")]');
 
         // Create a studio
@@ -116,14 +110,7 @@ describe('studio management', () => {
         // Sign in user3
         await driver.get(rootUrl);
         await driver.sleep(1000);
-        await clickXpath('//li[@class="link right login-item"]/a');
-        let name3 = await findByXpath('//input[@id="frc-username-1088"]');
-        await name3.sendKeys(username3);
-        let word3 = await findByXpath('//input[@id="frc-password-1088"]');
-        await word3.sendKeys(password);
-        await driver.sleep(500);
-        await clickXpath('//button[contains(@class, "button") and ' +
-            'contains(@class, "submit-button") and contains(@class, "white")]');
+        await signIn(username3, password, driver);
         await findByXpath('//span[contains(@class, "profile-name")]');
 
         // accept the curator invite
@@ -138,14 +125,7 @@ describe('studio management', () => {
         // sign in as user2
         await driver.get(rootUrl);
         await driver.sleep(1000);
-        await clickXpath('//li[@class="link right login-item"]/a');
-        let name4 = await findByXpath('//input[@id="frc-username-1088"]');
-        await name4.sendKeys(username2);
-        let word4 = await findByXpath('//input[@id="frc-password-1088"]');
-        await word4.sendKeys(password);
-        await driver.sleep(500);
-        await clickXpath('//button[contains(@class, "button") and ' +
-            'contains(@class, "submit-button") and contains(@class, "white")]');
+        await signIn(username2, password, driver);
         await findByXpath('//span[contains(@class, "profile-name")]');
 
         // promote user3