Best JavaScript code snippet using appium
visibility.js
Source: visibility.js
1define(['jquery', 'core/notification', 'core/str'], function($, notification, str) {2 // Private variables and functions.3 // The current clicked element.4 var element = 0;5 /**6 * Displays a confirmation dialog box for deleting visibility session.7 *8 * @param {String} confirmationText The string that should be used for the confirmation dialogue.9 * @param {Function} action The callback that performs the ajax action upon confirmation.10 * @method confirmationDialog11 */12 var confirmationDialog = function(confirmationText, action) {13 // Create confirmation string dialog.14 str.get_strings([15 { key: 'confirm', component: 'moodle' },16 { key: confirmationText, component: 'local_visibility' },17 { key: 'yes', component: 'core' },18 { key: 'no', component: 'core' }19 ]).done(function(strs) {20 notification.confirm(21 strs[0], // Confirm.22 strs[1], // Are you absolutely sure?23 strs[2], // Yes.24 strs[3], // No.25 action26 );27 }.bind(this)).fail(notification.exception);28 };29 /**30 * Deletes selected visibility session via ajax31 *32 * @method deleteSession33 */34 var deleteSession = function(){35 var id = element.data('id');36 var courseId = element.data('course');37 $.ajax({38 url: "ajax.php",39 data: {40 action: 'delete',41 courseid: courseId,42 rangeid: id,43 sesskey: M.cfg.sesskey44 }45 }).done(function( msg ) {46 if (msg.success) {47 $(".range" + id).fadeOut(250);48 $(".notifications").remove(); // Remove any notices if any.49 notification.alert(50 null,51 msg.successmsg52 );53 if (msg.count == 0) {54 location.reload(); // Reload the page so Visibility dropdown is unlocked.55 }56 } else {57 // Deletion failed. Display an error message.58 var moodleStringPromise = str.get_string('deleteerror', 'local_visibility');59 $.when(moodleStringPromise).done(function(errorMsg) {60 window.alert(errorMsg);61 });62 }63 });64 };65 /**66 * Deletes all visibility sessions via ajax67 *68 * @method deleteAllSessions69 */70 var deleteAllSessions = function(){71 var courseId = element.data('course');72 $.ajax({73 url: "ajax.php",74 data: {75 action: 'deleteall',76 courseid: courseId,77 sesskey: M.cfg.sesskey78 }79 }).done(function( msg ) {80 if (msg.success) {81 $(".visibility-session").fadeOut(250);82 $(".notifications").remove(); // Remove any notices if any.83 notification.alert(84 null,85 msg.successmsg86 );87 location.reload(); // Reload the page so Visibility dropdown is unlocked.88 } else {89 // Deletion failed. Display an error message.90 var moodleStringPromise = str.get_string('deleteallerror', 'local_visibility');91 $.when(moodleStringPromise).done(function(errorMsg) {92 window.alert(errorMsg);93 });94 }95 });96 };97 return {98 // Public variables and functions.99 /**100 * Initialise the module.101 * @method init102 */103 init: function() {104 $('.rangedeletebutton').click(function(ev) {105 element = $(this);106 ev.preventDefault();107 confirmationDialog('confirmremovevisibilitysession', deleteSession);108 });109 $('#id_rangedeleteallbutton').click(function(ev) {110 element = $(this);111 ev.preventDefault();112 confirmationDialog('confirmdeleteallsessions', deleteAllSessions);113 });114 }115 };...
SessionPanel-test.js
Source: SessionPanel-test.js
...60 // dispatchFuncs.deleteSession.mockClear();61 // dispatchFuncs.deleteAllSessions.mockClear();62 // });63 // it('can delete all', () => {64 // subject.instance().deleteAllSessions();65 // expect(dispatchFuncs.deleteAllSessions).toHaveBeenCalled();66 // });67 // it('can delete one', () => {68 // subject.instance().deleteSession(mockSessionId);69 // expect(dispatchFuncs.deleteSession).toHaveBeenCalled();70 // });71 // it('requires a sessionId to delete single session', () => {72 // subject.instance().deleteSession();73 // expect(dispatchFuncs.deleteSession).not.toHaveBeenCalled();74 // });75 // describe('UI', () => {76 // let instance;77 // beforeEach(() => {78 // subject = mount(<Provider store={mockStore}><SessionPanel {...props} /></Provider>);...
login.test.js
Source: login.test.js
...24 const secondValidBody = loginBodyFactory(user2);25 const invalidBody = invalidLoginEmailFactory();26 const wrongPasswordBody = wrongLoginPasswordFactory(validBody);27 beforeAll(async () => {28 await deleteAllSessions();29 await deleteAllUsers();30 const userId = (31 await insertUser({ ...user, password: hashPassword(user.password) })32 ).rows[0].id;33 await insertSession(userId, token);34 });35 afterAll(async () => {36 await deleteAllSessions();37 await deleteAllUsers();38 endConnection();39 });40 it('should return status code 404 when there is no such email', async () => {41 const routeReturn = await supertest(server)42 .post(login.route)43 .send(secondValidBody);44 expect(routeReturn.status).toEqual(404);45 });46 it('should return status code 404 when the password is incorrect', async () => {47 const routeReturn = await supertest(server)48 .post(login.route)49 .send(wrongPasswordBody);50 expect(routeReturn.status).toEqual(404);...
index.js
Source: index.js
1const adapterManager = require('../../adapter-manager');2const createSessionService = require('@tryghost/session-service');3const sessionFromToken = require('@tryghost/mw-session-from-token');4const createSessionMiddleware = require('./middleware');5const expressSession = require('./express-session');6const models = require('../../../models');7const urlUtils = require('../../../../shared/url-utils');8const url = require('url');9function getOriginOfRequest(req) {10 const origin = req.get('origin');11 const referrer = req.get('referrer') || urlUtils.getAdminUrl() || urlUtils.getSiteUrl();12 if (!origin && !referrer || origin === 'null') {13 return null;14 }15 if (origin) {16 return origin;17 }18 const {protocol, host} = url.parse(referrer);19 if (protocol && host) {20 return `${protocol}//${host}`;21 }22 return null;23}24const sessionService = createSessionService({25 getOriginOfRequest,26 getSession: expressSession.getSession,27 findUserById({id}) {28 return models.User.findOne({id});29 }30});31module.exports = createSessionMiddleware({sessionService});32const ssoAdapter = adapterManager.getAdapter('sso');33// Looks funky but this is a "custom" piece of middleware34module.exports.createSessionFromToken = sessionFromToken({35 callNextWithError: false,36 createSession: sessionService.createSessionForUser,37 findUserByLookup: ssoAdapter.getUserForIdentity.bind(ssoAdapter),38 getLookupFromToken: ssoAdapter.getIdentityFromCredentials.bind(ssoAdapter),39 getTokenFromRequest: ssoAdapter.getRequestCredentials.bind(ssoAdapter)40});41module.exports.sessionService = sessionService;...
logout.test.js
Source: logout.test.js
...16 const user = userFactory();17 const token = uuidFactory();18 const validBody = logoutBodyFactory(user, token);19 beforeAll(async () => {20 await deleteAllSessions();21 await deleteAllUsers();22 const userId = (23 await insertUser({ ...user, password: hashPassword(user.password) })24 ).rows[0].id;25 await insertSession(userId, token);26 });27 afterAll(async () => {28 await deleteAllSessions();29 await deleteAllUsers();30 endConnection();31 });32 it('should return status code 200 when email is valid and password is correct', async () => {33 const routeReturn = await supertest(server)34 .post(logout.route)35 .send(validBody);36 const successfulLogout = await searchSession(user.uuid, token);37 expect(routeReturn.status).toEqual(200);38 expect(successfulLogout.rowCount).toEqual(0);39 });40 it("should return status code 404 when the session doesn't exist", async () => {41 const routeReturn = await supertest(server)42 .post(logout.route)...
sessionsTable.js
Source: sessionsTable.js
1import dbConnection from './connection.js';2const searchSession = (userUuid, token) =>3 dbConnection.query(4 `SELECT 5 users.id, users.name, users.email6 FROM users7 JOIN sessions8 ON sessions.user_id = users.id9 WHERE10 users.uuid = $1 AND11 sessions.token= $2;`,12 [userUuid, token]13 );14const insertSession = (userId, token) =>15 dbConnection.query(16 `17 INSERT INTO sessions (user_id, token)18 VALUES ($1, $2);19 `,20 [userId, token]21 );22const deleteSession = (id, token) =>23 dbConnection.query(24 `25 DELETE FROM sessions26 WHERE27 user_id = $1 AND28 token = $229 returning id30 ;`,31 [id, token]32 );33const deleteAllSessions = () => dbConnection.query('DELETE FROM sessions;');34function getToken(token) {35 return dbConnection.query(36 'SELECT users.* FROM sessions JOIN users ON users.id = sessions.user_id WHERE sessions.token = $1',37 [token]38 );39}40export {41 searchSession,42 insertSession,43 deleteSession,44 deleteAllSessions,45 getToken,...
actions.js
Source: actions.js
1import * as actionTypes from './actionTypes';2const initState = (state) => ({3 type: actionTypes.INIT_STATE,4 payload: {5 state: state,6 },7});8const createSession = title => ({9 type: actionTypes.CREATE_SESSION,10 payload: {11 title: title,12 },13});14const deleteSession = id => ({15 type: actionTypes.DELETE_SESSION,16 payload: {17 id: id,18 },19});20const deleteAllSessions = () => ({21 type: actionTypes.DELETE_ALL_SESSIONS,22 payload: {},23});24const addPhotoToSession = (sessionId, photo) => ({25 type: actionTypes.ADD_PHOTO_TO_SESSION,26 payload: {27 id: sessionId,28 photo,29 },30});31const deletePhotoFromSession = (sessionId, photoId) => ({32 type: actionTypes.DELETE_PHOTO_FROM_SESSION,33 payload: {34 sessionId,35 photoId36 },37});38export {39 initState,40 createSession,41 deleteSession,42 deleteAllSessions,43 addPhotoToSession,44 deletePhotoFromSession...
sessionControllers.js
Source: sessionControllers.js
...16}17function removeBooking(req, res) {18 sessionServices.removeBooking(req, res);19}20function deleteAllSessions(req, res) {21 sessionServices.deleteAllSessions(req, res);22}23module.exports = {24 getAllSessions,25 getSessionById,26 createSession,27 updateSeatInfo,28 bookSelectedSeats,29 removeBooking,30 deleteAllSessions...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({'browserName': 'chrome'})4 .build();5driver.deleteAllSessions();6driver.quit();7[debug] [MJSONWP] Calling AppiumDriver.deleteSession() with args: ["b8a1b0f3-0e2b-4a8b-8d6e-7e9f9a0e8a46"]8[debug] [BaseDriver] Event 'quitSessionRequested' logged at 1512170006365 (13:20:06 GMT+0530 (IST))9[debug] [BaseDriver] Event 'quitSessionFinished' logged at 1512170006367 (13:20:06 GMT+0530 (IST))10[debug] [MJSONWP] Responding to client with driver.deleteSession() result: null11package test;12import io.appium.java_client.AppiumDriver;13import io.appium.java_client.android.AndroidDriver;14import java.net.URL;15import org.openqa.selenium.remote.DesiredCapabilities;16public class test {
Using AI Code Generation
1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('firefox')5 .build();6driver.manage().deleteAllCookies();7driver.quit();8var webdriver = require('selenium-webdriver'),9 until = webdriver.until;10var driver = new webdriver.Builder()11 .forBrowser('firefox')12 .build();13driver.manage().deleteCookie('myCookie');14driver.quit();15var webdriver = require('selenium-webdriver'),16 until = webdriver.until;17var driver = new webdriver.Builder()18 .forBrowser('firefox')19 .build();20driver.manage().deleteCookieNamed('myCookie');21driver.quit();22var webdriver = require('selenium-webdriver'),23 until = webdriver.until;24var driver = new webdriver.Builder()25 .forBrowser('firefox')26 .build();27driver.executeAsyncScript('window.setTimeout(arguments[arguments.length - 1], 500);');28driver.quit();29var webdriver = require('selenium-webdriver'),30 until = webdriver.until;31var driver = new webdriver.Builder()32 .forBrowser('firefox')33 .build();34driver.executeScript('window.alert("Hello World!");');35driver.quit();
Using AI Code Generation
1const AppiumServer = require('appium-server');2const server = new AppiumServer();3server.deleteAllSessions();4const AppiumServer = require('appium-server');5const server = new AppiumServer();6server.start();7const AppiumServer = require('appium-server');8const server = new AppiumServer();9server.stop();10const AppiumServer = require('appium-server');11const server = new AppiumServer();12server.getLogs();13const AppiumServer = require('appium-server');14const server = new AppiumServer();15server.getStatus();16[MIT](LICENSE)
Check out the latest blogs from LambdaTest on this topic:
Were you able to work upon your resolutions for 2019? I may sound comical here but my 2019 resolution being a web developer was to take a leap into web testing in my free time. Why? So I could understand the release cycles from a tester’s perspective. I wanted to wear their shoes and see the SDLC from their eyes. I also thought that it would help me groom myself better as an all-round IT professional.
Technology is constantly evolving, what was state of art a few years back might be defunct now. Especially now, where the world of software development and testing is innovating ways to incorporate emerging technologies such as artificial intelligence, machine learning, big data, etc.
With the rapid evolution in technology and a massive increase of businesses going online after the Covid-19 outbreak, web applications have become more important for organizations. For any organization to grow, the web application interface must be smooth, user-friendly, and cross browser compatible with various Internet browsers.
Before starting this post on Unity testing, let’s start with a couple of interesting cases. First, Temple Run, a trendy iOS game, was released in 2011 (and a year later on Android). Thanks to its “infinity” or “never-ending” gameplay and simple interface, it reached the top free app on the iOS store and one billion downloads.
Let’s put it short: Appium Desktop = Appium Server + Inspector. When Appium Server runs automation test scripts, Appium Inspector can identify the UI elements of every application under test. The core structure of an Appium Inspector is to ensure that you discover every visible app element when you develop your test scripts. Before you kickstart your journey with Appium Inspector, you need to understand the details of it.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!