pomcorn 0.8.7__tar.gz → 0.9.0__tar.gz

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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pomcorn
3
- Version: 0.8.7
3
+ Version: 0.9.0
4
4
  Summary: Base implementation of Page Object Model
5
5
  Home-page: https://pypi.org/project/pomcorn/
6
6
  License: MIT
@@ -157,25 +157,41 @@ class XPathLocator(Locator):
157
157
  """
158
158
  return XPathLocator(query=f"({self.query} | {other.query})")
159
159
 
160
- def __getitem__(self, index: int) -> XPathLocator:
161
- """Allow get related xpath locator by index.
160
+ def __getitem__(self, value: int | str | XPathLocator) -> XPathLocator:
161
+ """Allow to set xpath expressions or index into the locator query.
162
162
 
163
- Example:
163
+ Examples:
164
164
  div_locator = XPathLocator("//div") --> `//div`
165
+
166
+ # Indexation
165
167
  div_locator[0] --> `(//div)[1]` # xpath numeration starts with 1
166
168
  div_locator[-1] --> `(//div)[last()]`
167
169
 
170
+ # Attribute condition
171
+ div_locator["@type='black'"] --> `//div[@type='black']
172
+
173
+ # Checking if there are children
174
+ child_locator = XPathLocator("//label").contains("Schedule")
175
+ --> `//label[contains(., 'Star']`
176
+ div_locator[child_locator] --> `//div[//label[contains(., 'Star']]`
177
+
168
178
  """
169
179
  query = f"({self.query})"
170
180
 
171
- if index >= 0:
181
+ if isinstance(value, XPathLocator):
182
+ value = value.query
183
+
184
+ if isinstance(value, str):
185
+ return XPathLocator(f"{query}[{value}]")
186
+
187
+ if value >= 0:
172
188
  # `+1` is used here because numeration in xpath starts with 1
173
- query += f"[{index + 1}]"
174
- elif index == -1:
189
+ query += f"[{value + 1}]"
190
+ elif value == -1:
175
191
  # To avoid ugly locators with `...)[last() - 0]`
176
192
  query += "[last()]"
177
193
  else:
178
- query += f"[last() - {abs(index + 1)}]"
194
+ query += f"[last() - {abs(value + 1)}]"
179
195
 
180
196
  return XPathLocator(query)
181
197
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pomcorn"
3
- version = "0.8.7"
3
+ version = "0.9.0"
4
4
  description = "Base implementation of Page Object Model"
5
5
  authors = [
6
6
  "Saritasa <pypi@saritasa.com>",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes