Best Python code snippet using autotest_python
web_copy.py
Source:web_copy.py
1## Seleniumì íì©í ì¹íì´ì§ ììì excel ìì ì±ìë£ë ì¤í¬ë¦½í¸2## í
ì¤í¸ copy ë° select ë° ì íë§ì ì¬ì©íììµëë¤.3from time import sleep4from distutils.log import info5from tkinter.tix import Tree6from matplotlib.pyplot import getp7from numpy import empty8import selenium9from selenium import webdriver10from selenium.webdriver import ActionChains11from selenium.webdriver.support import expected_conditions as EC12from selenium.webdriver.support.ui import WebDriverWait as wait13from selenium.webdriver.support.ui import Select14from selenium.webdriver.common.keys import Keys15from selenium.webdriver.common.by import By16import pandas as pd17from datetime import datetime18from getpass import getpass19import tkinter as tk20from tkinter import filedialog21from tkinter import messagebox22import openpyxl23# ìì
ë°ì´í° ìë24def alrt(name,infomiss,data=0):25 #print(data.isna().sum())26 print(name+"ê³ ê°ëì "+infomiss+" ì ë³´ê° ë¹ì´ììµëë¤.")27 return "{infomiss}ì ë³´ê° ë¹ì´ììµëë¤.".format(infomiss=infomiss)28# ë°ì´í° ì²ë¦¬29def process(name,sheet_name):30 info_dic = dict()31 y = df.loc[ df [ 'ì±ëª
' ] == name ]32 try:33 birth = ''.join(y['ìë
ìì¼'])34 birth = datetime.strptime(birth,'%Y-%m-%d').date()35 today = datetime.now().date()36 year = today.year - birth.year37 if today.month < birth.month or (today.month == birth.month and today.day < birth.day):38 year-=139 info_dic=dict({40 'ì¥ê¸°ì¤ê¸°' : 'â ì¥ê¸°' if 'ì¥ê¸°' in sheet_name else 'â ì¤ê¸°',41 'Nì°¨' : sheet_name.split('-')[1][0:1],42 'ì±ëª
' : ''.join(y['ì±ëª
']),43 'ìë
ìì¼' : ''.join(y['ìë
ìì¼']) if y['ìë
ìì¼'].isna().sum()==0 else alrt(name,'ìë
ìì¼'),44 'ì±ë³' : ''.join(y['ì±ë³']) if y['ì±ë³'].isna().sum()==0 else alrt(name,'ì±ë³'),45 'ìì' : ''.join(y['ìì']) if y['ìì'].isna().sum()==0 else alrt(name,'ìì'),46 'ëì´' : year,47 'ì°ë½ì²' : ''.join(y['ì°ë½ì²']) if y['ì°ë½ì²'].isna().sum()==0 else alrt(name,'ì íë²í¸'),48 'ì´ë©ì¼' : ''.join(y['E-mail 주ì']) if y['E-mail 주ì'].isna().sum()==0 else alrt(name,'ì´ë©ì¼'),49 '기본주ì' : ''.join(y['기본주ì']) if y['기본주ì'].isna().sum()==0 else alrt(name,'기본주ì'),50 'êµ°' : ''.join(y['êµ°']) if y['êµ°'].isna().sum()==0 else alrt(name,'êµ°'),51 'ê³ê¸' : ''.join(y['ê³ê¸']) if y['ê³ê¸'].isna().sum()==0 else alrt(name,'ê³ê¸'),52 'ë³ê³¼' : ''.join(y['ë³ê³¼']) if y['ë³ê³¼'].isna().sum()==0 else alrt(name,'ë³ê³¼'),53 'êµ°ë²' : ''.join(y['êµ°ë²']) if y['êµ°ë²'].isna().sum()==0 else alrt(name,'êµ°ë²'),54 'ì ììì ì¼' : ''.join(y['ì ì(ìì )ì¼']) if y['ì ì(ìì )ì¼'].isna().sum()==0 else alrt(name,'ì ììì ì¼'),55 '복무기ê°_ë
' : ''.join(y['복무기ê°']).split(" ")[0].replace("ë
",'') if y['복무기ê°'].isna().sum()==0 else alrt(name,'복무기ê°_ë
'),56 '복무기ê°_ì' : ''.join(y['복무기ê°']).split(" ")[1].replace("ê°ì",'') if y['복무기ê°'].isna().sum()==0 else alrt(name,'복무기ê°_ì'),57 'ê¶ì_ìë±í¬' : 'â' if 'ìë±í¬' == ''.join(y['ì¼í°']) else '',58 'ê¶ì_ìì¸ì²' : 'â' if 'ìì¸' == ''.join(y['ì¼í°']) else '',59 'ê¶ì_ìì' : 'â' if 'ìì' == ''.join(y['ì¼í°']) else '',60 'ê¶ì_í주' : 'â' if 'í주' == ''.join(y['ì¼í°']) else '',61 'ëìí¨' : 'â',62 'ìì ì' : ''.join(y['ì±ëª
']) + " ì ìë",63 'ì°í¸ë²í¸' : '00000'64 })65 66 except Exception as e:67 print("\n"+name+"ê³ ê°ëì ìì
ì ë³´íëì ì¤í¨íììµëë¤ ìë¬ì½ë {e}".format(e=e))68 69 return info_dic70messagebox.showinfo("ì¬ì©ë²", "ìì
ì ì ííì¬ ì£¼ì¸ì!")71file_path_ex = filedialog.askopenfilename(filetypes=[("Excel files", "*.xlsx")])72wb = openpyxl.load_workbook(file_path_ex)73ws = wb.active74sheet_name = str(ws.title)75id = str(input('ìì´ë를 ì
ë ¥íì¸ì : '))76pwd = getpass('ë¹ë°ë²í¸ë¥¼ ì
ë ¥íì¸ì : ')77service_start = str(input('ìë¹ì¤ ììì¼ì : '))78service_end = str(input('ìë¹ì¤ ì¢
ë£ì¼ì : '))79service_add = str(input('ìë¹ì¤ ë±ë¡ì¼ì : '))80while True:81 #1. ìì
íì¼ ì´ê¸°82 df = pd.read_excel(r'{}'.format(file_path_ex), sheet_name=sheet_name,header=2)83 if 'ì¥ê¸°' in sheet_name:84 print("\n----ì¥ê¸°ê³ ê°ì
ëë¤----")85 elif 'ì¤ê¸°' in sheet_name:86 print("\n----ì¤ê¸°ê³ ê°ì
ëë¤----")87 print("\n----ìì
íì¼ì ìë ì´ë¦ë¤ì
ëë¤----")88 print(df['ì±ëª
'])89 print("----------------------------------\n")90 while True:91 name = str(input('ì²ë¦¬íê³ ì íë ì¬ëì ì´ë¦ì ì
ë ¥íì¸ì : '))92 if df['ì±ëª
'].str.contains(name).any() :93 break94 else:95 print("ì´ë¦ì ë¤ì ì
ë ¥íì¸ì ì못ì
ë ¥íê±°ë excel íì¼ì í´ë¹ ì´ë¦ì´ ììµëë¤.")96 #2. ì¬ì´í¸ ì ì97 URL = 'https://cloud.sscrm.co.kr/Login.aspx'98 options = webdriver.ChromeOptions()99 options.add_experimental_option("excludeSwitches", ["enable-logging"])100 driver = webdriver.Chrome(executable_path='chromedriver',options=options)101 driver.get(url=URL)102 tabs = driver.window_handles103 print(tabs)104 #3. ë¡ê·¸ì¸ìì
105 driver.find_element_by_xpath('//*[@id="txtLoginID"]').send_keys('{id}'.format(id=id))106 driver.find_element_by_xpath('//*[@id="txtPassword"]').send_keys('{pwd}'.format(pwd=pwd))107 try:108 driver.find_element_by_xpath('//*[@id="btnLogin"]').click()109 except Exception as e:110 driver.find_element_by_xpath('//*[@id="Notice"]/div/div[3]/span[2]/input').click()111 driver.find_element_by_xpath('//*[@id="btnLogin"]').click()112 113 #4. ê³ ê° ì ë³´ ì
ë ¥ ì´ë114 driver.get(url="https://cloud.sscrm.co.kr/Pages__C002/CS/CSCI_List.aspx")115 driver.find_element_by_xpath('//*[@id="ucLeft_listCS12"]/a').click()116 #5. ê³ ê° ì ë³´ ì
ë ¥ 117 get_info_dict = process(name,sheet_name)118 if get_info_dict is not empty:119 driver.find_element_by_xpath("//*[@id='divRight']/div/table[2]/tbody/tr[1]/td[2]/img[1]").click()120 driver.switch_to.window(driver.window_handles[1])121 driver.find_element_by_xpath('/html/body/form/div[3]/table/tbody/tr/td/div/table[2]/tbody/tr/td[2]/input').send_keys("ì ìì¥ë³")122 driver.find_element_by_xpath('//*[@id="ContentPage_btnSearch"]').click()123 if 'ì¥ê¸°' in sheet_name:124 driver.find_element_by_xpath("//*[@id='ContentPage_gvList_btnClientNm_1']").click()125 else :126 driver.find_element_by_xpath("//*[@id='ContentPage_gvList_btnClientNm_0']").click()127 driver.switch_to.window(driver.window_handles[0])128 driver.find_element_by_xpath("//select[@name='ctl00$ContentPage$FLD_CTCCODE']/option[text()='í주ì§ì¬']").click() # CTC129 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_CUSTNM"]').send_keys(get_info_dict['ì±ëª
']) # ê³ ê°ëª
130 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_EMAIL"]').send_keys(get_info_dict['ì´ë©ì¼']) # ì´ë©ì¼131 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_MOBILE"]').send_keys(get_info_dict['ì°ë½ì²']) # í´ëí°132 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_BIRTHDAY"]').send_keys(get_info_dict['ìë
ìì¼']) # ìë
ìì¼133 driver.find_element_by_xpath("//select[@name='ctl00$ContentPage$FLD_SEX']/option[text()='{sex}']".format(sex=get_info_dict['ì±ë³'])).click() # ì±ë³134 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_WORKCOMPANYNAME"]').send_keys(get_info_dict['êµ°'])135 driver.find_element_by_xpath("//select[@name='ctl00$ContentPage$FLD_CAREERGOALCODE']/option[text()='ì·¨ì
']").click() # ê²½ë ¥ëª©í136 driver.find_element_by_xpath("//select[@name='ctl00$ContentPage$FLD_PROCESSSTATUSCODE']/option[text()='ì§íì¤']").click() # ì§íìí©137 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_SERVICEBEGINDATE"]').clear() # ìë¹ì¤ ììì¼ì ì´ê¸°í138 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_SERVICEENDDATE"]').clear() # ìë¹ì¤ ì¢
ë£ì¼ì ì´ê¸°í139 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_SERVICEREGDATE"]').clear() # ìë¹ì¤ ë±ë¡ì¼ì ì´ê¸°í140 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_SERVICEBEGINDATE"]').send_keys(service_start) # ìë¹ì¤ ììì¼ì141 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_SERVICEENDDATE"]').send_keys(service_end) # ìë¹ì¤ ì¢
ë£ì¼ì142 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_SERVICEREGDATE"]').send_keys(service_add) # ìë¹ì¤ ë±ë¡ì¼ì143 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_ADDRESS1"]').send_keys('{addr}'.format(addr=get_info_dict['기본주ì'])) # 주ì144 if get_info_dict['êµ°'] =='í´ë³ë':145 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_WORKRANK"]').send_keys('{army} {rank}'.format(army=get_info_dict['êµ°'][:2],rank=get_info_dict['ê³ê¸'])) # ì§ê¸ê³ê¸146 else :147 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_WORKRANK"]').send_keys('{army} {rank}'.format(army=get_info_dict['êµ°'][:1],rank=get_info_dict['ê³ê¸'])) # ì§ê¸ê³ê¸148 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_WORKRETIREDATE"]').send_keys('{}'.format(get_info_dict['ì ììì ì¼'])) # í´ìì¼ 149 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_ARMYWORKTYPE"]').send_keys('{armytype}'.format(armytype=get_info_dict['ë³ê³¼'])) # ë³ê³¼150 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_WORKDEPARTMENT"]').send_keys('{armytype}'.format(armytype=get_info_dict['ìì'])) # ë¶ì151 driver.find_element_by_xpath('//*[@id="ContentPage_FLD_WORKYEAR"]').send_keys('{}ë
'.format(get_info_dict['복무기ê°_ë
'])) # ê·¼ë¬´ê¸°ê° ë
152 if get_info_dict['복무기ê°_ì']!='0':153 driver.find_element_by_xpath("//select[@name='ctl00$ContentPage$FLD_WORKMONTH']/option[text()='{WORKMONTH}']".format(WORKMONTH=get_info_dict['복무기ê°_ì'])).click() # ê·¼ë¬´ê¸°ê° ì154 driver.find_element_by_xpath("//select[@name='ctl00$ContentPage$FLD_USEYN']/option[text()='ì¬ì©ê°ë¥']").click() # 커리ì´íë¬ì¤ì¬ì©ì¬ë¶155 else :156 messagebox.showinfo("ì¬ì©ë²", "ìì
ë°ì´í°ë¥¼ íì¸í´ì£¼ì¸ì")157 driver.close()158 if input("ì¢
ë£íìê² ìµëê¹? (Y/N) : ") == 'Y':...
dijkstras_testing.py
Source:dijkstras_testing.py
...33 if not edge_weight:34 edge_weight = edge_weights.get((node2,node1))35 return edge_weight36# Sets attributes for nodes, including names37def get_info_dict(node):38 info_dict = {0: {'name': 'Hassyampa'},39 1: {'name': 'Subway'},40 2: {'name': 'R1'},41 3: {'name': 'Adelphi Commons'},42 4: {'name': 'Starbucks'},43 5: {'name': 'R2'},44 6: {'name': 'Vista Del Sol'},45 7: {'name': 'Papa Johns'},46 8: {'name': 'R6'},47 9: {'name': 'R3'},48 10: {'name': 'Barrett'},49 11: {'name': 'R7'},50 12: {'name': 'R5'},51 13: {'name': 'McDonalds'},52 14: {'name': 'R4'},53 15: {'name': 'Taco Bell'},54 16: {'name': 'Tooker House'},55 17: {'name': 'Sonora'}, 56 } 57 return info_dict[node]58#code for heuristic attribute if required 59def get_heuristic(node_x, node_y):60 pass61# Code from networkx that creates the graph62G = nx.Graph()63G.add_nodes_from([(0, get_info_dict(0)), 64 (1, get_info_dict(1)), 65 (2, get_info_dict(2)), 66 (3, get_info_dict(3)),67 (4, get_info_dict(4)),68 (5, get_info_dict(5)),69 (6, get_info_dict(6)),70 (7, get_info_dict(7)),71 (8, get_info_dict(8)),72 (9, get_info_dict(9)),73 (10, get_info_dict(10)),74 (11, get_info_dict(11)),75 (12, get_info_dict(12)),76 (13, get_info_dict(13)),77 (14, get_info_dict(14)),78 (15, get_info_dict(15)),79 (16, get_info_dict(16)),80 (17, get_info_dict(17)),81 ])82e = [(0, 1, get_dist_metric(0,1)), 83 (0, 2, get_dist_metric(0,2)), 84 (0, 5, get_dist_metric(0,5)), 85 (2, 3, get_dist_metric(2,3)), 86 (2, 4, get_dist_metric(2,4)), 87 (2,6, get_dist_metric(2,6)), 88 (1,2, get_dist_metric(1,2)), 89 (4,6,get_dist_metric(4,6)), 90 (1,9,get_dist_metric(1,9)), 91 (3,17,get_dist_metric(3,17)), 92 (5,8,get_dist_metric(5,8)), 93 (5,10,get_dist_metric(5,10)), 94 (5,7,get_dist_metric(5,7)), ...
query.py
Source:query.py
2import numpy as np3from scipy.stats import norm4from active_reward_learning.util.helpers import get_array_from_scalar5from active_reward_learning.util.video import save_video6def get_info_dict(info):7 return tuple(info)8class QueryBase:9 def __init__(self):10 self.info = None11 def _asdict(self):12 raise NotImplementedError()13class LinearQuery(QueryBase):14 def __init__(self, gp_repr_list, linear_combination, reward, info):15 self.gp_repr_list = get_array_from_scalar(gp_repr_list)16 self.linear_combination = get_array_from_scalar(linear_combination)17 self.reward_ = reward18 self.info = info19 @property20 def reward(self):21 return self.reward_22 def __hash__(self):23 l = (24 tuple(25 [26 gp_repr.tostring()27 if isinstance(gp_repr, np.ndarray)28 else str(gp_repr)29 for gp_repr in self.gp_repr_list30 ]31 ),32 tuple(33 [34 a.tostring() if isinstance(a, np.ndarray) else str(a)35 for a in self.linear_combination36 ]37 ),38 self.reward,39 get_info_dict(self.info),40 )41 return hash(l)42 def _asdict(self):43 return {44 "gp_repr_list": [list(gp_repr) for gp_repr in self.gp_repr_list],45 "reward": float(self.reward),46 "info": get_info_dict(self.info),47 }48 def __eq__(self, other):49 return self.__hash__() == hash(other)50 def to_file(self, path, filename="query.txt"):51 file_path = os.path.join(path, filename)52 s = (53 str(self.gp_repr_list)54 + "\n\n"55 + str(self.linear_combination)56 + "n\n"57 + str(self.reward_)58 )59 with open(file_path, "w"):60 print(s)61 return file_path62class PointQuery(LinearQuery):63 def __init__(self, gp_repr, reward, info):64 self.gp_repr = get_array_from_scalar(gp_repr)65 super().__init__([gp_repr], [1], reward, info)66 def __hash__(self):67 l = (68 self.gp_repr.tostring(),69 self.reward,70 get_info_dict(self.info),71 )72 return hash(l)73 def _asdict(self):74 return {75 "gp_repr": self.gp_repr.tolist(),76 "reward": float(self.reward),77 "info": get_info_dict(self.info),78 }79 def __eq__(self, other):80 return self.__hash__() == hash(other)81class TrajectoryQuery(LinearQuery):82 def __init__(self, gp_repr_list, reward_list, info, rgb_arrays=None):83 reward = sum(reward_list)84 self.reward_list = reward_list85 self.rgb_arrays = rgb_arrays86 super().__init__(gp_repr_list, [1] * len(gp_repr_list), reward, info)87 def to_file(self, path, filename="query.gif"):88 if self.rgb_arrays is None:89 filename += ".txt"90 return super().to_file(path, filename=filename)91 else:92 file_path = os.path.join(path, filename)93 save_video(self.rgb_arrays, file_path, fps=5)94 return file_path95class ComparisonQueryLinear(LinearQuery):96 def __init__(97 self, gp_repr1, gp_repr2, reward1, reward2, info, response="bernoulli", **kwargs98 ):99 gp_repr_list = [gp_repr1, gp_repr2]100 linear_combination = [1, -1]101 super().__init__(gp_repr_list, linear_combination, 0, info)102 self.gp_repr1 = gp_repr_list[0]103 self.gp_repr2 = gp_repr_list[1]104 self.reward1 = reward1105 self.reward2 = reward2106 self.response = response107 if response == "difference":108 self.p = None109 elif response == "bernoulli":110 assert 0 <= reward1 <= 1, reward1111 assert 0 <= reward2 <= 1, reward2112 self.p = (1 + reward1 - reward2) / 2113 elif response == "deterministic":114 self.p = 1 if reward1 > reward2 else 0115 elif response == "probit":116 if "sigma" in kwargs:117 self.sigma = kwargs["sigma"]118 else:119 self.sigma = 1120 self.p = norm.cdf((reward1 - reward2) / (np.sqrt(2) * self.sigma))121 @property122 def reward(self):123 if self.p is None:124 return self.reward1 - self.reward2125 else:126 return np.random.choice([-1, 1], p=[1 - self.p, self.p])127 def __hash__(self):128 l = (129 self.gp_repr1.tostring(),130 self.gp_repr2.tostring(),131 self.reward1,132 self.reward2,133 get_info_dict(self.info),134 self.response,135 )136 return hash(l)137class StateQuery(PointQuery):138 def __init__(self, state, gp_repr, reward, info, obs=None):139 info["state"] = state140 info["obs"] = obs141 super().__init__(gp_repr, reward, info)142class StateComparisonQueryLinear(ComparisonQueryLinear):143 def __init__(144 self, gp_repr1, gp_repr2, reward1, reward2, info, response="bernoulli"145 ):...
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!!