Created by Sanyam Khurana | @ErSanyamKhurana | @CuriousLearner
Marionette consists of two parts:
Let's learn a little bit about mach
Mach (German for do) is a command-line interface to help developers perform common tasks.
You build, run, test your builds using mach
... and much more ...
pip install marionette_client
./mach run -marionette
from marionette import Marionette
client = Marionette('localhost', port=2828)
client.start_session()
client.local_port
client.session_capabilities
client.delete_session()
CONTENT CONTEXT
client.CONTEXT_CONTENT
CHROME CONTEXT
client.CONTEXT_CHROME
Set CONTEXT using set_context method
client.set_context(client.CONTEXT_CONTENT)
url = 'http://mozilla.org'
client.navigate(url)
url = 'http://SanyamKhurana.com'
client.navigate(url)
client.go_back()
client.go_forward()
assert client.get_url() == url
find_element()
find_elements()
from marionette_driver.marionette import HTMLElement
element = client.find_element(By.ID, 'first_name')
assert type(element) == HTMLElement
elements = client.find_elements(By.TAG_NAME, 'a')
assert type(elements) == list
element.send_keys('I love Python!')
element.click()
element.get_attribute()
buttons = client.find_elements(By.CLASS_NAME, 'button')
container_buttons = client.find_elements(By.CSS_SELECTOR, '#container li')
form = client.find_element(By.NAME, 'register')
paragraphs = client.find_elements(By.TAG_NAME, 'p')
link = client.find_element(By.LINK_TEXT, 'I love Python!')
link = client.find_element(By.PARTIAL_LINK_TEXT, 'love')
elem = client.find_element(By.XPATH, './/*[@id="first-name"')
result = client.execute_script("return arguments[0] * arguments[1];",
script_args=[5, 7])
result = client.execute_async_script("""
setTimeout(function() {
marionetteScriptFinished("finished");
}, arguments[0]);
""", script_args=[2000])
assert result == "finished"
alert = self.marionette.switch_to_alert()
text = alert.text
alert.accept()
first_element = client.find_element(By.ID, "first_element")
second_element = client.find_element(By.ID, "second_element")
# create action object
action = Actions(client)
# add actions (press, wait, move, release) into the object
action.press(first_element).wait(10).move(second_element).release()
# fire all the added events
action.perform()
# create multiaction object
multitouch = MultiActions(client)
# create several action objects
action_1 = Actions(client)
action_2 = Actions(client)
# add actions to each action object/finger
action_1.press(element1).move_to(element2).release()
action_2.press(element3).wait().release(element3)
# fire all the added events
multitouch.add(action_1).add(action_2).perform()
# Wait 30 seconds for window to open, checking for its presence once
# every 5 seconds.
wait = Wait(client, timeout=30, interval=5,
ignored_exceptions=errors.NoSuchWindowException)
window = wait.until(lambda m: m.switch_to_window(42))
Questions?
My websites:
www.SanyamKhurana.com | www.TheGeekyWay.com