Best JavaScript code snippet using appium
ProgressionBuilderElementController.js
Source:ProgressionBuilderElementController.js
1/* eslint-disable no-underscore-dangle */2/* global insertTestInstance, removeTestInstance, QuestionAreaController, draggableXML, parseCssProperty */3'use strict';4$(document).ready(() => {5 const id = 3;6 const builder = insertTestInstance(draggableXML);7 QUnit.test('ProgressionBuilderElementController: Move multiple objects', assert => {8 const progression = builder._zyTool.progression;9 const cssProperties = [ 'left', 'top', 'height', 'width' ];10 const $draggableArea = $(`#${id} .draggable-area`);11 assert.ok($('.draggable-area').length, 'A draggable area exists');12 cssProperties.forEach(property => assert.equal($draggableArea.css(property), '0px'));13 // Select all elements, dragging from the elements at the: left, top, right, then bottom.14 const elementControllers = builder._controllers.find(controller =>15 controller instanceof QuestionAreaController16 )._elementControllers;17 const progressionHeight = parseInt(progression.height, 10);18 const progressionWidth = parseInt(progression.width, 10);19 const leftElement = elementControllers[0];20 const topElement = elementControllers[1];21 const rightElement = elementControllers[2];22 const bottomElement = elementControllers[3];23 const $left = leftElement._$element;24 const $top = topElement._$element;25 const $right = rightElement._$element;26 const $bottom = bottomElement._$element;27 const expectedDraggables = elementControllers.map(element => {28 const $element = element._$element;29 const left = parseCssProperty($element, 'left') - parseCssProperty($left, 'left');30 const top = parseCssProperty($element, 'top') - parseCssProperty($top, 'top');31 const height = progressionHeight - top - 1 -32 ((parseCssProperty($bottom, 'top') + parseInt($bottom.height(), 10)) -33 (parseCssProperty($element, 'top') + parseInt($element.height(), 10)));34 const width = progressionWidth - left - 1 -35 ((parseCssProperty($right, 'left') + parseInt($right.width(), 10)) -36 (parseCssProperty($element, 'left') + parseInt($element.width(), 10)));37 return {38 left: `${left}px`,39 top: `${top}px`,40 height: `${height}px`,41 width: `${width}px`,42 };43 });44 builder._selectElements(progression.elements);45 elementControllers.forEach((elementController, index) => {46 elementController._$element.mousedown();47 cssProperties.forEach(property =>48 assert.equal(parseCssProperty($draggableArea, property), parseInt(expectedDraggables[index][property], 10))49 );50 });51 });52 QUnit.test('ProgressionBuilderElementController: Move with arrow keys', assert => {53 const questionAreaController = builder._controllers.find(controller =>54 controller instanceof QuestionAreaController55 );56 let elementController = questionAreaController._elementControllers[0];57 builder._selectElement(elementController._element);58 const originalLeft = parseCssProperty(elementController._$element, 'left');59 const originalTop = parseCssProperty(elementController._$element, 'top');60 const leftArrowEvent = $.Event(`keydown.${id}`, { key: 'ArrowLeft' }); // eslint-disable-line new-cap61 const upArrowEvent = $.Event(`keydown.${id}`, { key: 'ArrowUp' }); // eslint-disable-line new-cap62 const rightArrowEvent = $.Event(`keydown.${id}`, { key: 'ArrowRight' }); // eslint-disable-line new-cap63 const downArrowEvent = $.Event(`keydown.${id}`, { key: 'ArrowDown' }); // eslint-disable-line new-cap64 // Test triggering events moves the element.65 $(window).trigger(leftArrowEvent);66 assert.equal(parseCssProperty(elementController._$element, 'left'), originalLeft - 1, 'Pressing left moves 1 pixel left');67 assert.equal(parseCssProperty(elementController._$element, 'top'), originalTop, 'Pressing left does not move vertically');68 $(window).trigger(upArrowEvent);69 assert.equal(parseCssProperty(elementController._$element, 'left'), originalLeft - 1, 'Pressing up does not move horizontally');70 assert.equal(parseCssProperty(elementController._$element, 'top'), originalTop - 1, 'Pressing up moves 1 pixel up');71 $(window).trigger(rightArrowEvent);72 assert.equal(parseCssProperty(elementController._$element, 'left'), originalLeft, 'Pressing right moves 1 pixel right');73 $(window).trigger(downArrowEvent);74 assert.equal(parseCssProperty(elementController._$element, 'top'), originalTop, 'Pressing down moves 1 pixel down');75 // Test switching to player deactivates the event handler.76 builder._switchToPlayer();77 $(window).trigger(rightArrowEvent);78 assert.equal(parseCssProperty(elementController._$element, 'left'), originalLeft, 'Pressing right on player does nothing');79 // Back to builder enables the event handler.80 builder._switchToBuilder();81 elementController = questionAreaController._elementControllers[0];82 $(window).trigger(rightArrowEvent);83 assert.equal(parseCssProperty(elementController._$element, 'left'), originalLeft + 1, 'Pressing right back on builder works');84 // Switching to code editor disables the event handler.85 builder._switchToCodeEditor('Global', builder._zyTool.progression);86 $(window).trigger(rightArrowEvent);87 assert.equal(parseCssProperty(elementController._$element, 'left'), originalLeft + 1, 'Pressing right on code editor does nothing');88 // Back to builder enables the event handler.89 builder._switchToBuilder();90 elementController = questionAreaController._elementControllers[0];91 $(window).trigger(rightArrowEvent);92 assert.equal(parseCssProperty(elementController._$element, 'left'), originalLeft + 2, 'Pressing right back on builder works'); // eslint-disable-line no-magic-numbers93 });94 QUnit.test('ProgressionBuilderElementController: Toggle select element', assert => {95 const elementControllers = builder._controllers.find(96 controller => controller instanceof QuestionAreaController97 )._elementControllers;98 assert.ok(elementControllers[0]._element.isSelected, 'First element is selected');99 assert.notOk(elementControllers[1]._element.isSelected, 'Second element is not selected');100 builder._toggleSelectElement(elementControllers[1]._element);101 assert.ok(elementControllers[1]._element.isSelected, 'Toggle second element, second element is now selected.');102 assert.ok(elementControllers[0]._element.isSelected, 'First element is still selected.');103 builder._toggleSelectElement(elementControllers[2]._element);104 builder._toggleSelectElement(elementControllers[3]._element);105 assert.ok(elementControllers.every(elementController => elementController._element.isSelected), 'Toggle remaining, all selected');106 builder._toggleSelectElement(elementControllers[1]._element);107 assert.notOk(elementControllers[1]._element.isSelected, 'Toggle second element, not selected.');108 builder._toggleSelectElement(elementControllers[0]._element);109 assert.notOk(elementControllers[0]._element.isSelected, 'Toggle first element, not selected.');110 assert.ok(elementControllers[2]._element.isSelected, 'Third element still selected');111 assert.ok(elementControllers[3]._element.isSelected, 'Forth element still selected');112 });113 removeTestInstance();...
index.js
Source:index.js
1import React, {PureComponent} from 'react';2//ELEMENTS3import Shape from './shape';4import Text from './text';5import Postit from './postit';6import Line from './line';7import Image from './image';8import Slide from './slide';9import Link from './link';10import Youtube from './youtube';11import Emoji from './emoji';12import Dice from './dice';13class Elements extends PureComponent {14 constructor(props, context) {15 super(props, context);16 this.state = {17 18 };19 }20 render() {21 const {22 elements,23 elementState,24 handleTextEdit,25 handleSetCurrentElement,26 isSelected,27 isUniqueSelected,28 zoomLevel,29 animateToElement,30 loadRemoteBoard,31 handleUpdateElementProperty32 } = this.props;33 const slides = [];34 const elementNodes = Object.keys(elements).map(elementID => {35 const element = elements[elementID];36 const lowDetail = (element.styles.width/zoomLevel < 20) && (element.styles.height/zoomLevel < 20);37 if (element.type === "shape") {38 return (<Shape39 key={element.id}40 data={element}41 styles={element.styles}42 fontStyles={element.fontStyles}43 elementState={elementState[element.id]}44 handleTextEdit={handleTextEdit}45 handleSetCurrentElement={handleSetCurrentElement}46 isSelected={isSelected}47 lowDetail={lowDetail}48 />);49 } else if (element.type === "text") {50 return (<Text 51 key={element.id}52 data={element}53 styles={element.styles}54 fontStyles={element.fontStyles}55 elementState={elementState[element.id]}56 handleTextEdit={handleTextEdit}57 handleSetCurrentElement={handleSetCurrentElement}58 isSelected={isSelected}59 isUniqueSelected={isUniqueSelected}60 lowDetail={lowDetail}61 />);62 } else if (element.type === "postit") {63 return (<Postit64 key={element.id}65 data={element}66 styles={element.styles}67 fontStyles={element.fontStyles}68 elementState={elementState[element.id]}69 handleTextEdit={handleTextEdit}70 handleSetCurrentElement={handleSetCurrentElement}71 isSelected={isSelected}72 lowDetail={lowDetail}73 />);74 } else if (element.type === "line") {75 return (<Line76 key={element.id}77 data={element}78 styles={element.styles}79 fontStyles={element.fontStyles}80 elementState={elementState[element.id]}81 handleTextEdit={handleTextEdit}82 handleSetCurrentElement={handleSetCurrentElement}83 isSelected={isSelected}84 lowDetail={lowDetail}85 />);86 } else if (element.type === "image") {87 return (<Image88 key={element.id}89 data={element}90 styles={element.styles}91 fontStyles={element.fontStyles}92 elementState={elementState[element.id]}93 handleTextEdit={handleTextEdit}94 handleSetCurrentElement={handleSetCurrentElement}95 isSelected={isSelected}96 lowDetail={lowDetail}97 />);98 } else if (element.type === "slide") {99 slides.push(element.id);100 return (<Slide101 key={element.id}102 data={element}103 styles={element.styles}104 fontStyles={element.fontStyles}105 elementState={elementState[element.id]}106 handleTextEdit={handleTextEdit}107 handleSetCurrentElement={handleSetCurrentElement}108 isSelected={isSelected}109 slideNumber={slides.length}110 lowDetail={lowDetail}111 />);112 } else if (element.type === "link") {113 slides.push(element.id);114 return (<Link115 key={element.id}116 data={element}117 styles={element.styles}118 fontStyles={element.fontStyles}119 elementState={elementState[element.id]}120 handleSetCurrentElement={handleSetCurrentElement}121 isSelected={isSelected}122 lowDetail={lowDetail}123 animateToElement={animateToElement}124 loadRemoteBoard={loadRemoteBoard}125 />);126 } else if (element.type === "youtube") {127 return (<Youtube128 key={element.id}129 data={element}130 styles={element.styles}131 fontStyles={element.fontStyles}132 elementState={elementState[element.id]}133 handleTextEdit={handleTextEdit}134 handleSetCurrentElement={handleSetCurrentElement}135 isSelected={isSelected}136 lowDetail={lowDetail}137 />);138 } else if (element.type === "emoji") {139 return (<Emoji140 key={element.id}141 data={element}142 styles={element.styles}143 fontStyles={element.fontStyles}144 elementState={elementState[element.id]}145 handleSetCurrentElement={handleSetCurrentElement}146 isSelected={isSelected}147 lowDetail={lowDetail}148 />);149 } else if (element.type === "dice") {150 return (<Dice151 key={element.id}152 data={element}153 styles={element.styles}154 fontStyles={element.fontStyles}155 elementState={elementState[element.id]}156 handleSetCurrentElement={handleSetCurrentElement}157 handleUpdateElementProperty={handleUpdateElementProperty}158 isSelected={isSelected}159 lowDetail={lowDetail}160 />);161 }162 return null;163 });164 165 return (166 <>167 {elementNodes}168 </>169 );170 }171 172 }...
Header.js
Source:Header.js
1import React, { useEffect, useState } from 'react';2import Link from 'next/link';3import {4 Container,5 ListElement,6 LogoContainer,7 UnorderedList,8 Wrapper,9 MenuButtonContainer,10 MenuButton,11 MobileWrapper,12 NavContainer,13 MobileNav,14 Bullet,15 BulletContainer,16 StyledImage,17 TagLine,18} from './Header.styles';19import Logo from '../../public/logo.png';20import { Button } from '../Button';21import { LARGE_MIN } from '../../theme/theme';22import { useWindowWidth } from '../../hooks/useWindowWidth';23import {24 HOME_URL,25 ABOUT_URL,26 RESSOURCES_URL,27 NEW_JOBPOST_URL,28} from '../../constants/routes';29const MENU = {30 ABOUT: 'Pourquoi choisir Télétaf?',31 HOME: 'Annonces',32 RESSOURCES: 'Ressources',33};34export function Header({ pathname }) {35 const [isMobileMenuOpened, setIsMobileMenuOpened] = useState(false);36 const [isLarge, setIsLarge] = useState(false);37 const { windowWidth } = useWindowWidth();38 useEffect(() => {39 setIsMobileMenuOpened(false);40 }, [pathname]);41 useEffect(() => {42 if (windowWidth > LARGE_MIN) {43 setIsLarge(true);44 } else {45 setIsLarge(false);46 }47 }, [isLarge, setIsLarge, windowWidth]);48 return isLarge ? (49 <Wrapper>50 <Container>51 <Link href="/">52 <LogoContainer>53 <StyledImage54 alt="teletaf logo"55 src={Logo}56 width="153"57 height="35"58 />59 <TagLine>Trouvez un CDI en télétravail</TagLine>60 </LogoContainer>61 </Link>62 <nav>63 <UnorderedList>64 <ListElement isSelected={pathname === ABOUT_URL}>65 <Link href={ABOUT_URL}>{MENU.ABOUT}</Link>66 <BulletContainer>67 <Bullet />68 </BulletContainer>69 </ListElement>70 <ListElement isSelected={pathname === HOME_URL}>71 <Link href={HOME_URL}>{MENU.HOME}</Link>72 <BulletContainer>73 <Bullet />74 </BulletContainer>75 </ListElement>76 <ListElement isSelected={pathname.includes(RESSOURCES_URL)}>77 <Link href={RESSOURCES_URL}>{MENU.RESSOURCES}</Link>78 <BulletContainer>79 <Bullet />80 </BulletContainer>81 </ListElement>82 </UnorderedList>83 </nav>84 <Button85 as="a"86 href={NEW_JOBPOST_URL}87 target="_self"88 rel="noreferrer noopener"89 >90 Publier mon annonce91 </Button>92 </Container>93 </Wrapper>94 ) : (95 <MobileWrapper>96 <MenuButtonContainer97 onClick={() => setIsMobileMenuOpened(!isMobileMenuOpened)}98 >99 <MenuButton isOpen={isMobileMenuOpened}>100 <svg width="32" height="32" viewBox="0 0 100 100">101 <path102 className="line line1"103 d="M 20,29.000046 H 80.000231 C 80.000231,29.000046 94.498839,28.817352 94.532987,66.711331 94.543142,77.980673 90.966081,81.670246 85.259173,81.668997 79.552261,81.667751 75.000211,74.999942 75.000211,74.999942 L 25.000021,25.000058"104 />105 <path className="line line2" d="M 20,50 H 80" />106 <path107 className="line line3"108 d="M 20,70.999954 H 80.000231 C 80.000231,70.999954 94.498839,71.182648 94.532987,33.288669 94.543142,22.019327 90.966081,18.329754 85.259173,18.331003 79.552261,18.332249 75.000211,25.000058 75.000211,25.000058 L 25.000021,74.999942"109 />110 </svg>111 </MenuButton>112 </MenuButtonContainer>113 <NavContainer isOpen={isMobileMenuOpened}>114 <MobileNav>115 <UnorderedList>116 <ListElement isSelected={pathname === ABOUT_URL}>117 <Link href={ABOUT_URL}>{MENU.ABOUT}</Link>118 <BulletContainer>119 <Bullet />120 </BulletContainer>121 </ListElement>122 <ListElement isSelected={pathname === HOME_URL}>123 <Link href={HOME_URL}>{MENU.HOME}</Link>124 <BulletContainer>125 <Bullet />126 </BulletContainer>127 </ListElement>128 <ListElement isSelected={pathname.includes(RESSOURCES_URL)}>129 <Link href={RESSOURCES_URL}>{MENU.RESSOURCES}</Link>130 <BulletContainer>131 <Bullet />132 </BulletContainer>133 </ListElement>134 </UnorderedList>135 </MobileNav>136 </NavContainer>137 </MobileWrapper>138 );...
SearchNadine.js
Source:SearchNadine.js
1import React, {useState} from 'react';2import { View, Image, Text, Alert, TextInput } from 'react-native';3// Local imports4import logo from '../../assets/logo.png';5import styles from './styles';6import ButtonFilter from '../../components/ButtonTemplate/ButtonFilter';7import Form from '../../components/FormTemplate/index';8import FabsTemplate from '../../components/FabsTemplate/index';9const Separator = () => (10 <View style={styles.separator} />11);12const editForm = [13 {14 id: 1,15 render: 'date',16 label: 'Start Date',17 value: new Date()18 },19 {20 id:2,21 render: 'date',22 label: 'End Date',23 value: new Date()24 }25];26const SearchScreen = props => {27 const onLongPress= () => {28 Alert.alert('jai ete clicker') // TODO29 }30 const activities = [{31 name : "Restaurant",32 isSelected: false33 },34 {35 name : "Bar",36 isSelected: false37 },38 {39 name : "Afterwork",40 isSelected: false41 }42 ];43 const [selectedActivities, setSelectedActivities] = useState(activities);44 const selectActivity = (activity ) => {45 const updatedSelectedActivities = selectedActivities.map(element => {46 if(element.name == activity){47 return({48 ...element,49 isSelected: !element.isSelected50 })51 } else {52 return({...element})53 }54 });55 setSelectedActivities(updatedSelectedActivities)56 }57 const hostGenders = [{58 name: "Female",59 isSelected : false60 },61 {62 name: "Male",63 isSelected :false64 }65 ];66 const [selectedGenders, setSelectedGenders] = useState(hostGenders);67 const selectGender = (gender) => {68 const updatedSelectedGenders = selectedGenders.map(element => {69 if(element.name === gender){70 return({71 ...element,72 isSelected: !element.isSelected73 })74 } else {75 return({...element})76 }77 });78 setSelectedGenders(updatedSelectedGenders)79 }80 const keywords= [{81 name: "Bruxelles",82 isSelected: false83 },84 {85 name: "Museum",86 isSelected: false87 }88 ]89 const [selectedKeywords, setSelectedKeywords] = useState(keywords);90 const selectKeyword = (keyword) => {91 const updatedSelectedKeywords = selectedKeywords.map(element => {92 if(element.name == keyword){93 return({94 ...element,95 isSelected: !element.isSelected96 })97 } else {98 return({...element})99 }100 });101 setSelectedKeywords(updatedSelectedKeywords)102 }103 return (104 <View style={styles.container}>105 <Image style={styles.logo} source={logo} />106 <Text style={styles.filter}>My Filters</Text>107 <Separator />108 <Text style={styles.filtertext}>ACTIVITY</Text>109 <View style= {styles.containerFilter}>110 {selectedActivities.map((activity) => {111 // console.log(activity)112 return(113 <ButtonFilter key={activity.name} text={activity.name} handlePress={selectActivity} isSelected={activity.isSelected}/>114 )115 })}116 </View>117 <Separator />118 <Text style={styles.filtertext}>HOSTED BY</Text>119 <View style={styles.containerFilter}>120 {selectedGenders.map(gender => {121 return(122 <ButtonFilter key={gender.name} text={gender.name} handlePress={selectGender} isSelected={gender.isSelected} />123 )124 })}125 </View>126 <Separator />127 <Text style={styles.filtertext}>KEYWORDS</Text>128 <View style={styles.containerFilter}>129 {selectedKeywords.map(keyword => {130 return(131 <ButtonFilter key={keyword.name} text={keyword.name} handlePress={selectKeyword} isSelected={keyword.isSelected} />132 )133 })}134 </View>135 <Separator />136 {/* <FabsTemplate onLongPress={onLongPress} name={'pencil-circle-outline'} color={"black"} /> */}137 <Text style={styles.filtertext}>DATE</Text>138 <View style={styles.containerFilterDate}>139 <Form inputs={editForm} onSubmit={val => console.log(val) //TODO140 } />141 </View>142 </View>143 );144};...
ElementUIFactory.js
Source:ElementUIFactory.js
1import {2 Col,3 Form4} from 'react-bootstrap';567class ElementUIFactory {8 static getUIElement(element, isSelected, onChange) {9 if(element.type === "INPUT") {10 return ElementUIFactory.renderInput(element, isSelected, onChange);11 }12 else if(element.type === "SELECT") {13 return ElementUIFactory.renderSelect(element, isSelected, onChange);14 }15 else if(element.type === "RADIO") {16 return ElementUIFactory.renderRadio(element, isSelected, onChange);17 }18 else if(element.type === "TEXTAREA") {19 return ElementUIFactory.renderTextarea(element, isSelected, onChange);20 }21 return <div> No such element </div>;22 }2324 static renderInput(element, isSelected, onChange) {25 return (26 <Col27 className="form-col-spacing"28 md={element.columns}29 key={element.id + "-col"}30 style={isSelected ? {backgroundColor: "#fff3cd"} : {} }31 >32 <Form.Label> {element.label} </Form.Label>33 <Form.Control34 id={element.id}35 required={element.required}36 type="text"37 placeholder={element.placeholder}38 onChange={(e) => {onChange(element.id, element.name, e.target.value)}}39 />40 </Col>41 );42 }4344 static renderSelect(element, isSelected, onChange) {45 return (46 <Col47 className="form-col-spacing"48 md={element.columns}49 key={element.id + "-col"}50 style={isSelected ? {backgroundColor: "#fff3cd"} : {} }51 >52 <Form.Label> {element.label} </Form.Label>53 <Form.Select54 id={element.id}55 required={element.required}56 onChange={(e) => {onChange(element.id, element.name, e.target.value)}}57 >58 <option value=""> Select </option>59 {element.options.map((option, index) => {60 return (61 <option value={option.value} key={element.id + "-option" + index.toString()}>62 {option.display}63 </option>64 );65 })}66 </Form.Select>67 </Col>68 );69 }7071 static renderRadio(element, isSelected, onChange) {72 return (73 <Col74 md={element.columns}75 key={element.id + "-col"}76 className="form-col-spacing"77 style={isSelected ? {backgroundColor: "#fff3cd"} : {} }78 >79 <Form.Label style={{marginRight: "10px"}}> {element.label} </Form.Label>80 <Form.Check81 inline82 id={element.id + "radio1"}83 label={element.label1}84 type="radio"85 name={"radioGroup-" + element.id}86 value={element.value1}87 required={element.required}88 onChange={(e) => {onChange(element.id, element.name, e.target.value)}}89 />90 <Form.Check91 inline92 id={element.id + "radio2"}93 label={element.label2}94 type="radio"95 name={"radioGroup-" + element.id}96 value={element.value2}97 required={element.required}98 onChange={(e) => {onChange(element.id, element.name, e.target.value)}}99 />100 </Col>101 );102 }103104 static renderTextarea(element, isSelected, onChange) {105 return (106 <Col107 md={element.columns}108 key={element.id + "-col"}109 className="form-col-spacing"110 style={isSelected ? {backgroundColor: "#fff3cd"} : {} }111 >112 <Form.Label> {element.label} </Form.Label>113 <Form.Control114 id={element.id}115 as="textarea"116 rows={element.rows}117 required={element.required}118 placeholder={element.placeholder}119 onChange={(e) => {onChange(element.id, element.name, e.target.value)}}120 />121 </Col>122 );123 }124}125126
...
isNotSelected.js
Source:isNotSelected.js
1/*global module, element, protractor, by, browser, expect*/2(function () {3 'use strict';4 5 module.exports = function () {6 7 this.byId = function (element) {8 expect(element(by.id(element)).isSelected()).toBe(false, 'Element is selected!');9 };10 11 this.byCss = function (element) {12 expect(element(by.css(element)).isSelected()).toBe(false, 'Element is selected!');13 };14 15 this.byModel = function (element) {16 expect(element(by.model(element)).isSelected()).toBe(false, 'Element is selected!');17 };18 19 this.byClassName = function (element) {20 expect(element(by.className(element)).isSelected()).toBe(false, 'Element is selected!');21 };22 23 this.byCssContainingText = function (element, text) {24 expect(element(by.cssContainingText(element, text)).isSelected()).toBe(false, 'Element is selected!');25 };26 27 this.byName = function (element) {28 expect(element(by.name(element)).isSelected()).toBe(false, 'Element is selected!');29 };30 31 this.byBinding = function (element) {32 expect(element(by.binding(element)).isSelected()).toBe(false, 'Element is selected!');33 };34 35 this.byExactBinding = function (element) {36 expect(element(by.exactBinding(element)).isSelected()).toBe(false, 'Element is selected!');37 };38 39 this.byButtonText = function (element) {40 expect(element(by.buttonText(element)).isSelected()).toBe(false, 'Element is selected!');41 };42 43 this.byPartialButtonText = function (element) {44 expect(element(by.partialButtonText(element)).isSelected()).toBe(false, 'Element is selected!');45 };46 47 this.byExactRepeater = function (element) {48 expect(element(by.exactRepeater(element)).isSelected()).toBe(false, 'Element is selected!');49 };50 51 this.byTagName = function (element) {52 expect(element(by.tagName(element)).isSelected()).toBe(false, 'Element is selected!');53 };54 55 this.byXpath = function (element) {56 expect(element(by.xpath(element)).isSelected()).toBe(false, 'Element is selected!');57 };58 };...
isSelected.js
Source:isSelected.js
1/*global module, element, protractor, by, browser, expect*/2(function () {3 'use strict';4 5 module.exports = function () {6 7 this.byId = function (element) {8 expect(element(by.id(element)).isSelected()).toBe(true, 'Element is available!');9 };10 11 this.byCss = function (element) {12 expect(element(by.css(element)).isSelected()).toBe(true, 'Element is available!');13 };14 15 this.byModel = function (element) {16 expect(element(by.model(element)).isSelected()).toBe(true, 'Element is available!');17 };18 19 this.byClassName = function (element) {20 expect(element(by.className(element)).isSelected()).toBe(true, 'Element is available!');21 };22 23 this.byCssContainingText = function (element, text) {24 expect(element(by.cssContainingText(element, text)).isSelected()).toBe(true, 'Element is available!');25 };26 27 this.byName = function (element) {28 expect(element(by.name(element)).isSelected()).toBe(true, 'Element is available!');29 };30 31 this.byBinding = function (element) {32 expect(element(by.binding(element)).isSelected()).toBe(true, 'Element is available!');33 };34 35 this.byExactBinding = function (element) {36 expect(element(by.exactBinding(element)).isSelected()).toBe(true, 'Element is available!');37 };38 39 this.byButtonText = function (element) {40 expect(element(by.buttonText(element)).isSelected()).toBe(true, 'Element is available!');41 };42 43 this.byPartialButtonText = function (element) {44 expect(element(by.partialButtonText(element)).isSelected()).toBe(true, 'Element is available!');45 };46 47 this.byExactRepeater = function (element) {48 expect(element(by.exactRepeater(element)).isSelected()).toBe(true, 'Element is available!');49 };50 51 this.byTagName = function (element) {52 expect(element(by.tagName(element)).isSelected()).toBe(true, 'Element is available!');53 };54 55 this.byXpath = function (element) {56 expect(element(by.xpath(element)).isSelected()).toBe(true, 'Element is available!');57 };58 };...
Bars_v2.js
Source:Bars_v2.js
1import React, { useReducer } from "react";2const initialState = [3 { id: 1, isSelected: false, name: "bar1" },4 { id: 2, isSelected: false, name: "bar2" },5 { id: 3, isSelected: false, name: "bar3" },6 { id: 4, isSelected: true, name: "bar4" },7 { id: 5, isSelected: true, name: "bar5" },8];9/*10it's a refactored version of the Bar.js component11but has some issue12it has some bugs in the reducer() function, 13when selecting/clicking on any bar, all bars disappear from the screen14need to be fixed15*/16const reducer = (state, action) => {17 switch (action.type) {18 case "SELECTED":19 state &&20 state.map((element) => {21 //22 //23 if (element.isSelected === false) {24 if (element.id >= action.payload) {25 element.isSelected = true;26 return element.isSelected;27 } else {28 element.isSelected = false;29 return element.isSelected;30 }31 } else {32 element.isSelected = true;33 return element.isSelected;34 }35 });36 break;37 default:38 return state;39 }40};41const Bars = () => {42 const [state, dispatch] = useReducer(reducer, initialState);43 return (44 <>45 <div className="bars">46 {state &&47 state.map((element) => {48 return (49 <div50 key={element.id}51 className={52 element.isSelected53 ? `activeColor bar ${element.name}`54 : `inActiveColor bar ${element.name}`55 }56 onClick={() =>57 dispatch({ type: "SELECTED", payload: element.id })58 }59 ></div>60 );61 })}62 </div>63 </>64 );65};...
Using AI Code Generation
1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.findElement(By.name('q')).sendKeys('webdriver');7driver.findElement(By.name('btnG')).click();8driver.wait(until.titleIs('webdriver - Google Search'), 1000);9driver.quit();10driver.findElement(By.name("q")).sendKeys("webdriver");11driver.findElement(By.name("btnG")).click();12driver.wait(until.titleIs('webdriver - Google Search'), 1000);13driver.quit();14driver.findElement(By.name("q")).sendKeys("webdriver");15driver.findElement(By.name("btnG")).click();16driver.wait(until.titleIs('webdriver - Google Search'), 1000);17driver.quit();18driver.findElement(By.name("q")).sendKeys("webdriver");19driver.findElement(By.name("btnG")).click();20driver.wait(until.titleIs('webdriver - Google Search'), 1000);21driver.quit();22driver.findElement(By.name("q")).sendKeys("webdriver");23driver.findElement(By.name("btnG")).click();24driver.wait(until.titleIs('webdriver - Google Search'), 1000);25driver.quit();26driver.findElement(By.name("q")).sendKeys("webdriver");27driver.findElement(By.name("btnG")).click();28driver.wait(until.titleIs('webdriver - Google Search'), 1000);29driver.quit();30driver.findElement(By.name("q")).sendKeys("webdriver");31driver.findElement(By.name("btnG")).click();32driver.wait(until.titleIs('webdriver - Google Search'), 1000);33driver.quit();34driver.findElement(By.name("q")).sendKeys("webdriver");35driver.findElement(By.name("btnG")).click();36driver.wait(until.titleIs('webdriver - Google Search'), 1000);37driver.quit();38driver.findElement(By.name("q")).sendKeys("webdriver");39driver.findElement(By.name("btnG")).click();40driver.wait(until.titleIs('webdriver - Google Search'), 1000);41driver.quit();42driver.get("http
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');7driver.findElement(webdriver.By.name('btnG')).click();8driver.wait(function() {9 return driver.getTitle().then(function(title) {10 return title === 'webdriver - Google Search';11 });12}, 1000);13driver.quit();14driver.findElement(webdriver.By.name('q')).isSelected().then(function(isSelected) {15 console.log(isSelected);16});17I am trying to use the isSelected method of selenium web driver. I am using the below code to achieve this. But the console.log(isSelected) is returning false. I am not sure why this is happening. I have tried using the Appium inspector and I am able to see that the element is selected. I am not sure why the isSelected method is returning false. Can someone please help me with this?18driver.findElement(webdriver.By.name('q')).isSelected().then(function(isSelected) {19 console.log(isSelected);20});21driver.findElement(webdriver.By.name('q')).isSelected().then(function(isSelected) {22 console.log(isSelected);23});24driver.findElement(webdriver.By.name('q')).isSelected().then(function(isSelected) {25 console.log(isSelected);26});27driver.findElement(webdriver.By.name('q')).isSelected().then(function(isSelected) {28 console.log(isSelected);29});
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var By = webdriver.By;3var until = webdriver.until;4var driver = new webdriver.Builder()5 .forBrowser('chrome')6 .build();7driver.findElement(By.name('q')).sendKeys('webdriver');8driver.findElement(By.name('btnK')).click();9driver.wait(until.titleIs('webdriver - Google Search'), 1000);10driver.quit();11var webdriver = require('selenium-webdriver');12var By = webdriver.By;13var until = webdriver.until;14var driver = new webdriver.Builder()15 .forBrowser('chrome')16 .build();17driver.findElement(By.name('q')).sendKeys('webdriver');18driver.findElement(By.name('btnK')).click();19driver.wait(until.titleIs('webdriver - Google Search'), 1000);20driver.quit();21var webdriver = require('selenium-webdriver');22var By = webdriver.By;23var until = webdriver.until;24var driver = new webdriver.Builder()25 .forBrowser('chrome')26 .build();27driver.findElement(By.name('q')).sendKeys('webdriver');28driver.findElement(By.name('btnK')).click();29driver.wait(until.titleIs('webdriver - Google Search'), 1000);30driver.quit();31var webdriver = require('selenium-webdriver');32var By = webdriver.By;33var until = webdriver.until;34var driver = new webdriver.Builder()35 .forBrowser('chrome')36 .build();37driver.findElement(By.name('q')).sendKeys('webdriver');38driver.findElement(By.name('btnK')).click();39driver.wait(until.titleIs('webdriver - Google Search'), 1000);40driver.quit();41var webdriver = require('selenium-webdriver');42var By = webdriver.By;43var until = webdriver.until;44var driver = new webdriver.Builder()45 .forBrowser('chrome')46 .build();47driver.findElement(By.name('q')).sendKeys('webdriver');48driver.findElement(By.name('btnK')).click();49driver.wait(until.titleIs('webdriver - Google Search'), 1000);50driver.quit();
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').build();3var searchBox = driver.findElement(webdriver.By.name('q'));4searchBox.sendKeys('webdriver');5searchBox.getAttribute('value').then(function(value) {6});7driver.quit();8var webdriver = require('selenium-webdriver');9var driver = new webdriver.Builder().forBrowser('chrome').build();10var searchBox = driver.findElement(webdriver.By.name('q'));11searchBox.sendKeys('webdriver');12searchBox.getAttribute('value').then(function(value) {13});14driver.quit();15var webdriver = require('selenium-webdriver');16var driver = new webdriver.Builder().forBrowser('chrome').build();17var searchBox = driver.findElement(webdriver.By.name('q'));18searchBox.sendKeys('webdriver');19searchBox.getAttribute('value').then(function(value) {20});21driver.quit();22var webdriver = require('selenium-webdriver');23var driver = new webdriver.Builder().forBrowser('chrome').build();24var searchBox = driver.findElement(webdriver.By.name('q'));25searchBox.sendKeys('webdriver');26searchBox.getAttribute('value').then(function(value) {27});28driver.quit();29var webdriver = require('selenium-webdriver');30var driver = new webdriver.Builder().forBrowser('chrome').build();31var searchBox = driver.findElement(webdriver.By.name('q'));32searchBox.sendKeys('webdriver');33searchBox.getAttribute('value').then(function(value) {34});35driver.quit();36var webdriver = require('selenium-webdriver');37var driver = new webdriver.Builder().forBrowser('chrome').build();38var searchBox = driver.findElement(webdriver.By.name('q'));39searchBox.sendKeys('webdriver');
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').build();3var element = driver.findElement(webdriver.By.name('q'));4element.sendKeys('webdriver');5element.submit();6driver.findElement(webdriver.By.name('btnG')).click();7driver.wait(function() {8 return driver.getTitle().then(function(title) {9 return title === 'webdriver - Google Search';10 });11}, 1000);12driver.quit();13var webdriver = require('selenium-webdriver');14var driver = new webdriver.Builder().forBrowser('chrome').build();15var element = driver.findElement(webdriver.By.name('q'));16element.sendKeys('webdriver');17element.submit();18driver.findElement(webdriver.By.name('btnG')).click();19driver.wait(function() {20 return driver.getTitle().then(function(title) {21 return title === 'webdriver - Google Search';22 });23}, 1000);24driver.quit();25var webdriver = require('selenium-webdriver');26var driver = new webdriver.Builder().forBrowser('chrome').build();27var element = driver.findElement(webdriver.By.name('q'));28element.sendKeys('webdriver');29element.submit();30driver.findElement(webdriver.By.name('btnG')).click();31driver.wait(function() {32 return driver.getTitle().then(function(title) {33 return title === 'webdriver - Google Search';34 });35}, 1000);36driver.quit();37var webdriver = require('selenium-webdriver');38var driver = new webdriver.Builder().forBrowser('chrome').build();39var element = driver.findElement(webdriver.By.name('q'));40element.sendKeys('webdriver');41element.submit();42driver.findElement(webdriver.By.name('btnG')).click();43driver.wait(function() {44 return driver.getTitle().then(function(title) {45 return title === 'webdriver - Google Search';46 });47}, 1000);48driver.quit();49var webdriver = require('selenium-webdriver');50var driver = new webdriver.Builder().forBrowser('chrome').build();
Using AI Code Generation
1var wd = require('wd');2var chai = require('chai');3var expect = chai.expect;4var assert = chai.assert;5var should = chai.should();6var asserters = wd.asserters;7var driver = wd.promiseChainRemote('localhost', 4723);8var desiredCaps = {9};10 .init(desiredCaps)11 .sleep(2000)12 .elementByName('2. Dark Theme')13 .click()14 .sleep(2000)15 .elementByName('Checkbox 1')16 .isSelected()17 .then(function(isSelected) {18 console.log(isSelected);19 })20 .elementByName('Checkbox 1')21 .click()22 .elementByName('Checkbox 1')23 .isSelected()24 .then(function(isSelected) {25 console.log(isSelected);26 })27 .quit();28var webdriverio = require(‘webdriverio’);29var options = {30desiredCapabilities: {31}32};33var client = webdriverio.remote(options);34.init()35.setValue(‘#lst-ib’, ‘webdriverio’)36.click(‘#tsbb’)37.getTitle().then(function(title) {38console.log(‘Title was: ‘ + title);39})40.end();41client.isSelected(‘#lst-ib’).then(function(isSelected) {42console.log(isSelected);43});
Using AI Code Generation
1describe('Test for element.isSelected', function() {2 it('should return true if checkbox is selected', function() {3 return driver.elementById('checkbox').isSelected().should.become(true);4 });5});6describe('Test for element.selected', function() {7 it('should return true if checkbox is selected', function() {8 return driver.elementById('checkbox').selected().should.become(true);9 });10});11describe('Test for element.clear', function() {12 it('should clear the text field', function() {13 return driver.elementById('textfield').clear();14 });15});16describe('Test for element.getAttribute', function() {17 it('should return the value of the attribute', function() {18 return driver.elementById('textfield').getAttribute('value').should.become('Hello Appium!');19 });20});21describe('Test for element.getComputedCss', function() {22 it('should return the value of the CSS property
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!!