pomcorn 0.4.0__py3-none-any.whl → 0.6.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pomcorn might be problematic. Click here for more details.

pomcorn/component.py CHANGED
@@ -1,4 +1,3 @@
1
- import abc
2
1
  from typing import Generic, TypeVar, overload
3
2
 
4
3
  from . import locators
@@ -34,26 +33,28 @@ class ComponentWithBaseLocator(Generic[TPage], Component[TPage]):
34
33
 
35
34
  """
36
35
 
36
+ base_locator: locators.XPathLocator
37
+
37
38
  def __init__(
38
39
  self,
39
40
  page: TPage,
40
- base_locator: locators.XPathLocator,
41
+ base_locator: locators.XPathLocator | None = None,
41
42
  wait_until_visible: bool = True,
42
43
  ):
43
44
  """Initialize component.
44
45
 
45
46
  Args:
46
47
  page: An instance of the page that uses this component.
47
- base_locator: locator: Instance of a class to locate the element in
48
+ base_locator: Instance of a class to locate the element in
48
49
  the browser. Used in relative element initialization methods
49
- and visibility waits.
50
+ and visibility waits. You also can specify it as attribute.
50
51
  wait_until_visible: Whether to wait for the component to become
51
52
  visible before completing initialization or not.
52
53
 
53
54
  """
54
55
  super().__init__(page)
55
- self.base_locator = base_locator
56
- self.body = self.init_element(locator=base_locator)
56
+ self.base_locator = base_locator or self.base_locator
57
+ self.body = self.init_element(locator=self.base_locator)
57
58
 
58
59
  if wait_until_visible:
59
60
  self.wait_until_visible()
@@ -194,14 +195,44 @@ class ListComponent(
194
195
  Waits for `base_item_locator` property to be implemented and value of
195
196
  `item_class` to be set.
196
197
 
198
+ Waits for `base_item_locator` property to be overridden or one of the
199
+ attributes (`item_locator` or `relative_item_locator`) to be specified.
200
+
201
+ The `item_class` attribute is also required.
202
+
197
203
  """
198
204
 
199
205
  item_class: type[ListItemType]
200
206
 
201
- @abc.abstractproperty
207
+ item_locator: locators.XPathLocator | None = None
208
+ relative_item_locator: locators.XPathLocator | None = None
209
+
210
+ @property
202
211
  def base_item_locator(self) -> locators.XPathLocator:
203
- """Get the base locator of list item."""
204
- raise NotImplementedError
212
+ """Get the base locator of list item.
213
+
214
+ Raises:
215
+ ValueError: If both attributes are specified.
216
+ NotImplementedError: If no attribute has been specified,
217
+
218
+ """
219
+ if self.relative_item_locator and self.item_locator:
220
+ raise ValueError(
221
+ "You only need to specify one of the attributes: "
222
+ "`relative_item_locator` - if you want locator nested within "
223
+ "`base_locator`, `item_locator` - otherwise. "
224
+ "Or override `base_item_locator` property.",
225
+ )
226
+ if not self.relative_item_locator:
227
+ if not self.item_locator:
228
+ raise NotImplementedError(
229
+ "You need to specify one of the arguments: "
230
+ "`relative_item_locator` - if you want locator nested "
231
+ "within `base_locator`, `item_locator` - otherwise. "
232
+ "Or override `base_item_locator` property.",
233
+ )
234
+ return self.item_locator
235
+ return self.base_locator // self.relative_item_locator
205
236
 
206
237
  @property
207
238
  def count(self) -> int:
@@ -220,7 +251,7 @@ class ListComponent(
220
251
 
221
252
  items: list[ListItemType] = []
222
253
  for locator in self.iter_locators(self.base_item_locator):
223
- items.append(self.item_class(self.page, locator))
254
+ items.append(self.item_class(page=self.page, base_locator=locator))
224
255
  return items
225
256
 
226
257
  def get_item_by_text(self, text: str) -> ListItemType:
@@ -200,13 +200,18 @@ class ButtonWithTextLocator(ElementWithTextLocator):
200
200
  super().__init__(text=text, element="button", exact=exact)
201
201
 
202
202
 
203
- class InputByLabelLocator(XPathLocator):
203
+ class InputInLabelLocator(XPathLocator):
204
204
  """Locator to looking for input with label by XPath.
205
205
 
206
206
  Specify the query as the string
207
207
  ``//label[contains(., "label")]//input``, where ``label`` is the text of
208
208
  the input label.
209
209
 
210
+ Example:
211
+ <label>Title</label>
212
+ <input value="Value">
213
+ </label>
214
+
210
215
  """
211
216
 
212
217
  def __init__(self, label: str):
@@ -216,6 +221,28 @@ class InputByLabelLocator(XPathLocator):
216
221
  )
217
222
 
218
223
 
224
+ class InputByLabelLocator(XPathLocator):
225
+ """Locator to looking for input next to label by XPath.
226
+
227
+ Specify the query as the string
228
+ ``//label[contains(., "label")]/following-sibling::input``, where ``label``
229
+ is the text of the input label.
230
+
231
+ Example:
232
+ <div>
233
+ <label for="InputWithLabel">Title</label>
234
+ <input id="InputWithLabel" value="Value">
235
+ </div>
236
+
237
+ """
238
+
239
+ def __init__(self, label: str):
240
+ """Init XPathLocator."""
241
+ super().__init__(
242
+ query=f'//label[contains(., "{label}")]/following-sibling::input',
243
+ )
244
+
245
+
219
246
  class TextAreaByLabelLocator(XPathLocator):
