Skip to content

Instantly share code, notes, and snippets.

@thepushkarp
Created November 4, 2020 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thepushkarp/a03bc5ca7cb677263ad15b5c864160eb to your computer and use it in GitHub Desktop.
Save thepushkarp/a03bc5ca7cb677263ad15b5c864160eb to your computer and use it in GitHub Desktop.
JS code to test Pathshala using Selenium
const { Builder, By, Key, until } = require('selenium-webdriver')
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
async function testJoin(classCode) {
console.log('Testing Joining')
const driver = await new Builder().forBrowser('chrome').build()
// Open the Home Page
await driver.get('https://pathshala.vercel.app/')
console.log('Home Page opened')
// Wait for 2 second
await sleep(2000)
// Find the Join Button and click it
const locator = await driver.findElements(By.id('joinButton'))
await locator[0].click()
console.log('Join button clicked')
// Open the Join Page
await driver.get('https://pathshala.vercel.app/join')
console.log('Join Page opened')
// Wait for 2 second
await sleep(2000)
// Find the User Name Input Box and Enter User Name
await driver.findElement(By.id('name')).sendKeys('Tester')
// Wait for 2 second
await sleep(2000)
// Find the User Name Input Box and Enter User Name
await driver.findElement(By.id('classCode')).sendKeys(classCode)
// Wait for 2 second
await sleep(2000)
// Enter the Classroom
await driver.findElement(By.id('classCode')).sendKeys(Key.RETURN)
console.log('ClassPage Page opened')
}
async function testHost() {
console.log('Testing Hosting')
const driver = await new Builder().forBrowser('chrome').build()
// Open the Home Page
await driver.get('https://pathshala.vercel.app/')
console.log('Home Page opened')
// Wait for 2 second
await sleep(2000)
// Find the Host Button and click it
const locator = await driver.findElements(By.id('hostButton'))
await locator[0].click()
console.log('Host button clicked')
// Open the Host Page
await driver.get('https://pathshala.vercel.app/host')
console.log('Host Page opened')
// Wait for 2 second
await sleep(2000)
// Find the Class Name Input Box and Enter Class Name
await driver.findElement(By.id('className')).sendKeys('Test Class')
// Get the Class Code
const classCode = await driver.findElement(By.id('classCode')).getAttribute('value')
console.log(`Class Code: ${classCode}`)
// Wait for 2 second
await sleep(2000)
// Enter the Classroom
await driver.findElement(By.id('className')).sendKeys(Key.RETURN)
console.log('ClassPage Page opened')
// Wait for 2 second
await sleep(2000)
// Upload an image file
var path = require('path')
await driver.findElement(By.id('filename')).sendKeys(path.join(__dirname, 'test.jpg'))
console.log('Test Image Uploaded')
// Wait for 2 second
await sleep(2000)
// Click the Submit Button
await driver.findElement(By.id('fileSubmit')).click()
console.log('Test Image Submitted')
// Calling the Join function
testJoin(classCode)
}
testHost()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment