本文整理汇总了Python中splinter.Browser.attach_file方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.attach_file方法的具体用法?Python Browser.attach_file怎么用?Python Browser.attach_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类splinter.Browser
的用法示例。
在下文中一共展示了Browser.attach_file方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: splinter
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import attach_file [as 别名]
def splinter(url):
browser = Browser()
# login 126 email websize
browser.visit(url)
time.sleep(1)
browser.find_by_id("text").fill(text)
browser.find_by_id("go").click()
time.sleep(1)
# print browser.find_by_id('download-png')
browser.find_by_id("download-png").click()
browser.attach_file("transparent shrinkToFit", "C:\\somefile.jpg")
time.sleep(1)
示例2: SplinterBrowserDriver
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import attach_file [as 别名]
#.........这里部分代码省略.........
@property
def page_source(self):
return self._browser.html
@property
def page_title(self):
return self._browser.title
def open_url(self, url):
self._browser.driver.get(url)
def quit(self):
return self._browser.quit()
def is_element_visible(self, element):
return element.visible
def get_element_text(self, element):
return element.text
def get_element_by_xpath(self, selector):
return self._browser.find_by_xpath(selector)
def get_element_by_css(self, selector):
return self._browser.find_by_css(selector)
def get_element_by_id(self, selector):
return self._browser.find_by_id(selector)
def get_element_by_tag(self, selector):
return self._browser.find_by_tag(selector)
@element_action
def type(self, element, text, slowly=False):
return element.type(text, slowly)
@element_action
def fill(self, element, text):
return element.fill(text)
@element_action
def clear(self, element):
self.fill(element, '')
@element_action
def click(self, element):
return element.click()
@element_action
def check(self, element):
return element.check()
@element_action
def uncheck(self, element):
return element.uncheck()
@element_action
def mouse_over(self, element):
return element.mouse_over()
@element_action
def mouse_out(self, element):
return element.mouse_out()
def reload(self):
return self._browser.reload()
def go_back(self):
return self._browser.back()
def go_forward(self):
return self._browser.forward()
def execute_script(self, script):
return self._browser.evaluate_script(script)
def get_iframe(self, iframe_id):
return self._browser.get_iframe(iframe_id)
def get_alert(self):
return self._browser.get_alert()
def attach_file(self, input_name, file_path):
return self._browser.attach_file(input_name, file_path)
def wait_pageload(self, timeout=30):
wait_interval = 0.05
elapsed = 0
while self.execute_script('document.readyState') != 'complete':
self.wait(wait_interval)
elapsed += wait_interval
if elapsed > timeout:
raise PageNotLoadedException
def click_and_wait(self, element, timeout=30):
self.click(element)
self.wait_pageload(timeout)
示例3: UserTestCase
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import attach_file [as 别名]
#.........这里部分代码省略.........
self.browser.find_by_name('password').fill('')
self.browser.find_by_xpath(
"//div[@id='body']/div/form/input").first.click()
text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
self.assertEqual(text, 'This field is required.')
def test_user_signin_bad_password(self):
signup(self, 'bob', '[email protected]', 'bob_secret')
self.browser.visit(self.live_server_url + '/accounts/signin/')
self.browser.find_by_name('identification').fill('bob')
self.browser.find_by_name('password').fill('alice_secret')
self.browser.find_by_xpath(
"//div[@id='body']/div/form/input").first.click()
text = self.browser.find_by_xpath("//ul[@class='errorlist']/li").first.text
self.assertEqual(text, 'Please enter a correct username or email and password. Note that both fields are case-sensitive.')
def test_user_logout(self):
signup(self, 'bob', '[email protected]', 'bob_secret')
signin(self, 'bob', 'bob_secret')
logout(self)
self.assertEqual(self.browser.title, 'SylvaDB - Signed out')
self.assertEqual(self.browser.find_by_css('.body-inside').first.value, 'You have been signed out. Till we meet again.')
def test_user_details(self):
signup(self, 'bob', '[email protected]', 'bob_secret')
signin(self, 'bob', 'bob_secret')
self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
self.browser.find_link_by_href('/accounts/bob/').first.click()
self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
self.browser.find_link_by_href('/accounts/bob/edit/').first.click()
self.assertEqual(self.browser.title, 'SylvaDB - Account setup')
self.browser.find_by_name('first_name').fill('Bob')
self.browser.find_by_name('last_name').fill('Doe')
self.browser.attach_file('mugshot', 'http://www.gravatar.com/avatar/3d4bcca5d9c3a56a0282f308f9acda07?s=90')
self.browser.select('language', 'en')
self.browser.select('gender', '1')
self.browser.find_by_name('website').fill('http://www.bobweb.com')
self.browser.find_by_name('location').fill('London, Ontario')
self.browser.find_by_name('birth_date').fill('01/01/1975')
self.browser.find_by_name('about_me').fill('I am a very nice guy')
self.browser.find_by_name('institution').fill('University')
self.browser.find_by_name('company').fill('CulturePlex')
self.browser.find_by_name('lab').fill('CulturePlex')
self.browser.find_by_value('Save changes').first.click()
self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
logout(self)
def test_user_details_bad_website(self):
signup(self, 'bob', '[email protected]', 'bob_secret')
signin(self, 'bob', 'bob_secret')
self.assertEqual(self.browser.title, 'SylvaDB - Dashboard')
self.browser.find_link_by_href('/accounts/bob/').first.click()
self.assertEqual(self.browser.title, 'SylvaDB - bob\'s profile.')
self.browser.find_link_by_href('/accounts/bob/edit/').first.click()
self.assertEqual(self.browser.title, 'SylvaDB - Account setup')
self.browser.find_by_name('first_name').fill('Bob')
self.browser.find_by_name('last_name').fill('Doe')
self.browser.attach_file('mugshot', 'http://www.gravatar.com/avatar/3d4bcca5d9c3a56a0282f308f9acda07?s=90')
self.browser.select('language', 'en')
self.browser.select('gender', '1')
self.browser.find_by_name('website').fill('bobweb')
self.browser.find_by_name('location').fill('London, Ontario')
self.browser.find_by_name('birth_date').fill('01/01/1975')
self.browser.find_by_name('about_me').fill('I am a very nice guy')
self.browser.find_by_name('institution').fill('University')
self.browser.find_by_name('company').fill('CulturePlex')
示例4: SchemaTestCase
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import attach_file [as 别名]
class SchemaTestCase(LiveServerTestCase):
"""
A set of tests for testing export schema, import schema and everything
related to advanced types (patterns, options, etc.).
"""
def setUp(self):
self.browser = Browser()
signup(self, 'bob', '[email protected]', 'bob_secret')
signin(self, 'bob', 'bob_secret')
def tearDown(self):
logout(self)
self.browser.quit()
def test_export_schema(self):
create_graph(self)
create_schema(self)
create_type(self)
self.browser.find_by_id('toolsMenu').first.click()
cookies = {self.browser.cookies.all()[0]["name"]: self.browser.cookies.all()[0]["value"], self.browser.cookies.all()[1]["name"]: self.browser.cookies.all()[1]["value"]}
result = requests.get(self.live_server_url + '/schemas/bobs-graph/export/', cookies=cookies)
self.assertEqual(result.headers['content-type'], 'application/json')
self.assertEqual(self.browser.status_code.is_success(), True)
f = open('sylva/base/tests/files/bobs-graph_schema.json')
self.assertEqual(f.read().split("\n")[0], result.content)
def test_import_schema(self):
create_graph(self)
create_schema(self)
self.browser.find_by_id('schemaImport').first.click()
file_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'files/bobs-graph_schema.json'
)
self.browser.attach_file('file', file_path)
self.browser.find_by_value('Continue').first.click()
self.assertEqual(self.browser.title, "SylvaDB - Bob's graph")
text = self.browser.find_by_id('diagramBoxField_bobs-graph.bobs-type.undefined').first.value
self.assertEqual(text, "Name")
def test_new_type(self):
create_graph(self)
create_schema(self)
self.browser.find_link_by_href(
'/schemas/bobs-graph/types/create/').first.click()
text = self.browser.find_by_xpath(
"//div[@class='content2-first']/h2").first.value
self.assertEqual(text, 'Type')
self.browser.find_by_name('name').first.fill("Bob's type")
self.browser.find_by_xpath(
"//div[@class='content2-first']/p/textarea[@name='description']").first.fill('The loved type')
self.browser.find_by_value('Save Type').first.click()
text = self.browser.find_by_xpath(
"//div[@id='diagramBox_bobs-type']/div[@class='title']").first.value
self.assertNotEqual(text.find("Bob's type"), -1)
def test_new_advanced_type(self):
create_graph(self)
create_schema(self)
self.browser.find_link_by_href(
'/schemas/bobs-graph/types/create/').first.click()
text = self.browser.find_by_xpath(
"//div[@class='content2-first']/h2").first.value
self.assertEqual(text, 'Type')
self.browser.find_by_name('name').first.fill("Bob's type")
self.browser.find_by_id('advancedModeButton').first.click()
self.browser.find_by_name('properties-0-key').first.fill('Name')
self.browser.find_by_name('properties-0-display').first.check()
self.browser.find_by_name('properties-0-required').first.check()
self.browser.find_by_name('properties-0-default').first.fill(
"Bob's node default name")
self.browser.find_by_name('properties-0-order').first.fill('1')
self.browser.find_by_name('properties-0-description').first.fill(
"The name of this Bob's node")
self.browser.find_by_value('Save Type').first.click()
text = self.browser.find_by_id(
'diagramBoxField_bobs-graph.bobs-type.undefined').first.value
self.assertEqual(text, "Name")
def test_new_advanced_type_string_empty(self):
create_graph(self)
create_schema(self)
self.browser.find_link_by_href(
'/schemas/bobs-graph/types/create/').first.click()
text = self.browser.find_by_xpath(
"//div[@class='content2-first']/h2").first.value
self.assertEqual(text, 'Type')
self.browser.find_by_name('name').first.fill("Bob's type")
self.browser.find_by_id('advancedModeButton').first.click()
self.browser.find_by_name('properties-0-key').first.fill('String name')
self.browser.find_by_name('properties-0-display').first.check()
self.browser.find_by_name('properties-0-required').first.check()
self.browser.find_by_xpath("//select[@id='id_properties-0-datatype']/optgroup[@label='Basic']/option[@value='s']").first.click()
self.browser.find_by_name('properties-0-order').first.fill('1')
self.browser.find_by_name('properties-0-description').first.fill(
"The name of this Bob's node")
self.browser.find_by_value('Save Type').first.click()
text = self.browser.find_by_id(
'diagramBoxField_bobs-graph.bobs-type.undefined').first.value
#.........这里部分代码省略.........
示例5: ToolsTestCaseCsv
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import attach_file [as 别名]
class ToolsTestCaseCsv(LiveServerTestCase):
"""
A master test to check the behaviour of the new 'auto' fields.
Actually only works with gephi format.
"""
def setUp(self):
self.browser = Browser()
socket.setdefaulttimeout(30)
signup(self, 'bob', '[email protected]', 'bob_secret')
signin(self, 'bob', 'bob_secret')
self.firstGraphName = "bobgraph"
self.secondGraphName = "alicegraph"
def tearDown(self):
logout(self)
self.browser.quit()
@classmethod
def tearDownClass(cls):
sleep(10) # It needs some time for close the LiverServerTestCase
super(ToolsTestCaseCsv, cls).tearDownClass()
def test_graph_export_csv(self):
# Create a graph with a auto_user property
create_graph(self, self.firstGraphName)
create_advanced_schema(self, self.firstGraphName)
create_advanced_type(self, self.firstGraphName, "e")
create_advanced_data(self)
# Create new graph for import the data
import_advanced_schema_csv(self, self.firstGraphName, self.secondGraphName)
# Data import
self.browser.find_by_id('toolsMenu').first.click()
self.browser.find_link_by_href('/tools/' + self.secondGraphName + '/import/').first.click()
self.browser.find_by_id('csv-radio').first.click()
# Change the display field of input to attach the file
script = """
$('#files').css('display', '');
"""
self.browser.execute_script(script)
self.browser.is_text_present('Drop your nodes files here', wait_time=10)
# Import the nodes
file_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'files/csv/bobs-type.csv'
)
self.browser.attach_file('file', file_path)
self.browser.is_text_present('Nodes files loaded. Loading edges files...', wait_time=10)
# Wait until the data is imported
self.browser.is_text_present('Now drop your edges files', wait_time=10)
# Change the display field of input to attach the file
script = """
$('#files2').css('display', '');
"""
self.browser.execute_script(script)
# Import the relationships
file_path = os.path.join(
os.path.abspath(os.path.dirname(__file__)),
'files/csv/bobs-rels.csv'
)
self.browser.attach_file('file2', file_path)
self.browser.is_text_present('Data loaded. Uploading to the server...', wait_time=10)
# Wait until the data is imported
self.browser.is_text_present('Data uploaded.', wait_time=10)
# Check that nodes and relationships are ok
self.browser.find_by_id('dataMenu').first.click()
self.browser.find_by_xpath("//a[@class='dataOption list']").first.click()
alicegraph = Graph.objects.get(name=self.secondGraphName)
alicegraphNodes = alicegraph.nodes.count()
spin_assert(lambda: self.assertEqual(3, alicegraph.nodes.count()))
spin_assert(lambda: self.assertEqual(
1, alicegraph.relationships.count()))
# Add new nodes and relationships and check all is correct
self.browser.find_by_id('dataMenu').first.click()
self.browser.find_by_xpath(
"//a[@class='dataOption new']").first.click()
text = self.browser.find_by_id('propertiesTitle').first.value
spin_assert(lambda: self.assertEqual(text, 'Properties'))
self.browser.find_by_value("Save Bob's type").first.click()
text = self.browser.find_by_xpath("//div[@class='pagination']/span[@class='pagination-info']").first.value
spin_assert(lambda: self.assertNotEqual(
text.find(" elements Bob's type."), -1))
spin_assert(lambda: self.assertEqual(
alicegraphNodes + 1, alicegraph.nodes.count()))
# Destroy the databases
Graph.objects.get(name=self.firstGraphName).destroy()
Graph.objects.get(name=self.secondGraphName).destroy()
示例6: UploadTestCase
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import attach_file [as 别名]
class UploadTestCase(unittest.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.browser = Browser('chrome')
def tearDown(self):
self.testbed.deactivate()
def test_when_create_task_upload_file(self):
#login
self.browser.visit("http://127.0.0.1:8080/")
self.assertEqual(self.browser.find_by_tag("h3").first.text, "Not logged in")
self.browser.find_by_id("submit-login").first.click()
self.assertEqual(self.browser.find_link_by_text("Insurance").first.text, "Insurance")
self.browser.visit("http://127.0.0.1:8080/tasks")
self.browser.click_link_by_text('Create new task')
self.browser.fill('title', 'title')
self.browser.fill('text', 'text')
self.browser.is_element_present_by_name('files[]', wait_time=10)
self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))
#self.browser.attach_file('files[]', 'test/1.png')
self.browser.find_by_css('.btn.btn-primary.start').first.click()
self.assertEqual(1, len(self.browser.find_by_css('.template-download.fade.in')))
self.assertEqual(4, len(self.browser.find_by_css('.template-download.fade.in td')))
def test_when_create_task_upload_many_files(self):
#login
self.browser.visit("http://127.0.0.1:8080/")
self.assertEqual(self.browser.find_by_tag("h3").first.text, "Not logged in")
self.browser.find_by_id("submit-login").first.click()
self.assertEqual(self.browser.find_link_by_text("Insurance").first.text, "Insurance")
self.browser.visit("http://127.0.0.1:8080/tasks")
self.browser.click_link_by_text('Create new task')
self.browser.fill('title', 'title')
self.browser.fill('text', 'text')
self.browser.is_element_present_by_name('files[]')
self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))
self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))
self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))
#self.browser.attach_file('files[]', 'test/1.png')
self.browser.find_by_css('.btn.btn-primary.start').first.click()
sleep(3)
self.assertEqual(3, len(self.browser.find_by_css('.files tr.template-download')))
示例7: add_album_to_rym
# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import attach_file [as 别名]
def add_album_to_rym(args, config_file):
br = Browser()
br.visit('https://rateyourmusic.com/account/login')
time.sleep(3)
# Login
br.fill('username', credentials.username)
br.fill('password', credentials.password)
br.find_by_id('login_submit').click()
time.sleep(5)
(title, artist, tracklist, release, cover) = config.read_config(config_file)
"""
if args.update_album:
br.visit(args.rym_album)
else:
"""
if args.add_artist:
br.visit('https://rateyourmusic.com/artist_add')
#br.fill('lastname', unicode(artist))
br.fill('lastname', artist)
br.fill('comments', args.url)
br.find_by_id('submitbtn').click()
time.sleep(3)
br.find_by_text(artist).click()
else:
br.visit(args.rym_profile)
time.sleep(3)
br.click_link_by_partial_href('/releases/ac?artist_id=')
# Add data
#br.fill('title', unicode(title))
br.fill('title', title)
br.find_by_id('format58').click()
br.find_by_id('goAdvancedBtn').click()
tracks_div = br.find_by_id('tracks_adv')
tracks_text_area = tracks_div.find_by_id('track_advanced')
#tracks_text_area.fill(unicode(tracklist))
tracks_text_area.fill(tracklist)
br.find_by_id('goSimpleBtn').click()
br.fill('notes', args.url)
(year, month, day) = parse_release_date(release)
release_month_selector = br.find_by_id('month')
release_month_selector.select(month)
release_day_selector = br.find_by_id('day')
release_day_selector.select(day)
release_year_selector = br.find_by_id('year')
release_year_selector.select(year)
br.find_by_id('previewbtn').click()
br.find_by_id('submitbtn').click()
# Add cover art
"""
coverart_img_element = br.find_by_xpath("//img[@class='coverart_img']")
print(coverart_im_element)
sys.exit(0)
"""
br.click_link_by_partial_href('/images/upload?type=l&assoc_id=')
br.attach_file('upload_file', cover)
br.fill('source', args.url)
br.find_by_id('uploadbutton').click()
time.sleep(5)
br.click_link_by_partial_href('javascript:setStatus')
# Vote for genre
br.click_link_by_partial_href('/release/')
time.sleep(3)
br.click_link_by_partial_href('/rgenre/set?')
prigen_text_area = br.find_by_xpath("//input[@id='prigen']")
prigen_text_area.fill('vaporwave')
prigen_vote_button = br.find_by_xpath("//input[@value='+ propose']").first
#.........这里部分代码省略.........