Ejemplo n.º 1
0
    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()
Ejemplo n.º 2
0
    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"
            }))
Ejemplo n.º 3
0
    def get_logout_action(self):

        command1 = Command(command=Command.SENDKEYS,
                           element=self.username,
                           config_key=ElementType.USERNAME)
        command2 = Command(command=Command.SENDKEYS,
                           element=self.password,
                           config_key=ElementType.PASSWORD)
        command3 = Command(command=Command.CLICK, element=self.submit)

        action = Action(name="Login %s" % self.start_state.url,
                        steps=[command1, command2, command3],
                        start_state=self.start_state)

        response = action.execute(self.driver, self.config)
        if response.passed and not self.start_state.is_state_present(
                self.driver):
            print "assuming login was successful because the state is no longer present"
            self.end_state = state_builder.get_current_state(self.driver)
            self.end_state.save()
            action.end_state = self.end_state
            action.save()
            return action
        else:
            raise Exception("Could not generate login action")
Ejemplo n.º 4
0
    def test_save_action(self):
        element = ElementState(locators=[Locator(by=By.NAME, value="q")])
        element.save()
        google_home = State(url=self.driver.current_url, elements=[element])
        google_home.save()
        action = action_builder.get_nav_action("http://www.google.com/",
                                               google_home)
        action.save()

        state1 = State(elements=[element], url="http://www.google.com")
        state1.save()

        state2 = State(elements=[element], url="http://www.google.com")

        state2.save()
        commands = [
            Command(command=Command.NAVIGATE, params="http://www.google.com/"),
            Command(command=Command.SENDKEYS,
                    element=element,
                    params="Something")
        ]
        action = Action(name="Some Action",
                        steps=commands,
                        start_state=state1,
                        end_state=state2)
        action.save()
        state1.actions = [action]
        state1.save()
        print state1.id
        assert state1.actions[0].steps == commands
        assert state1.actions[0].end_state == state2
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
def register_commands():
    # first we delete all the current registered commands
    Command.delete().execute()
    for command in all_commands:
        logger.debug("Creating {}".format(command))
        Command.create(name=command.name,
                       admin_required=command.admin_required)
        importlib.import_module("commands.{}".format(command.name))
    return True
Ejemplo n.º 8
0
async def run():
    tasks = [
        Command("cleanmgr.exe /sagerun:1"),
        Command("wuauclt /detectnow /updatenow"),
        Command("cipher.exe /w:E"),
        Command("cipher.exe /w:C"),
        Command("sfc /scannow"),
    ]

    await asyncio.gather(*[task() for task in tasks])
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
 def handle_message(self, state_update):
     logger.debug("Handling message")
     conversation = self.get_or_create_conversation(state_update.conversation)
     if state_update.event_notification.event.sender_id.gaia_id == settings.BOT_ID:
         message = Message.create(conversation=conversation, user=self.user, text="".join(
             [seg.text for seg in state_update.event_notification.event.chat_message.message_content.segment]), time=datetime.now())
         message.conversation.logger.info(message.text.replace("\n", " "), extra={
             "username": message.user.username,
             "message_time": datetime.strftime(message.time, "%Y-%m-%d %X"),
         })
         return True
     sending_user = User.get(User.id == state_update.event_notification.event.sender_id.gaia_id)
     message_body = ""
     for seg in state_update.event_notification.event.chat_message.message_content.segment:
         message_body += seg.text
     message = Message.create(conversation=conversation, user=sending_user, text=message_body, time=datetime.now())
     message.conversation.logger.info(message.text.replace("\n", " "), extra={
         "username": message.user.username,
         "message_time": datetime.strftime(message.time, "%Y-%m-%d %X"),
     })
     matched = self.command_matcher.match(message.text)
     if matched:
         try:
             cmd_to_run = Command.get(name=matched.group(1).lower())
             yield from cmd_to_run.run(bot=self,
                                       conversation=message.conversation,
                                       user=message.user,
                                       args=message.text.split(matched.group(1), 1)[-1].split())
         except Command.DoesNotExist:
             pass
     for hook in self.hooks:
         matcher = re.compile(r"{}".format(hook.regex))
         if matcher.match(message.text):
             yield from hook.run(bot=self, conversation=message.conversation, user=message.user, text=message.text)
     return True
