Example #1
0
class SeleniumTestCase(LiveServerTestCase):
        def setUp(self):
            super(SeleniumTestCase, self).setUp()
            self.selenium = WebDriver()

        def tearDown(self):
            self.selenium.quit()
            super(SeleniumTestCase, self).tearDown()

        def loginAsUser(self):
            self.selenium.get('%s%s' % (self.live_server_url, '/accounts/login/'))
            username_input = self.selenium.find_element_by_name("username")
            username_input.send_keys('user')
            password_input = self.selenium.find_element_by_name("password")
            password_input.send_keys('demo')
            self.selenium.find_element_by_xpath('//input[@value="Login"]').click()
Example #2
0
class SeleniumTestCase(LiveServerTestCase):
    def setUp(self):
        super(SeleniumTestCase, self).setUp()
        self.selenium = WebDriver()

    def tearDown(self):
        self.selenium.quit()
        super(SeleniumTestCase, self).tearDown()

    def loginAsUser(self):
        self.selenium.get('%s%s' % (self.live_server_url, '/accounts/login/'))
        username_input = self.selenium.find_element_by_name("username")
        username_input.send_keys('user')
        password_input = self.selenium.find_element_by_name("password")
        password_input.send_keys('demo')
        self.selenium.find_element_by_xpath('//input[@value="Login"]').click()
Example #3
0
def get_hotel(driver: WebDriver, city: str, n: int) -> None:
    driver.get('%s/%s/p%d' % (ROOT_URL, city, n))

    driver.implicitly_wait(1)

    hotel_list = driver.find_element_by_id('hotel_list')
    hotels = hotel_list.find_elements_by_class_name('searchresult_list')
    for hotel in hotels:
        hid = str(hotel.get_attribute('id'))
        if not re.match(r'^\d+$', hid):
            continue
        name = driver.find_element_by_xpath('//*[@id="%s"]/ul/li[2]/h2/a' %
                                            hid).get_attribute('title')
        try:
            points = hotel.find_element_by_class_name('hotel_value').text
        except Exception:
            continue
        start_price = hotel.find_element_by_class_name('J_price_lowList').text
        about_points = hotel.find_element_by_class_name('hotel_judgement').text
        points_count = RE_COMMENT.search(about_points).group()
        logging.info('%s\n%s\n%s\n%s\n%s\n%s\n%s\n' %
                     (city, hid, name, n, points, start_price, points_count))
        if Hotel.objects.filter(hid=hid).count() == 0:
            Hotel.objects.create(city=city,
                                 hid=hid,
                                 name=name,
                                 page=n,
                                 points=points,
                                 start_price=start_price,
                                 points_count=points_count)