220
247
  """Locator to looking for textarea with label by XPath.
221
248
 
pomcorn/page.py CHANGED
@@ -3,7 +3,6 @@ from typing import Self
3
3
  from selenium.common.exceptions import TimeoutException
4
4
  from selenium.webdriver.remote.webdriver import WebDriver
5
5
 
6
- from . import locators
7
6
  from .exceptions import PageDidNotLoadedError
8
7
  from .web_view import WebView
9
8
 
@@ -146,14 +145,19 @@ class Page(WebView):
146
145
  self._get_full_relative_url(self.app_root, relative_url),
147
146
  )
148
147
 
149
- def click_on_page(self):
150
- """Click on page `html` tag.
148
+ def click_on_page(self) -> None:
149
+ """Click on (1, 1) coordinates in the upper left corner of the page.
151
150
 
152
151
  Allows you to move focus away from an element, for example, if it
153
152
  is currently unavailable for interaction.
154
153
 
155
154
  """
156
- self.init_element(locator=locators.TagNameLocator("html")).click()
155
+ from selenium.webdriver.common.action_chains import ActionChains
156
+
157
+ ActionChains(self.webdriver).move_by_offset(
158
+ xoffset=1, # cspell:disable-line
159
+ yoffset=1, # cspell:disable-line
160
+ ).click().perform()
157
161
 
158
162
  @staticmethod
159
163
  def _get_full_relative_url(app_root: str, relative_url: str) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pomcorn
3
- Version: 0.4.0
3
+ Version: 0.6.0
4
4
  Summary: Base implementation of Page Object Model
5
5
  Home-page: https://pypi.org/project/pomcorn/
6
6
  License: MIT
@@ -1,15 +1,15 @@
1
1
  pomcorn/__init__.py,sha256=-0WkJfyev7Onx4Z4BhcWVpZS75GhCLt_oyjHBIjjXC8,362
2
- pomcorn/component.py,sha256=cYpiQ3fKGmGkR9eZ6EZnh-DT2ZytpOjF60QtJFsWIK8,7190
2
+ pomcorn/component.py,sha256=gA9KU2a46o7WYMUvQlG4oGGFN43MDjb1av6I_KK2etQ,8632
3
3
  pomcorn/element.py,sha256=rInhUgDzBr49VSyMsCuxCuSIKA2VIbQnTYOlAevQ5DY,12195
4
4
  pomcorn/exceptions.py,sha256=8ZOmrybDwvEVZRLQzyozjRNhJvSLbablaFwGFUVMhrU,1131
5
5
  pomcorn/locators/__init__.py,sha256=hNSlfmz3y-LI4PXF5VIwX8J5WSalyE2wmzuYc6kNxMA,708
6
6
  pomcorn/locators/base_locators.py,sha256=OegetP1kSzVriLrOj5a_Uu3x9VDXlcgpB9xyO7LW_PA,4432
7
- pomcorn/locators/xpath_locators.py,sha256=SKfRw5D6kOAJx5Hl0yfuInKE-U96AlMbbCtOEQ2KSG4,6507
8
- pomcorn/page.py,sha256=mg4I9rO-7utaWKlLG9ch0KlGNpFqsfSl3EsDijIkIyk,5239
7
+ pomcorn/locators/xpath_locators.py,sha256=mmhNH_S6yUIEuFfSvryY97x-COVrr16cxpxIoae593c,7202
8
+ pomcorn/page.py,sha256=u3DfFdVRxBaXRvFMfrCssr8_ZeA0EJW5UOEjFJjcK4k,5436
9
9
  pomcorn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  pomcorn/waits_conditions.py,sha256=0H2qKCZod8YJC2iTl-urys-A_k0P3zDCenFyUL6hEfw,3493
11
11
  pomcorn/web_view.py,sha256=OenE6H3Vt_1rXt3XHlzdSoNdRV3kkh2O993MO0UJ5c4,14179
12
- pomcorn-0.4.0.dist-info/LICENSE,sha256=1vmhQNp1dDH8ksJ199LuG4oKz5D4ZvNccPcFckiG2S4,1091
13
- pomcorn-0.4.0.dist-info/METADATA,sha256=wZq8n-VHoZlvKsctYJvaRFgwQA5eYwL6yZJcqxfbkHw,6644
14
- pomcorn-0.4.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
15
- pomcorn-0.4.0.dist-info/RECORD,,
12
+ pomcorn-0.6.0.dist-info/LICENSE,sha256=1vmhQNp1dDH8ksJ199LuG4oKz5D4ZvNccPcFckiG2S4,1091
13
+ pomcorn-0.6.0.dist-info/METADATA,sha256=8_OXIUBARDkybQWRzD6U-cAvxcLXTLez5UScKJ5vIwI,6644
14
+ pomcorn-0.6.0.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
15
+ pomcorn-0.6.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.8.1
2
+ Generator: poetry-core 1.7.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any