Best Python code snippet using fMBT_python
BuyMe.py
Source:BuyMe.py
1#import relevant packages and classes for testing use2from selenium import webdriver3from selenium.webdriver.common.keys import Keys4import time5#save chrome selenium webdriver in variable, open chrome browser6driverChrome = webdriver.Chrome(executable_path='C:/DevOps/Class 2/chromedriver_win32/chromedriver.exe')7#define element waiting time rule8driverChrome.implicitly_wait(10)9#open txt file and read the content to variable and open BuyMe internet page10webSiteFile = open("C:/DevOps/First Project/URL_WebSite.txt", 'r', encoding='UTF-8')11URL = webSiteFile.read()12driverChrome.get(URL)13# maximize browser window14driverChrome.maximize_window()15#save class element in variable and click on it(×× ×ס×|×רש××)16enterRegistrationWindow = driverChrome.find_element_by_class_name("seperator-link")17enterRegistrationWindow.click()18#19# #save class element in variable and click on it (×רש××)20# enterRegistration = driverChrome.find_element_by_class_name("text-btn")21# enterRegistration.click()22#23# #save element in variable and print the name on inputBox24# firstName = driverChrome.find_element_by_id("ember1019")25# firstName.send_keys("Bruce")26#27# #save element in variable and print the email on inputBox28# email = driverChrome.find_element_by_id("ember1021")29# email.send_keys("BruceSpringsteen1984@gmail.com")30#31# password = driverChrome.find_element_by_id("valPass")32# password.send_keys("Abcd1234!")33#34#35# rePassword = driverChrome.find_element_by_id("ember1025")36# rePassword.send_keys("Abcd1234!")37#38#39# # because checkbox not clickable by python selenium i used "execute_script" to click the checkbox40# driverChrome.execute_script("arguments[0].click();", driverChrome.find_element_by_id("ember1026-id"))41#42#43# pressSingButton = driverChrome.find_element_by_class_name("ui-btn")44# pressSingButton.click()45#46# for enters without registration each Python script running47# enter mail48mailEnter = driverChrome.find_element_by_id("ember1005")49mailEnter.send_keys("BruceSpringsteen1984@gmail.com")50#enter password51passwordEnter = driverChrome.find_element_by_id("ember1007")52passwordEnter.send_keys("Abcd1234!")53#press enter button54enterBuyMeButton = driverChrome.find_element_by_class_name("ui-btn")55enterBuyMeButton.click()56# wait to sec57time.sleep(2)58#open drop list of pickAmount59pickSum = driverChrome.find_element_by_xpath("//*[@id='ember664_chosen']/a")60pickSum.click()61#select amount of 99-199 NIS62SelectAmount = driverChrome.find_element_by_xpath("//*[@id='ember664_chosen']/div/ul/li[3]")63SelectAmount.click()64#open drop list of Area65pickArea = driverChrome.find_element_by_xpath("//*[@id='ember679_chosen']/a")66pickArea.click()67#select south Area68selectArea = driverChrome.find_element_by_xpath("//*[@id='ember679_chosen']/div/ul/li[5]")69selectArea.click()70#open drop list of Category71pickCategory = driverChrome.find_element_by_xpath("//*[@id='ember688_chosen']/a")72pickCategory.click()73#select category74selectCategory = driverChrome.find_element_by_xpath("//*[@id='ember688_chosen']/div/ul/li[5]")75selectCategory.click()76#Press search button77presssearchButton = driverChrome.find_element_by_id("ember723")78presssearchButton.click()79#select busines80pickBusiness = driverChrome.find_element_by_xpath("//*[@id='ember1165']/div")81pickBusiness.click()82#selectGiftAmount83selectGiftAmount = driverChrome.find_element_by_id("ember1215")84selectGiftAmount.send_keys("154")85time.sleep(2)86#Press choose Button87pressChoose = driverChrome.find_element_by_xpath("//*[@id='ember1214']/div[2]/div/button")88pressChoose.click()89#select to else90giftTo = driverChrome.find_element_by_xpath("//*[@id='ember1280']/label[1]")91giftTo.click()92time.sleep(2)93#Gift to94driverChrome.find_element_by_id("ember1308").clear()95EnterGiftreceiver = driverChrome.find_element_by_id("ember1308").send_keys("James")96driverChrome.find_element_by_id("ember1310").clear()97EnterSenderreceiver = driverChrome.find_element_by_id("ember1310").send_keys("Superman")98clearText = driverChrome.find_element_by_xpath("//*[@id='ember1327']/textarea").clear()99time.sleep(2)100EnterSender = driverChrome.find_element_by_xpath("//*[@id='ember1327']/textarea").send_keys("××× ××× ××××...×¢× 120")101Enterreceiver = driverChrome.find_element_by_xpath("//*[@id='ember1336']").send_keys("C:\DevOps\First Project\yomholedet.jpg")102time.sleep(2)103#select event104openEvents = driverChrome.find_element_by_xpath("//*[@id='ember1312_chosen']/a").click()105selectEvent = driverChrome.find_element_by_xpath("//*[@id='ember1312_chosen']/div/ul/li[5]").click()106#pay time107payTime = driverChrome.find_element_by_class_name("send-now").click()108#selectSMSMethod109selectSMS = driverChrome.find_element_by_xpath("//*[@id='ember1273']/div[4]/div/div[1]/div[1]/div/button").click()110senderPhone = driverChrome.find_element_by_xpath("//*[@id='resendReciver']").send_keys("0501234567")111driverChrome.find_element_by_xpath("//*[@id='resendReciver']").clear()112receiverPhone = driverChrome.find_element_by_xpath("//*[@id='resendReciver']").send_keys("0507654321")113time.sleep(2)114pressSavePhone = driverChrome.find_element_by_xpath("//*//*[@id='ember1273']/div[5]/button").click()115time.sleep(2)116#press payment117paymentSave = driverChrome.find_element_by_xpath("//*[@id='ember1817']/div[5]/button").click()118print("xxxx")119time.sleep(3)120driverChrome.close()121#END122#Test...
HomeScreen.js
Source:HomeScreen.js
1import * as React from 'react';2import { Text, View, TouchableOpacity, TextInput, StyleSheet } from 'react-native';3import { Header } from 'react-native-elements';4import db from '../localdb';5import * as Speech from 'expo-speech';6export default class HomeScreen extends React.Component {7 constructor() {8 super();9 this.state = {10 text: '',11 meaning: [],12 lexicography: [],13 pressSearch: false,14 loading: false,15 word: 'Receiving...'16 };17 }18 getWord = (text) => {19 var text = text.toLowerCase()20 try{21 var word = db[text]["word"]22 var lexicography = db[text]["lexicography"]23 var meaning = db[text]["meaning"]24 this.setState({25 "word" : word,26 "lexicography" : lexicography,27 "meaning" : meaning28 })29 }30 catch(err){31 alert("This word is unavailable")32 this.setState({33 'text':'',34 'pressSearch':false35 })36 }37 }38 speak = () => {39 Speech.speak(this.state.word)40 } 41 render() {42 return(43 <View style={styles.container}>44 <Header style= {styles.header} />45 <View style={styles.enterBox}>46 <TextInput style={styles.inputBox}47 onChangeText={text => {48 this.setState({49 text: text,50 pressSearch: false,51 word: "Receiving...",52 lexicography :'',53 examples : [],54 meaning : ""55 });56 }}57 value={this.state.text}58 />59 60 <TouchableOpacity style={styles.searchIcon}61 onPress={() => {62 this.setState({ pressSearch: true });63 this.getWord(this.state.text)64 }}>65 <Text style={styles.searchWord}>Search</Text>66 </TouchableOpacity>67 </View>68 <View style={styles.outputBox}>69 <Text style={styles.text}>70 {71 this.state.pressSearch && this.state.word === "Receiving..."72 ? this.state.word73 : ""74 }75 </Text>76 {77 this.state.word !== "Receiving..." ?78 (79 <View style={{justifyContent:'center', marginLeft: 13}}>80 <View style={styles.detailsBox}>81 <Text style={styles.detailsTitle}>82 Word :{" "}83 </Text>84 <Text style={{fontSize: 19, color: 'orange'}}>85 {this.state.word}86 </Text>87 </View>88 <View style={styles.detailsBox}>89 <Text style={styles.detailsTitle}>90 Type :{" "}91 </Text>92 <Text style={{fontSize: 18, fontStyle: 'bold'}}>93 {this.state.lexicography}94 </Text>95 </View>96 <View>97 <Text style={styles.detailsTitle}>98 Meaning:{" "}99 </Text>100 <Text style={{ fontSize:19}}>101 {this.state.meaning}102 </Text>103 <TouchableOpacity style={styles.speechButton}104 onPress = {105 this.speak106 }>107 <Text>108 {this.state.word}109 </Text>110 </TouchableOpacity>111 </View>112 </View>113 )114 :null115 }116 </View>117 </View>118 );119 }120}121const styles = StyleSheet.create({122 container: {123 flex: 1,124 backgroundColor: 'white'125 },126 header: {127 fontSize: 22,128 backgroundColor: 'purple'129 },130 enterBox: {131 flex: 0.25,132 alignItems: 'center',133 justifyContent: 'center'134 },135 inputBox: {136 width: '70%',137 alignSelf: 'center',138 height: 40,139 textAlign: 'center',140 borderWidth: 3,141 },142 searchIcon: {143 width: '50%',144 height: 40,145 justifyContent: 'center',146 alignItems: 'center',147 margin: 10,148 borderWidth: 3,149 borderRadius: 11,150 },151 searchWord: {152 fontSize: 20,153 fontWeight: 'bold'154 },155 156 outputBox: {157 flex: 0.7,158 alignItems:'center'159 },160 161 detailsBox: {162 flexDirection: 'row',163 alignItems: 'center'164 },165 166 detailsTitle: {167 color: 'orange',168 fontSize: 18,169 },170 171 speechButton: {172 width: '40%',173 height: 20,174 justifyContent: 'center',175 alignItems: 'center',176 margin: 10,177 borderWidth: 3,178 borderRadius: 11,179 }...
LinkedinJob.py
Source:LinkedinJob.py
1from selenium import webdriver2from selenium.webdriver.common.keys import Keys3import time4class LinkedinPostings:5 jobSearch_xpath = '/html[1]/body[1]/header[1]/nav[1]/section[1]/section[2]/form[1]/section[1]/input[1]'6 jobLocation = 'location'7 pressSearch = 'base-search-bar__submit-btn'8 jobs_css = 'li[class *= \'result-card\']'9 jobTitle_css = 'h2[class *= \'topcard__title\']'10 jobCompany_css = 'a[class *= \'topcard__org-name-link topcard__flavor--black-link\']'11 12 13 14 def __init__(self, driver):15 self.driver = driver16 17 def maxScreen(self):18 self.driver.maximize_window()19 def searchJobs(self, jobInput):20 self.driver.find_element_by_xpath(self.jobSearch_xpath).send_keys(jobInput)21 # self.driver.find_element_by_xpath(self.jobSearch_xpath).send_keys(Keys.ENTER)22 def inputLocation(self, location):23 self.driver.find_element_by_name(self.jobLocation).clear()24 self.driver.find_element_by_name(self.jobLocation).send_keys(location)25 self.driver.find_element_by_name(self.jobLocation).send_keys(Keys.ENTER)26 return self.driver.find_element_by_name(self.jobLocation).get_attribute("value")27 # def continueToListing(self):28 # button = self.driver.find_element_by_class_name(self.pressSearch)29 def getJobs(self):30 return self.driver.find_elements_by_css_selector(self.jobs_css)31 def getJobTitle(self):32 return self.driver.find_element_by_css_selector(self.jobTitle_css).text33 def getJobCompany(self):34 return self.driver.find_element_by_css_selector(self.jobCompany_css).text35 def loopJobs(self, jobs):36 jobs_Details = []37 38 for job in jobs:39 job.click()40 #replace time with selenium timer/await method41 time.sleep(1)42 title = self.getJobTitle()43 company = self.getJobCompany()44 # company = self.getJobCompany()45 # jobs_Details.append(title)...
setFormSearchProperty.test.ts
Source:setFormSearchProperty.test.ts
...16});17describe('submit', ()=>{18 it('Pressed', async ()=>{19 const page = await openMockBrowserPage();20 await pressSearch(page);21 page.browser().disconnect();22 expect(page);23 }, browserTimeOut);...
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!!