Best Python code snippet using robotframework-pageobjects_python
monkeypatches.py
Source: monkeypatches.py
...58 locators = self._parse_table_locator(table_locator, location_method)59 locators = [locator % str(row) for locator in locators]60 return self._search_in_locators(browser, locators, content)61 TableElementFinder.find_by_row = find_by_row62 def find_by_col(self, browser, table_locator, col, content):63 """ 64 Selenium2Library locator method used by _TableElementKeywords.table_row_should_contain65 66 Monkey patch: added support for negative indexes (QAR-48165).67 """ 68 location_method = "col"69 if "-" == col[0]:70 col = col[1:]71 location_method = "last-col"72 locators = self._parse_table_locator(table_locator, location_method)73 locators = [locator % str(col) for locator in locators]74 return self._search_in_locators(browser, locators, content)75 76 TableElementFinder.find_by_col = find_by_col...
repository.py
Source: repository.py
...22 return inspect(self._model).primary_key[0].name23 async def delete(self, item: _MT):24 await self.session.delete(item)25 async def find_by_pk(self, pk: _T) -> Optional[_MT]:26 return await self.find_by_col(**{self._pk_column: pk})27 @final28 async def find_by_col(self, **kwargs) -> Optional[_MT]:29 item = await self.session.execute(self._gen_stmt_for_param(**kwargs))30 return item.unique().scalars().one_or_none()31 @final32 def _gen_stmt_for_param(self, **kwargs) -> Select:33 stmt = select(self._model)34 if kwargs:35 for key, value in kwargs.items():36 stmt = stmt.where(getattr(self._model, key) == value)37 return stmt38 @final39 async def find_all(self, **kwargs) -> List[_MT]:40 stmt = self._gen_stmt_for_param(**kwargs)41 result = await self.session.execute(stmt)42 return result.unique().scalars().fetchall()43 @final44 async def is_exists(self, **kwargs) -> bool:45 result = await self.session.execute(self._gen_stmt_for_param(**kwargs).exists().select())46 return result.scalar()47 @final48 def create(self, item: _MT):49 self.session.add(item)50 @final51 async def create_all(self, items: List[_MT]):52 self.session.add_all(items)53 def update(self, item: _MT, req: dict):54 for k, v in req.items():55 if v is not None:56 setattr(item, k, v)57class BaseSyncRepository(Protocol):58 _session: Session59 @property60 def session(self) -> Session:61 assert self._session is not None62 return self._session63class SyncRepository(BaseSyncRepository, Protocol[_MT, _T]):64 @property65 def _model(self):66 return get_args(self.__orig_bases__[0])[0]67 @property68 def _pk_column(self) -> str:69 return inspect(self._model).primary_key[0].name70 @final71 def count(self, **kwargs) -> int:72 return self._gen_query_for_param(**kwargs).count()73 def delete(self, item: _MT):74 self.session.delete(item)75 def find_by_pk(self, pk: _T) -> Optional[_MT]:76 return self.find_by_col(**{self._pk_column: pk})77 @final78 def find_by_col(self, **kwargs) -> Optional[_MT]:79 query = self._gen_query_for_param(**kwargs)80 return query.one_or_none()81 @final82 def _gen_query_for_param(self, **kwargs) -> Query:83 query = self.session.query(self._model)84 if kwargs:85 for key, value in kwargs.items():86 query = query.filter(getattr(self._model, key) == value)87 return query88 @final89 def find_all(self, **kwargs) -> List[_MT]:90 query = self._gen_query_for_param(**kwargs)91 return query.all()92 @final...
test_tableelementfinder.py
Source: test_tableelementfinder.py
...7 self.ctx.element_finder = mock()8 self.finder = TableElementFinder(self.ctx)9 def tearDown(self):10 unstub()11 def test_find_by_col(self):12 element = mock()13 xpath = ['//tr//*[self::td or self::th][1]']14 when(self.finder)._search_in_locators('id:table', xpath,15 'content').thenReturn(element)16 self.finder.find_by_col('id:table', 1, 'content')17 xpath = ['//tbody/tr/td[position()=last()-(2-1)]',18 '//tbody/tr/td[position()=last()-(2-1)]']19 when(self.finder)._search_in_locators('id:table', xpath,20 'content').thenReturn(element)21 self.finder.find_by_col('id:table', 1, 'content')22 def test_find_by_row(self):23 element = mock()24 xpath = ['//tr[2]//*']25 when(self.finder)._search_in_locators('xpath=//table', xpath,26 'content').thenReturn(element)27 self.finder.find_by_row('xpath=//table', 2, 'content')28 xpath = ['//tbody/tr[position()=last()-(3-1)]']29 when(self.finder)._search_in_locators('xpath=//table', xpath,30 'content').thenReturn(element)31 self.finder.find_by_row('xpath=//table', -3, 'content')32 def test_by_search_in_locators(self):33 xpath = ['//th']34 table = mock()35 element1 = mock()...
Check out the latest blogs from LambdaTest on this topic:
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Building a website is all about keeping the user experience in mind. Ultimately, it’s about providing visitors with a mind-blowing experience so they’ll keep coming back. One way to ensure visitors have a great time on your site is to add some eye-catching text or image animations.
Agile has unquestionable benefits. The mainstream method has assisted numerous businesses in increasing organizational flexibility as a result, developing better, more intuitive software. Distributed development is also an important strategy for software companies. It gives access to global talent, the use of offshore outsourcing to reduce operating costs, and round-the-clock development.
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!