def logout(automator): url = automator.config.get_user_option_value("wp.logout.url").as_str() automator.browser.go_to_url(url) automator.element(With.link_ptext("log out")).click() message = automator.element(With.ptext("logged out")).wait_until_visible() automator.quit()
def login(automator,at_home=False): if not at_home: go_to_wp_home(automator) user, pwd = automator.config.get_user_option_value("wp.users.admin").split_as_str_list() # Login automator.element(With.id("user_login")).set_text(user) automator.element(With.id("user_pass")).set_text(pwd) automator.element(With.id("wp-submit")).click() automator.element(With.class_name("welcome-view-site")).wait_until_visible()
def __convert_to_with(self, input): w = None if isinstance(input, With): w = input elif type(input) is str: w = With.gns_name(input) elif isinstance(input, Enum): w = With.gns_name(input.name) else: raise Exception( "A With object or name of element is expected as argument.") return w
def login_with_default_creds(self): self.app.browser.go_to_url( self.config.get_user_option_value("wp.login.url").as_str()) user, pwd = self.config.get_user_option_value( "wp.users.admin").split_as_str_list() # Login self.app.element( With.gns_name("login").format(RoLe="user")).set_text(user) self.app.element( With.gns_name("password").format(roLE="user")).set_text(pwd) self.app.element("submit").click() self.app.element("view-site").wait_until_visible()
from arjuna.tpi import Arjuna from arjuna.tpi.guiauto.helpers import With from commons import * init_arjuna() automator = launch_automator() login(automator) automator.element(With.link_text("Posts")).click() automator.element(With.link_text("Categories")).click() check_boxes = automator.multi_element(With.name("delete_tags[]")) check_boxes.at_index(0).uncheck() check_boxes.at_index(0).check() check_boxes.at_index(0).check() check_boxes.at_index(1).uncheck() check_boxes.first.uncheck() check_boxes.last.uncheck() check_boxes.random.uncheck() logout(automator)
from commons import * from arjuna.tpi.guiauto.helpers import With, GuiActionConfig init_arjuna() automator = launch_automator() url = automator.config.get_user_option_value("narada.ex.radio.url").as_str() automator.browser.go_to_url(url) radios = automator.radio_group(With.name("Traditional")) radios.select_index(1) # Tag mix up radios = automator.radio_group(With.name("Prob1")) radios.select_index(1) # Type mix up radios = automator.radio_group(With.name("Prob2")) radios.select_index(1) # Group mix up radios = automator.radio_group(With.class_name("Prob3")) radios.select_index(1) # state check off conf = GuiActionConfig.builder().check_pre_state(False).build() radios = automator.element(With.name("Traditional").configure(config)) radios.select_index(1) # tag mix up, state check off
from commons import * from arjuna.tpi.guiauto.helpers import With, Screen init_arjuna() automator = launch_automator() go_to_wp_home(automator) user, pwd = automator.config.get_user_option_value( "wp.users.admin").split_as_str_list() # Login user_field = automator.element(With.id("user_login")) user_field.identify() user_field.wait_until_clickable() user_field.set_text(user) pwd_field = automator.element(With.id("user_pass")) pwd_field.identify() pwd_field.wait_until_clickable() pwd_field.set_text(pwd) submit = automator.element(With.id("wp-submit")) submit.identify() submit.wait_until_clickable() submit.click() automator.element(With.class_name("welcome-view-site")).wait_until_visible() # Logout url = automator.config.get_user_option_value("wp.logout.url").as_str()
from arjuna.tpi import Arjuna from arjuna.tpi.guiauto.helpers import With from commons import * init_arjuna() automator = launch_automator() login(automator) automator.execute_javascript( "document.getElementsByClassName('welcome-view-site')[0].click();") automator.element(With.link_text("Site Admin")).wait_until_clickable() logout(automator)
''' 3. (Especially for custom select controls) - Click the drop down control and then click the option. ''' from commons import * from arjuna.tpi.guiauto.helpers import With, GuiActionConfig init_arjuna() automator = launch_automator() url = automator.config.get_user_option_value("narada.ex.dropdown.url").as_str() automator.browser.go_to_url(url) conf = GuiActionConfig.builder().check_type(False).check_post_state( False).build() dropdown = automator.dropdown( With.id("DropDown"), option_container_locators=With.class_name("dropdown"), option_locators=With.class_name("dropdown-item")) dropdown.configure(conf) dropdown.select_index(2) # automator.quit()
''' The following code is for user name field. Html of user name: <input type="text" name="log" id="user_login" class="input" value="" size="20"> Params: APP URL: E.g. http://192.168.56.103 Page: E.g. wp-login Resulting in http://192.168.56.103/wp-login.php ''' identifier = r"//*[@action='$app_url$/$page$.php']" app_url = automator.config.get_user_option_value("wp.app.url").as_str() page = "wp-login" element = automator.element(With.xpath(identifier).format(app_url=app_url, page=page)) element.identify() print(element.source.content.root) # Named params need not be passed in order, providing you flexibility, readability and preventing positional errors. element = automator.element(With.xpath(identifier).format(page=page, app_url=app_url)) element.identify() print(element.source.content.root) # Names for parameters are case-insensitive element = automator.element(With.xpath(identifier).format(PaGe=page, aPP_Url=app_url)) element.identify() print(element.source.content.root) logout(automator)
from commons import * from arjuna.tpi.guiauto.helpers import With init_arjuna() automator = launch_automator() go_to_wp_home(automator) # The following code is for user name field. # Html of user name: <input type="text" name="log" id="user_login" class="input" value="" size="20"> element = automator.element(With.id("user_login")) element.identify() print(element.source.content.root) element = automator.element(With.name("log")) element.identify() print(element.source.content.root) element = automator.element(With.class_name("input")) element.identify() print(element.source.content.root) element = automator.element(With.tag_name("input")) element.identify() print(element.source.content.root) # The following options are for # Html of link: <a href="http://192.168.56.103/wp-login.php?action=lostpassword" title="Password Lost and Found">Lost your password?</a> element = automator.element(With.link_text("Lost your password?")) element.identify() print(element.source.content.root)
from commons import * from arjuna.tpi.guiauto.helpers import With, GuiActionConfig init_arjuna() automator = launch_automator() url = automator.config.get_user_option_value( "narada.ex.elemstate.url").as_str() automator.browser.go_to_url(url) automator.element(With.id("target")).click() automator.alert.confirm() automator.browser.go_to_url(url) conf = GuiActionConfig.builder().check_pre_state(False).build() print(conf.settings) automator.element(With.id("target")).configure(conf).click() automator.alert.confirm()
from commons import * def print_source_info(source): print(source.content.root) print(source.content.all) print(source.content.inner) print(source.content.text) init_arjuna() automator = launch_automator() go_to_wp_home(automator) element = automator.element(With.id("loginform")) print_source_info(element.source) login(automator, at_home=False) automator.element(With.link_text("Settings")).click() # Dopdown element = automator.dropdown(With.id("default_role")) print_source_info(element.source) # Radio date_format = automator.radio_group(With.name("date_format")) print_source_info(date_format.source) # Automator source
from commons import * from arjuna.tpi.guiauto.helpers import With init_arjuna() automator = launch_automator() go_to_wp_home(automator) # Based on Text element = automator.element(With.xpath("//*[text() = 'Lost your password?']")) element.identify() print(element.source.content.root) # Based on partial text element = automator.element(With.xpath("//*[contains(text(), 'Lost')]")) element.identify() print(element.source.content.root) # Based on Title element = automator.element( With.xpath("//*[@title = 'Password Lost and Found']")) element.identify() print(element.source.content.root) # Based on Value element = automator.element(With.xpath("//*[@value = 'Log In']")) element.identify() print(element.source.content.root) # Based on any attribute e.g. for element = automator.element(With.xpath("//*[@for = 'user_login']"))
from commons import * from arjuna.tpi.guiauto.helpers import With, Screen init_arjuna() automator = launch_automator() go_to_wp_home(automator) user, pwd = automator.config.get_user_option_value( "wp.users.admin").split_as_str_list() # Login automator.element(With.id("user_login")).set_text(user) automator.element(With.id("user_pass")).set_text(pwd) automator.element(With.id("wp-submit")).click() automator.element(With.class_name("welcome-view-site")).wait_until_visible() # Logout url = automator.config.get_user_option_value("wp.logout.url").as_str() automator.browser.go_to_url(url) automator.element(With.link_ptext("log out")).click() message = automator.element(With.ptext("logged out")).wait_until_visible() automator.quit()
from arjuna.tpi import Arjuna from arjuna.tpi.guiauto.helpers import With from commons import * init_arjuna() automator = launch_automator() login(automator) automator.element(With.link_text("Settings")).click() date_format = automator.radio_group(With.name("date_format")) print(date_format.has_value_selected("Y-m-d")) print(date_format.has_index_selected(1)) print(date_format.first_selected_option_value) date_format.select_value(r"\c\u\s\t\o\m") date_format.select_index(2) logout(automator)
from commons import * from arjuna.tpi.guiauto.helpers import With, Screen init_arjuna() automator = launch_automator() go_to_wp_home(automator) # Based on Text element = automator.element(With.text("Lost your password?")) element.identify() print(element.source.content.root) # Based on partial text element = automator.element(With.ptext("Lost")) element.identify() print(element.source.content.root) # Based on Title element = automator.element(With.title("Password Lost and Found")) element.identify() print(element.source.content.root) # Based on Value element = automator.element(With.value("Log In")) element.identify() print(element.source.content.root) # Based on any attribute e.g. for element = automator.element(With.attr_value("[for][user_login]")) element.identify()
from commons import * from arjuna.tpi.guiauto.helpers import With init_arjuna() automator = launch_automator() go_to_wp_home(automator) # Based on any attribute e.g. for element = automator.element(With.css_selector("*[for = 'user_login']")) element.identify() print(element.source.content.root) # Based on partial content of an attribute element = automator.element(With.css_selector("*[for *= '_login']")) element.identify() print(element.source.content.root) # Based on element type element = automator.element(With.css_selector("*[type ='password']")) element.identify() print(element.source.content.root) # Based on compound classes element = automator.element(With.css_selector(".button.button-large")) element.identify() print(element.source.content.root) automator.quit()
automator.execute_javascript("window.open('/abc')") cwin = automator.latest_child_window cwin.focus() print(cwin.title) cwin.close() automator.execute_javascript("window.open('https://rahulverma.net')") automator.execute_javascript("window.open('https://google.com')") automator.close_all_child_windows() print(main_win.title) automator.execute_javascript("window.open('https://rahulverma.net')") automator.execute_javascript("window.open('https://google.com')") dwin = automator.child_window(With.window_title("Google")) dwin.focus() dwin.title dwin.close() automator.execute_javascript("window.open('https://rahulverma.net')") automator.execute_javascript("window.open('https://google.com')") dwin = automator.child_window(With.window_ptitle("gle")) dwin.focus() dwin.title dwin.close() automator.execute_javascript("window.open('https://rahulverma.net')") automator.execute_javascript("window.open('https://google.com')")
go_to_wp_home(automator) def cleanup(): global automator global melement for i in range(melement.length): print(melement.at_index(i).source.content.root) automator.quit() melement = None automator = None setup() melement = automator.multi_element( With.javascript("return document.getElementById('wp-submit')")) cleanup() setup() melement = automator.multi_element( With.javascript("return document.getElementsByClassName('input')")) cleanup() # setup() # melement = automator.multi_element(With.javascript("return null")) # cleanup() # setup() # melement = automator.multi_element(With.javascript("return [undefined]")) # cleanup()
from commons import * from arjuna.tpi.guiauto.helpers import With, Screen init_arjuna() automator = launch_automator() go_to_wp_home(automator) # Two identifiers. Only first one would be tried as it succeeds. element = automator.element(With.id("user_login"), With.name("log")) element.identify() print(element.source.content.root) # Two identifiers. First invalid, second valid. Hence it succeeds by using second With construct # Identification max wait time is for all With constructs clubbed together. element = automator.element(With.id("INVALID"), With.name("log")) element.identify() print(element.source.content.root) automator.quit()
from arjuna.tpi import Arjuna from arjuna.tpi.guiauto.helpers import With from commons import * init_arjuna() automator = launch_automator() login(automator) automator.element(With.link_text("Posts")).click() automator.element(With.link_text("Add New")).click() tinymce = With.id("tinymce") publish = With.id("publish") # Frame by identifier and jump to root automator.frame(With.id("content_ifr")).focus() automator.element(tinymce).set_text("This is a test - frame by name.") automator.dom_root.focus() automator.element(publish).click() # Frame by index automator.frame(With.index(0)).focus() automator.element(tinymce).set_text("This is a test - frame by index.") # Focusing on root from frame itself automator.dom_root.focus() automator.element(publish).click() # jump to parent frame = automator.frame(With.xpath("//iframe")) print(frame)
Arjuna tries to cater to all of them with a single abstraction - its DropDown object. 3 will be covered later when element configuration has been discussed. ''' from arjuna.tpi import Arjuna from arjuna.tpi.guiauto.helpers import With from commons import * init_arjuna() automator = launch_automator() login(automator) automator.element(With.link_text("Settings")).click() role_select = automator.dropdown(With.id("default_role")) role_select.select_value("editor") role_select.select_visible_text("Subscriber") print(role_select.has_visible_text_selected("Subscriber")) print(role_select.has_value_selected("subscriber")) print(role_select.has_index_selected(2)) print(role_select.first_selected_option_value) print(role_select.first_selected_option_text) role_select.select_index(4) print(role_select.has_index_selected(4)) text = "Subscriber"