def test_local_suite(self): element = ElementState(locators=[Locator(by=By.NAME, value="q")]) element.save() state1 = State(elements=[], url="") state2 = State(elements=[element], url="http://www.google.com") state1.save() state2.save() params = {} params["url"] = "http://www.google.com/" params["search"] = "Something" commands = [ Command(command=Command.NAVIGATE, config_key="url"), Command(command=Command.SENDKEYS, element=element, config_key="search") ] action = Action(name="Some Action", steps=commands, start_state=state1, end_state=state2) action.save() test = Test(name="Some test", actions=[action]) test.save() suite = TestSuite(tests=[test], url="http://www.google.com/") config1 = RunConfig(browser="Firefox", params=params) config2 = RunConfig(browser="Chrome", params=params) configs = SuiteConfig(configs=[config1, config2], suite=suite) configs.save() suite.suite_config = configs suite.save() executor = SuiteExecutor(suite) executor.execute()
def test_suite_config(self): params = {"url": "http://www.google.com/", "search": "Something"} suite = Suite.objects().first() config1 = RunConfig(browser="Firefox", params=params) config2 = RunConfig(browser="Chrome", params=params) suite_config = SuiteConfig(configs=[config1, config2], suite=suite, params=params) suite_config.save()
def __init__(self, browsers): self.browsers = browsers self.configs=[] for browser in self.browsers: if browser.lower() == "iphone": config = RunConfig(browser="Chrome", device_name="Apple iPhone 5", host="localhost") elif browser.lower() == "ipad": config = RunConfig(browser="Chrome", device_name="Apple iPad", host="localhost") elif browser.lower() == "kindle": config = RunConfig(browser="Chrome", device_name="Amazon Kindle Fire HDX", host="localhost") elif browser.lower() == "galaxy": config = RunConfig(browser="Chrome", device_name="Samsung Galaxy S4", host="localhost") else: config = RunConfig(browser=browser) self.configs.append(config)
def test_generate_facebook_nav_test(self): config = RunConfig(params={"url": "http://www.facebook.com/"}) generator = TestGenerator(self.driver) test = generator.generate_navigate_test("http://www.facebook.com/") result = test.execute(self.driver, config) assert result.passed, result.message
def test_save_test(self): element = ElementState(locators=[Locator(by=By.NAME, value="q")]) element.save() state1 = State(elements=[], url="") state2 = State(elements=[element], url="http://www.google.com") state1.save() state2.save() config = RunConfig(params={ "url": "http://www.google.com/", "search": "Something" }) commands = [ Command(command=Command.NAVIGATE, config_key="url"), Command(command=Command.SENDKEYS, element=element, config_key="search") ] action = Action(name="Some Action", steps=commands, start_state=state1, end_state=state2) action.save() test = Test(name="Some test", actions=[action]) test.save() suite = Suite(tests=[test], url="http://www.google.com/") suite.execute(self.driver, config) suite.save() assert suite.suite_results[-1].passed, suite.suite_results[-1].message
def test_verify_state_action(self): element = ElementState(locators=[Locator(by=By.NAME, value="q")]) element2 = ElementState(locators=[Locator(by=By.NAME, value="btnK")]) element.save() element2.save() state1 = State(elements=[], url="") state1.save() state = State(elements=[element], url="http://www.google.com") state.save() verify_state = action_builder.get_verify_state_action(state) commands = [Command(command=Command.NAVIGATE, config_key="url")] action = Action(name="Google Nav", steps=commands, start_state=state1, end_state=state) action.save() state.actions = [] results = action.execute( self.driver, config=RunConfig(params={ "url": "http://www.google.com/", "search": "Something" }))
def test_execute(self): element = ElementState(locators=[Locator(by=By.NAME, value="q")]) element2 = ElementState(locators=[Locator(by=By.NAME, value="btnG")]) element.save() element2.save() state1 = State(elements=[], url="") state2 = State(elements=[element], url="http://www.google.com") state3 = State(elements=[element2], url="http://www.google.com") state1.save() state2.save() state3.save() commands = [ Command(command=Command.NAVIGATE, config_key="url"), Command(command=Command.SENDKEYS, element=element, config_key="search"), Command(command=Command.CLICK, element=element2) ] action = Action(name="Google Search", steps=commands, start_state=state1, end_state=state3) action.save() results = action.execute( self.driver, config=RunConfig(params={ "url": "http://www.google.com/", "search": "Something" }))
def test_arrow_cart_nav_test(self): params = {"url": "http://cart.arrow.com"} generator = TestGenerator(self.driver) test = generator.generate_navigate_test("http://cart.arrow.com/") result = test.execute(self.driver, config=RunConfig(params=params)) assert result.passed, result.message
def test_generate_google_nav_test(self): generator = TestGenerator(self.driver) config = RunConfig(params={"url": "http://www.google.com/"}) test = generator.generate_navigate_test("http://www.google.com/") for i in range(0, 5): result = test.execute(self.driver, config) assert result.passed, result.message
def test_sauce_firefox(self): config = RunConfig(browser="Firefox", sauce_user="******", sauce_key="c479e821-57e7-4b3f-8548-48e520585187") session = BrowserSession(config) session.start_sauce_session() session.driver.get("http://www.google.com") session.driver.quit()
def tesgt_emulated_ipad(self): config = RunConfig(browser="Chrome", device_name="Apple iPhone 5", host="localhost") session = BrowserSession(config) session.start_session() session.driver.get("http://www.facebook.com") session.end()
def test_emulated_kindle(self): config = RunConfig(browser="Chrome", device_name="Amazon Kindle Fire HDX", host="localhost") session = BrowserSession(config) session.start_session() session.driver.get("http://www.percolate.com") session.end()
def test_invalid_command(self): element = ElementState(locators=[Locator(by=By.NAME, value="q")]) element.save() command = Command(command="INVALID", element=element, params="Something") response = command.execute(self.driver, config=RunConfig()) assert not response.passed, response.exception
def test_sauce_iphone_6(self): config = RunConfig(browser="Safari", device_name="iPhone 6", version="8.0", sauce_user="******", sauce_key="c479e821-57e7-4b3f-8548-48e520585187") session = BrowserSession(config) session.start_sauce_session() session.driver.get("http://www.google.com") session.driver.quit()
def test_init_state(self): self.url = "http://www.google.com" blank_state = state_builder.get_blank_state() blank_state.save() self.driver.get(self.url) state = state_builder.get_current_state(self.driver) state.save() element = ElementState(locators=[Locator(by=By.NAME, value="q")]) element2 = ElementState(locators=[Locator(by=By.NAME, value="btnG")]) element.save() element2.save() nav_command = [Command(command=Command.NAVIGATE, config_key="url")] type_command = [ Command(command=Command.SENDKEYS, element=element, config_key="search"), Command(command=Command.SENDKEYS, element=element, config_key="enter") ] action = Action(name="Navigate", steps=nav_command, start_state=blank_state, end_state=state) action.save() action2 = Action(name="Search", steps=type_command, start_state=state, end_state=blank_state) action2.save() config = RunConfig( params={ "url": "http://www.google.com/", "search": "Something", "enter": Keys.ENTER }) action.execute(self.driver, config) action2.execute(self.driver, config) time.sleep(5) new_state = state_builder.get_current_state(self.driver) new_state.save() action2.end_state = new_state action2.save() new_state.init_actions = [action, action2] new_state.save() state_id = new_state.id print state_id self.driver.get("http://www.msn.com/") new_state.initialize_state(self.driver, config)
def test_sauce_suite(self): element = ElementState(locators=[Locator(by=By.NAME, value="q")]) element.save() state1 = State(elements=[], url="") state2 = State(elements=[element], url="http://www.google.com") state1.save() state2.save() params = {} params["url"] = "http://www.google.com/" params["search"] = "Something" commands = [ Command(command=Command.NAVIGATE, config_key="url"), Command(command=Command.SENDKEYS, element=element, config_key="search") ] action = Action(name="Some Action", steps=commands, start_state=state1, end_state=state2) action.save() test = Test(name="Some test", actions=[action]) test.save() suite = TestSuite(tests=[test], url="http://www.google.com/") config1 = RunConfig(browser="iphone", sauce_user="******", host="sauce", sauce_key="c479e821-57e7-4b3f-8548-48e520585187", params=params) config2 = RunConfig(browser="ipad", sauce_user="******", shost="sauce", auce_key="c479e821-57e7-4b3f-8548-48e520585187", params=params) configs = SuiteConfig(configs=[config1], suite=suite) configs.save() suite.suite_config = configs suite.save() executor = SuiteExecutor(suite) executor.execute()
def test_generate_login_test(self): config = RunConfig( params={ "url": "https://www.gmail.com/", "username": "******", "password": "******" }) test = LoginTestGenerator(self.driver, "http://www.gmail.com/", config).generate() result = test.execute(self.driver, config) assert result.passed, result.message
def test_compare_state(self): self.driver.get("http://www.google.com/") state1 = state_builder.get_blank_state() state1.save() state2 = state_builder.get_current_state(self.driver) state2.save() self.driver.get("https://www.google.com/#q=something") state3 = state_builder.get_current_state(self.driver) state3.save() config = RunConfig(params={ "url": "http://www.google.com/", "search": "Something" }) search_fields = element_filter.filter_contains_text( state2.elements, "Search") search_field = search_fields[0] commands1 = [Command(command=Command.NAVIGATE, config_key="url")] commands2 = [ Command(command=Command.SENDKEYS, element=search_field, config_key="search") ] nav_action = Action(name="Google Nav", steps=commands1, start_state=state1, end_state=state2) search_action = Action(name="Google Search", steps=commands2, start_state=state2, end_state=state3) nav_action.save() search_action.save() test = Test(name="Google Search Failure", actions=[nav_action, search_action]) test.save() suite = Suite(name="Failure Example", tests=[test]) suite.execute(self.driver, config) suite.save(cascade=True) print suite.id assert suite.suite_results[-1].passed search_field.locators = [Locator(by=By.CLASS_NAME, value="INVALID")] search_field.save() suite.execute(self.driver, config=config) results = suite.suite_results[-1] assert not results.passed comparison = StateComparer(self.driver).compare_states( results.failed_state, results.actual_state) assert len(comparison[0].elements) == len(comparison[1].elements)
def test_failure_report(self): element = ElementState(locators=[Locator(by=By.NAME, value="INVALID")]) element2 = ElementState( locators=[Locator(by=By.NAME, value="INVALID")]) element.save() element2.save() state1 = State(elements=[], url="") state2 = State(elements=[element], url="http://www.google.com") state3 = State(elements=[element2], url="http://www.google.com") state1.save() state2.save() state3.save() commands = [ Command(command=Command.NAVIGATE, config_key="http://www.google.com/"), Command(command=Command.SENDKEYS, element=element, config_key="search"), Command(command=Command.CLICK, element=element2) ] action = Action(name="Google Search", steps=commands, start_state=state1, end_state=state3) action.save() test = Test(name="Some test", actions=[action]) test.save() suite = Suite(name="some name", tests=[test]) suite.execute(self.driver, config=RunConfig(params={ "url": "http://www.google.com/", "search": "Something" })) suite.save() assert not suite.suite_results[-1].passed assert suite.suite_results[-1].actual_state is not None assert suite.suite_results[-1].failed_state is not None assert suite.suite_results[-1].html is not None and not "" assert suite.suite_results[-1].screenshot is not None and not ""
def test_send_keys(self): self.driver.get("http://www.google.com/") command = Command(driver=self.driver, command=Command.SENDKEYS,element=ElementState(locators=[Locator(by=By.NAME,value="q")]),config_key="search") command.execute(self.driver, config=RunConfig(params={"search":"Something"})) assert WebElement(self.driver, [Locator(by=By.NAME,value="q")]).value == "Something"
def test_launch_local_firefox(self): session = BrowserSession(RunConfig.default()) session.browser = "Firefox" session.start_local_session() session.driver.get("http://www.google.com") session.driver.quit()
class MobileDevices: ANDROID_5 = RunConfig(browser="android", device_name="Android 5.1 Emulator") NEXUS_4 = RunConfig(browser="android", device_name="LG Nexus 4 Emulator") SAMSUNG_GALAXY_TAB_3 = RunConfig( browser="android", device_name="Samsung Galaxy Tab 3 Emulator") NEXUS_7 = RunConfig(browser="android", device_name="Google Nexus 7 HD Emulator") SAMSUNG_S4 = RunConfig(browser="android", device_name="Samsung Galaxy S4 Emulator") IPHONE_4S = RunConfig(browser="iPhone", device_name="iPhone 4s") IPHONE_5 = RunConfig(browser="iPhone", device_name="iPhone 5") IPHONE_6 = RunConfig(browser="iPhone", device_name="iPhone 6") IPHONE_6_PLUS = RunConfig(browser="iPhone", device_name="iPhone 6 Plus") IPAD_AIR = RunConfig(browser="iPhone", device_name="iPad Air") IPAD_2 = RunConfig(browser="iPhone", device_name="iPad 2")
def test_navigate(self): self.driver.get("http://www.google.com/") command = Command(driver=self.driver, command=Command.NAVIGATE,config_key="url") command.execute(self.driver, config=RunConfig(params={"url":"http://www.google.com/"})) assert "google" in self.driver.current_url
def test_execute_navigate(self): command = Command(command=Command.NAVIGATE, config_key="url") command.execute( self.driver, config=RunConfig(params={"url": "http://www.google.com/"})) assert self.driver.current_url == "https://www.google.com/?gws_rd=ssl", self.driver.current_url
def test_click(self): self.driver.get("http://www.google.com/") command = Command(driver=self.driver, command=Command.CLICK,element=ElementState(locators=[Locator(by=By.NAME,value="q")])) command.execute(self.driver, config=RunConfig())