Ejemplo n.º 12
0
    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"
            }))
Ejemplo n.º 13
0
def add():
    commandString = request.form["command"]
    experimentId = None
    nodes = []

    try:
        experimentId = request.form["experimentId"]
    except KeyError:
        pass

    try:
        nodes = Node.query.filter(Node.id.in_(request.form.getlist("nodeIds"))).all()
    except KeyError:
        pass

    try:
        command = Command(commandString, experimentId, nodes)
        db.session.add(command)
        db.session.commit()
        flash("Command '%s' added successfully" % commandString)
    except Exception as e:
        db.session.rollback()
        flash("Error adding command '%s': %s" % (commandString, str(e))) 
    if experimentId:
        return redirect(url_for("web.experiment.show", id=experimentId))
    else:
        return redirect(url_for("web.admin.index"))
Ejemplo n.º 14
0
 def setUpClass(cls):
     element = ElementState(locators=[Locator(by=By.NAME, value="q")])
     element.save()
     command = Command(command=Command.SENDKEYS,
                       element=element,
                       params="Something")
     cls.element_id = command.element.id
Ejemplo n.º 15
0
def get_click_action(element, start_state, end_state):
    command = Command(element=element, command=Command.CLICK)
    action = Action(name="Click %s" % str(element),
                    steps=[command],
                    start_state=start_state,
                    end_state=end_state)
    action.save()
    return action
Ejemplo n.º 16
0
def get_nav_action(url, end_state):
    command1 = Command(command=Command.NAVIGATE, config_key="url")
    action = Action(name="Get %s" % url,
                    steps=[command1],
                    start_state=state_builder.get_blank_state(),
                    end_state=end_state)
    action.save()
    return action
Ejemplo n.º 17
0
 def create_command(self, command_line="echo OK", experimentId=None, nodes=[]):
     if not experimentId:
         experiment = self.create_experiment(nodes=nodes)
         experimentId = experiment.id
     command = Command(command_line, experimentId)
     db.session.add(command)
     db.session.commit()
     return command
Ejemplo n.º 18
0
def get_verify_state_action(state):
    all_commands = []
    for element in state.elements:
        all_commands.append(Command(element=element, command=Command.VERIFY))
    action = Action(name="Verify %s" % state,
                    steps=all_commands,
                    start_state=state,
                    end_state=state)
    action.save()
    return action
Ejemplo n.º 19
0
def get_sendkeys_action(element, start_state, end_state):
    command = Command(element=element,
                      command=Command.SENDKEYS,
                      config_key=element.type)
    action = Action(name="Send Keys %s" % str(element),
                    steps=[command],
                    start_state=start_state,
                    end_state=end_state)
    action.save()
    return action
Ejemplo n.º 20
0
    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()
Ejemplo n.º 21
0
 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 ""
Ejemplo n.º 22
0
def coords(id):
    node = Node.query.get_or_404(id)
    coordx = request.form["coordx"]
    coordy = request.form["coordy"]
    coordz = request.form["coordz"]
    if is_number(coordx) and is_number(coordy) and is_number(coordz):
        try:
            node.coordx = coordx
            node.coordy = coordy
            node.coordz = coordz
            cmd = "wibed-location " + coordx + " " + coordy + " " + coordz
            command = Command(cmd, None, [node])
            db.session.add(command)
            flash("Node info will be updated")
            db.session.commit()
        except Exception as e:
            db.session.rollback()
            flash("Error updating node: %s" % (str(e)))
    else:
        flash("Incorrect inserted coordinates")
    return render_template("node/show.html", node=node)
Ejemplo n.º 23
0
    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"
Ejemplo n.º 24
0
 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())
Ejemplo n.º 25
0
from lifecycle.ingest.ingest import ingest
from models.command import Command
import sys

command = Command(sys.argv[1:])
ingest(command)
Ejemplo n.º 26
0
 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
Ejemplo n.º 27
0
 def test_params(self):
     element = ElementState(locators=[Locator(by=By.NAME, value="q")])
     element.save()
     command = Command(command=Command.SENDKEYS,
                       element=element,
                       params="Something")
Ejemplo n.º 28
0
    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