def keypair(self,cloud_controller_name):
Cloud_DebugLog.stepinfo(Messages.LOGIN_CLOUD) #"Login cloud"
Cloud_client_browser = self.driver
# :???????? Login and pass in with username, password, server and port
self.admin_cloud_login(username='admin')
time.sleep(TestSpeedControl.TEST_STEP_INTERVAL)
Cloud_DebugLog.stepinfo(Messages.CLICK_SET)
Cloud_DebugLog.debug_print(Messages.CLICK_SET)
Cloud_browser_main_map = Main_Browser_UIMap(Cloud_client_browser)
openstatus=Cloud_client_browser.find_element_by_xpath("//span[text()='??']/../..").get_attribute("class")
if openstatus=='open':
pass
else:
safe_menu_btn=Cloud_browser_main_map.get_menu('security/')
safe_menu_btn.click()
safe_map=Safe_UIMap(Cloud_client_browser)
safe_map.getelement("//span[text()='???']").click()
time.sleep(1)
safe_map.getelement("//*[@id='create_keypair']").click()
time.sleep(1)
keypairname='gyp'+"".join(random.sample('1234567890zyxwvutsrqponmlkjihgfedcba',5))
safe_map.getelement("//*[@id='modal_style']/div/div[2]/div/div/div[1]/input").send_keys(keypairname)
safe_map.get_select(cloud_controller_name,name='cloud_controller_id')
safe_map.getelement(id='id_button_submit').click()
time.sleep(5)
#safe_map.getelement("//*[@id='product-page']/div/h3").send_keys(Keys.ENTER)
h3=safe_map.getelement("//*[@id='product-page']/div/h3").text
a="???\""+keypairname+"\"??????????????????"
assert h3==a
python类ENTER的实例源码
def _execute_script(email, password, count):
print("\nLoading..\nCheck out today's xkcd comic till then : %s \n\n" %(_xkcd()))
driver = webdriver.PhantomJS()
driver.get('https://www.facebook.com')
email_ID = driver.find_element_by_id('email')
pass_ID = driver.find_element_by_id('pass')
email_ID.send_keys(email)
pass_ID.send_keys(password)
pass_ID.send_keys(Keys.ENTER)
sleep(5)
for i in range(0,count):
driver.execute_script("window.scrollBy(0, document.body.scrollHeight);")
sleep(1)
sleep(5)
driver_tags = driver.execute_script('return document.getElementsByClassName("scaledImageFitWidth img")')
driver_img_list = {
'src' : [x.get_attribute('src') for x in driver_tags],
'alt' : [x.get_attribute('alt') for x in driver_tags],
}
driver.quit()
return driver_img_list
def test_castalio(self):
driver = self.driver
driver.get("http://castalio.info/")
driver.find_element_by_id("tipue_search_input").send_keys("6 anos")
driver.find_element_by_id("tipue_search_input").send_keys(Keys.ENTER)
driver.find_element_by_link_text(u"Episódio 88: Episódio Especial de 6 Anos").click()
self.assertEqual(u"Episódio 88: Episódio Especial de 6 Anos - Castálio Podcast", driver.title)
test_list_item_validation.py 文件源码
项目:superlists.ir
作者: aaghamohammadi
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def test_cannot_add_empty_list_items(self):
# Edith goes to the home page and accidentally tries to submit
# an empty list item. She hits Enter on the empty input box
self.browser.get(self.live_server_url)
self.get_item_input_box().send_keys(Keys.ENTER)
# The browser intercepts the request, and does not load the
# list page
self.wait_for(lambda: self.browser.find_elements_by_css_selector('#id_text:invalid'))
# She starts typing some text for the new item and the error disappears
self.get_item_input_box().send_keys('Buy milk')
self.wait_for(lambda: self.browser.find_elements_by_css_selector('#id_text:valid'))
# And she can submit it successfully
self.get_item_input_box().send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('1: Buy milk')
# Perversely, she now decides to submit a second blank list item
self.get_item_input_box().send_keys(Keys.ENTER)
# Again, the browser will not comply
self.wait_for_row_in_list_table('1: Buy milk')
self.wait_for(lambda: self.browser.find_elements_by_css_selector('#id_text:invalid'))
# And she can correct it by filling some text in
self.get_item_input_box().send_keys('Make tea')
self.wait_for(lambda: self.browser.find_elements_by_css_selector('#id_text:valid'))
self.get_item_input_box().send_keys(Keys.ENTER)
self.wait_for_row_in_list_table('1: Buy milk')
self.wait_for_row_in_list_table('2: Make tea')
def test(name,chat):
print ('ok here')
#elem = weixin_main.driver.find_element_by_name("editor")
#elem = weixin_main.driver.find_element_by_class_name("web_wechat_search")
friend_name = weixin_main.driver.find_element_by_tag_name("input")
#elem.click()
friend_name.send_keys(name)
time.sleep(3)
friend_name.send_keys(Keys.ENTER)
chat_content = weixin_main.driver.find_element_by_id("editArea")
time.sleep(1)
chat_content.send_keys(chat)
#elem.send_keys(Keys.ENTER)
print ('ok here1')
def test(name,chat):
print ('ok here')
#elem = weixin_main.driver.find_element_by_name("editor")
#elem = weixin_main.driver.find_element_by_class_name("web_wechat_search")
friend_name = weixin_main.driver.find_element_by_tag_name("input")
#elem.click()
friend_name.send_keys(name)
time.sleep(3)
friend_name.send_keys(Keys.ENTER)
chat_content = weixin_main.driver.find_element_by_id("editArea")
time.sleep(1)
chat_content.send_keys(chat)
#elem.send_keys(Keys.ENTER)
print ('ok here1')
def test(name,chat):
print ('hello011')
#????
timedelta=datetime.timedelta(minutes=5)
#?????
now = str(datetime.datetime.now())[:-7]
next=now
#???????????,?????????????
while True:
print ('hello012')
now = str(datetime.datetime.now())[:-7]
if now==next:
#print (sched_time)
next=str(datetime.datetime.now()+timedelta)[:-7]
#print (sched_time)
print ('??????????')
chat=???????.main()
print ('abc is ',chat)
#elem = weixin_main.driver.find_element_by_name("editor")
#elem = weixin_main.driver.find_element_by_class_name("web_wechat_search")
friend_name = weixin_main.driver.find_element_by_tag_name("input")
#elem.click()
friend_name.send_keys(name)
time.sleep(3)
friend_name.send_keys(Keys.ENTER)
chat_content = weixin_main.driver.find_element_by_id("editArea")
time.sleep(1)
chat_content.send_keys(chat)
time.sleep(2)
time.sleep(1)
#chat_content.send_keys(Keys.ENTER)
#elem.send_keys(Keys.ENTER)
print ('ok here1')
print ('ok here')
def search(self, phrase):
"""
Enter a search phrase and display the results
"""
selector = 'input.gsc-input'
self.wait_for_element_visibility(selector, 'Search input available')
self.q(css=selector).fill(phrase + Keys.ENTER)
self.wait_for_element_visibility('.gsc-results', 'Search results shown')
def should_see_link_to(driver: webdriver, section: str, item_name: str):
item_selector = SECTIONS[section.lower()][item_name.lower()]
if section.lower() in ["export readiness", "guidance", "services"]:
logging.debug("Open the menu by sending 'Right Arrow' key")
menu_selector = SECTIONS[section.lower()]["menu"]
menu = find_element(driver, by_css=menu_selector)
menu.send_keys(Keys.ENTER)
menu_item = find_element(driver, by_css=item_selector)
wait_for_visibility(driver, by_css=item_selector)
with assertion_msg(
"It looks like '%s' in '%s' section is not visible", item_name,
section):
assert menu_item.is_displayed()
def start_requests(self):
def _search(driver):
driver.find_element_by_id('key').send_keys(u"?????", Keys.ENTER)
gevent.sleep(3)
self._jump_guide(driver)
gevent.sleep(3)
yield Request(url='https://www.jd.com/',
meta={"cookiejar": "jd"},
callback=self.parse_list,
dynamic=True,
browser_actions=[_search]
)
def find_write(driver, elem_path, write_str, clear_first=True, send_enter=False,
by=CSS, timeout=TIMEOUT, poll_frequency=0.5):
""" Find a writable element and write to it
find_write locates a writable element on the page, waiting
for up to timeout seconds. Once found, it writes the string
to it.
Args:
driver (selenium webdriver or element): A driver or element
elem_path (str): String used to located the element
write_str (str): String to write
clear_first (bool): Clear the contents before writing (default True)
send_enter (bool): Send a keyboard ENTER after writing string
by (selenium By): Selenium By reference
timeout (int): Selenium Wait timeout, in seconds
poll_frequency (float): Selenium Wait polling frequency, in seconds
Returns:
element: Selenium element
Raises:
TimeoutException: Raised when target element isn't located
"""
elem = find_element(driver, elem_path=elem_path, by=by, timeout=timeout,
poll_frequency=poll_frequency)
if clear_first:
elem.clear()
elem.send_keys(write_str)
if send_enter:
elem.send_keys(Keys.ENTER)
return elem
def test_can_enter_donation_form_and_execute_donation(self):
# Donor has heard about the opportunity to donate to the organization and enters the website
self.browser.get(self.live_server_url)
self.fill_in_donation_fields_right()
self.fill_in_personal_fields_right()
self.fill_in_cc_fields("4111111111111111")
# Submit
submit = self.browser.find_element_by_name("subbtn")
submit.send_keys(Keys.ENTER)
self.wait_for(lambda: self.assertIn('Muito obrigado pela sua doação!', self.browser.page_source))
def test_donor_fills_wrong_credit_card_and_gets_error(self):
# Donor has heard about the opportunity to donate to the organization and enters the website
self.browser.get(self.live_server_url)
self.fill_in_donation_fields_right()
self.fill_in_personal_fields_right()
self.fill_in_cc_fields("4111111111111112")
# Submit
submit = self.browser.find_element_by_name("subbtn")
submit.send_keys(Keys.ENTER)
self.wait_for(lambda: self.assertIn('Erro nas informações de cartão de crédito enviadas.', self.browser.page_source))
def __init__(self):
'''change these variables to fit your needs'''
'''Go to twilio.com and create a free account'''
self.accountsid = '??????????' # accountsid for twilio account, required to receive texts
self.authtoken = '??????????' # authtoken for twilio account, required to receive texts
self.mycellphone = '??????????' # your cell phone number
self.twiliocell = '??????????' # twilio cellnumber that will be used to send texts to your actual phone
self.username = '??????????' # CUNYFIRST USERNAME
self.password = '??????????' # CUNYFIRST PASSWORD
'''In order to receive an email you must go myaccount.google.com/security and scroll all the way to he bottom.
Then go to where it says 'Allow less secure apps: ON' and check OFF. You should get an email about the change '''
self.gmailuser = '??????????' # GMAIL USER
self.gmailpass = '??????????' # GMAIL PASSWORD
self.recipient = '??????????' # Recipient email address (most likely your email)
self.interval = 60 # refresh interval in seconds
'''Add shopping cart link is very important to this script. Go to CUNYFIRST, Click Enroll. Then choose your Term.
Once you are are on the Shopping Cart Page, Right + Click on 'add' and Click on 'Copy Link Location'.
Then copy and paste in here with single quotes. It should look like the link below'''
self.addshoppingcartlink = 'https://hrsa.cunyfirst.cuny.edu/psc/cnyhcprd/EMPLOYEE/HRMS/c/SA_LEARNER_SERVICES.SSR_SSENRL_CART.GBL?Page=SSR_SSENRL_CART&Action=A&ACAD_CAREER=UGRD&EMPLID=12345678&ENRL_REQUEST_ID=&INSTITUTION=BKL01&STRM=1172'
print("Starting Firefox and heading to CUNYFIRST")
self.driver = webdriver.PhantomJS()
self.driver.get('https://home.cunyfirst.cuny.edu')
login = WebDriverWait(self.driver, timeout=30).until(
EC.presence_of_element_located((By.NAME, "login")))
login.send_keys(self.username)
passs = self.driver.find_element_by_name("password")
passs.send_keys(self.password, Keys.ENTER)
studentcenter = WebDriverWait(self.driver, timeout=30).until(
EC.presence_of_element_located((By.LINK_TEXT, "Student Center")))
studentcenter.click()
self.driver.get(self.addshoppingcartlink)
shoppingcartlen = len(self.driver.find_elements_by_xpath("//table[@id='SSR_REGFORM_VW$scroll$0']/tbody/tr")) - 2
self.shoppingcart = {}
for i in range(0, shoppingcartlen):
classname = self.driver.find_element_by_id("win0divP_CLASS_NAME$" + str(i)).text
print(classname)
status = self.driver.find_element_by_xpath(
"//div[@id='win0divDERIVED_REGFRM1_SSR_STATUS_LONG$" + str(i) + "']/div/img").get_attribute('alt')
self.shoppingcart[classname] = status
def _execute_script(email, password, count):
print("\nLoading..\nCheck out today's xkcd comic till then : %s \n\n" %(_xkcd()))
driver = webdriver.PhantomJS()
driver.get('https://www.facebook.com')
email_ID = driver.find_element_by_id('email')
pass_ID = driver.find_element_by_id('pass')
email_ID.send_keys(email)
pass_ID.send_keys(password)
pass_ID.send_keys(Keys.ENTER)
sleep(5)
for i in range(0,count):
driver.execute_script("window.scrollBy(0, document.body.scrollHeight);")
sleep(1)
sleep(5)
driver_tags = driver.execute_script('return document.getElementsByClassName("scaledImageFitWidth img")')
driver_img_list = {
'src' : [x.get_attribute('src') for x in driver_tags],
'alt' : [x.get_attribute('alt') for x in driver_tags],
}
driver.quit()
return driver_img_list
def login_to_lichess(username, password):
# login to Lichess
chrome.get('https://en.lichess.org/login')
login = chrome.find_element_by_id('username')
login.send_keys(username)
passwordField = chrome.find_element_by_id('password')
passwordField.send_keys(password)
passwordField.send_keys(Keys.ENTER)
def auth(self,uname,passd):
time.sleep(2)
username = self.driver.find_element_by_id('email')
password = self.driver.find_element_by_id('pass')
username.send_keys(uname)
password.send_keys(passd)
password.send_keys(Keys.ENTER)
def auth(self,uname,passd):
time.sleep(2)
username = self.driver.find_element_by_id('email')
password = self.driver.find_element_by_id('pass')
username.send_keys(uname)
password.send_keys(passd)
password.send_keys(Keys.ENTER)
def auth(self,uname,passd):
time.sleep(2)
username = self.driver.find_element_by_id('email')
password = self.driver.find_element_by_id('pass')
username.send_keys(uname)
password.send_keys(passd)
password.send_keys(Keys.ENTER)
def _slow_type(self,word,elem):
""" Mimics a human user typing """
typing_speed = 42 #50 #wpm
for letter in word:
elem.send_keys(letter)
time.sleep(random.random()*10.0/typing_speed)
elem.send_keys(Keys.ENTER)