Skip to content

Commit fd76a89

Browse files
committed
Organize the project structure
1 parent 942062c commit fd76a89

File tree

7 files changed

+294
-0
lines changed

7 files changed

+294
-0
lines changed

dev-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests
2+
aiohttp

docs/CODE_OF_CONDUCT.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Contributing Guidelines
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, gender identity and expression, level of experience,
9+
education, socio-economic status, nationality, personal appearance, race,
10+
religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at {{ email }}. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+

docs/CONTRIBUTING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
To start to contribute, install the dependencies (Python >= 3.6)
2+
```
3+
python3 -m venv venv
4+
pip install -e .
5+
pip install -r test-requirements.txt
6+
```
7+
Fork this repository, make the changes into the forked repository and push a new Merge Request to 'main' branch.
8+
Open an issue in case of big MRs.
9+
# Testing
10+
To run the tests, start a new Driver as server on port `9999`, for example:
11+
```
12+
./chromedriver --port=9999
13+
```
14+
And execute the tests
15+
```
16+
python -m pytest -n auto
17+
```

samples/sample-appium.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Simple example of usage of caqui with Android App
2+
# It opens the app and get the source code
3+
# Appium configured using docker for simplicity
4+
# https://hub.docker.com/r/appium/appium/
5+
# sample app in ./tests/apk folder
6+
from caqui import synchronous
7+
8+
9+
def main():
10+
driver_url = "http://127.0.0.1:4723"
11+
capabilities = {
12+
"capabilities": {
13+
"firstMatch": [{}],
14+
"alwaysMatch": {
15+
"appium:automationName": "UIAutomator2",
16+
"platformName": "Android",
17+
"appium:udid": "YOUR-APP-UUID", # replace with your device uuid
18+
"appium:app": "/home/androidusr/sample.apk", # refereces the folder in docker container
19+
},
20+
}
21+
}
22+
23+
session = synchronous.get_session(driver_url, capabilities)
24+
print("session: ", session)
25+
26+
source = synchronous.get_page_source(driver_url, session)
27+
print("source: ", source)
28+
29+
synchronous.close_session(driver_url, session)
30+
31+
32+
if __name__ == "__main__":
33+
main()
34+
35+
# output
36+
# python sample-appium.py
37+
# session: 8264988f-2c63-4935-a46f-3aa8ccc09004
38+
# source: <?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
39+
# <hierarchy index="0" class="hierarchy" rotation="0" width="720" height="1472">
40+
# <android.widget.FrameLayout index="0" package="com.example.sample" class="android.widget.FrameLayout" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,0][720,1472]" displayed="true">
41+
# <android.widget.LinearLayout index="0" package="com.example.sample" class="android.widget.LinearLayout" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,0][720,1472]" displayed="true">
42+
# <android.widget.FrameLayout index="0" package="com.example.sample" class="android.widget.FrameLayout" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,0][720,1472]" displayed="true">
43+
# <android.widget.LinearLayout index="0" package="com.example.sample" class="android.widget.LinearLayout" text="" resource-id="com.example.sample:id/action_bar_root" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,0][720,1472]" displayed="true">
44+
# <android.widget.FrameLayout index="0" package="com.example.sample" class="android.widget.FrameLayout" text="" resource-id="android:id/content" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,0][720,1472]" displayed="true">
45+
# <android.view.ViewGroup index="0" package="com.example.sample" class="android.view.ViewGroup" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,0][720,1472]" displayed="true">
46+
# <android.widget.LinearLayout index="0" package="com.example.sample" class="android.widget.LinearLayout" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,0][720,159]" displayed="true">
47+
# <android.view.ViewGroup index="0" package="com.example.sample" class="android.view.ViewGroup" text="" resource-id="com.example.sample:id/toolbar" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,47][720,159]" displayed="true">
48+
# <android.widget.TextView index="0" package="com.example.sample" class="android.widget.TextView" text="First Fragment" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[28,76][282,129]" displayed="true" />
49+
# <androidx.appcompat.widget.LinearLayoutCompat index="1" package="com.example.sample" class="androidx.appcompat.widget.LinearLayoutCompat" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[649,54][720,152]" displayed="true">
50+
# <android.widget.ImageView index="0" package="com.example.sample" class="android.widget.ImageView" text="" content-desc="More options" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" long-clickable="true" password="false" scrollable="false" selected="false" bounds="[649,61][720,145]" displayed="true" />
51+
# </androidx.appcompat.widget.LinearLayoutCompat>
52+
# </android.view.ViewGroup>
53+
# </android.widget.LinearLayout>
54+
# <android.view.ViewGroup index="1" package="com.example.sample" class="android.view.ViewGroup" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,159][720,1472]" displayed="true">
55+
# <android.widget.FrameLayout index="0" package="com.example.sample" class="android.widget.FrameLayout" text="" resource-id="com.example.sample:id/nav_host_fragment_content_main" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,159][720,1472]" displayed="true">
56+
# <android.widget.ScrollView index="0" package="com.example.sample" class="android.widget.ScrollView" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="true" focused="false" long-clickable="false" password="false" scrollable="true" selected="false" bounds="[0,159][720,1472]" displayed="true">
57+
# <android.view.ViewGroup index="0" package="com.example.sample" class="android.view.ViewGroup" text="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[0,159][720,1472]" displayed="true">
58+
# <android.widget.Button index="0" package="com.example.sample" class="android.widget.Button" text="Next" resource-id="com.example.sample:id/button_first" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[283,187][437,271]" displayed="true" />
59+
# <android.widget.TextView index="1" package="com.example.sample" class="android.widget.TextView" text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam in scelerisque sem. Mauris volutpat, dolor id interdum ullamcorper, risus dolor egestas lectus, sit amet mattis purus dui nec risus. Maecenas non sodales nisi, vel dictum dolor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Suspendisse blandit eleifend diam, vel rutrum tellus vulputate quis. Aliquam eget libero aliquet, imperdiet nisl a, ornare ex. Sed rhoncus est ut libero porta lobortis. Fusce in dictum tellus.&#10;&#10; Suspendisse interdum ornare ante. Aliquam nec cursus lorem. Morbi id magna felis. Vivamus egestas, est a condimentum egestas, turpis nisl iaculis ipsum, in dictum tellus dolor sed neque. Morbi tellus erat, dapibus ut sem a, iaculis tincidunt dui. Interdum et malesuada fames ac ante ipsum primis in faucibus. Curabitur et eros porttitor, ultricies urna vitae, molestie nibh. Phasellus at commodo eros, non aliquet metus. Sed maximus nisl nec dolor bibendum, vel congue leo egestas.&#10;&#10; Sed interdum tortor nibh, in sagittis risus mollis quis. Curabitur mi odio, condimentum sit amet auctor at, mollis non turpis. Nullam pretium libero vestibulum, finibus orci vel, molestie quam. Fusce blandit tincidunt nulla, quis sollicitudin libero facilisis et. Integer interdum nunc ligula, et fermentum metus hendrerit id. Vestibulum lectus felis, dictum at lacinia sit amet, tristique id quam. Cras eu consequat dui. Suspendisse sodales nunc ligula, in lobortis sem porta sed. Integer id ultrices magna, in luctus elit. Sed a pellentesque est.&#10;&#10; Aenean nunc velit, lacinia sed dolor sed, ultrices viverra nulla. Etiam a venenatis nibh. Morbi laoreet, tortor sed facilisis varius, nibh orci rhoncus nulla, id elementum leo dui non lorem. Nam mollis ipsum quis auctor varius. Quisque elementum eu libero sed commodo. In eros nisl, imperdiet vel imperdiet et, scelerisque a mauris. Pellentesque varius ex nunc, quis imperdiet eros placerat ac. Duis finibus orci et est auctor tincidunt. Sed non viverra ipsum. Nunc quis augue egestas, cursus lorem at, molestie sem. Morbi a consectetur ipsum, a placerat diam. Etiam vulputate dignissim convallis. Integer faucibus mauris sit amet finibus convallis.&#10;&#10; Phasellus in aliquet mi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. In volutpat arcu ut felis sagittis, in finibus massa gravida. Pellentesque id tellus orci. Integer dictum, lorem sed efficitur ullamcorper, libero justo consectetur ipsum, in mollis nisl ex sed nisl. Donec maximus ullamcorper sodales. Praesent bibendum rhoncus tellus nec feugiat. In a ornare nulla. Donec rhoncus libero vel nunc consequat, quis tincidunt nisl eleifend. Cras bibendum enim a justo luctus vestibulum. Fusce dictum libero quis erat maximus, vitae volutpat diam dignissim." resource-id="com.example.sample:id/textview_first" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[28,299][692,1472]" displayed="true" />
60+
# </android.view.ViewGroup>
61+
# </android.widget.ScrollView>
62+
# </android.widget.FrameLayout>
63+
# </android.view.ViewGroup>
64+
# <android.widget.ImageButton index="2" package="com.example.sample" class="android.widget.ImageButton" text="" resource-id="com.example.sample:id/fab" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[594,1390][692,1472]" displayed="true" />
65+
# </android.view.ViewGroup>
66+
# </android.widget.FrameLayout>
67+
# </android.widget.LinearLayout>
68+
# </android.widget.FrameLayout>
69+
# </android.widget.LinearLayout>
70+
# </android.widget.FrameLayout>
71+
# </hierarchy>

samples/sample-win-app-driver.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Simple example of usage of caqui with Windows Calculator
2+
# It opens the Calculator and clicks the number "8"
3+
# Test works just in Windows environment. Tested with Windows 10
4+
from caqui import synchronous
5+
6+
7+
def main():
8+
driver_url = "http://127.0.0.1:4723"
9+
capabilities = {
10+
"capabilities": {
11+
"firstMatch": [{}],
12+
"alwaysMatch": {},
13+
},
14+
"desiredCapabilities": {
15+
"debugConnectToRunningApp": "false",
16+
"app": "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App",
17+
},
18+
}
19+
session = synchronous.get_session(driver_url, capabilities)
20+
element = synchronous.find_element(
21+
driver_url, session, locator_type="name", locator_value="Eight"
22+
)
23+
24+
synchronous.click(driver_url, session, element)
25+
synchronous.close_session(driver_url, session)
26+
27+
28+
if __name__ == "__main__":
29+
main()

samples/sample-winium.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Simple example of usage of caqui with Windows Calculator
2+
# It opens the Calculator and clicks the number "8"
3+
# Test works just in Windows environment. Tested with Windows 10
4+
from caqui import synchronous
5+
6+
7+
def main():
8+
driver_url = "http://127.0.0.1:9999"
9+
capabilities = {
10+
"capabilities": {"firstMatch": [{}], "alwaysMatch": {}},
11+
"desiredCapabilities": {
12+
"debugConnectToRunningApp": "false",
13+
"app": "C:/windows/system32/calc.exe",
14+
},
15+
}
16+
session = synchronous.get_session(driver_url, capabilities)
17+
element = synchronous.find_element(
18+
driver_url, session, locator_type="name", locator_value="Eight"
19+
)
20+
21+
synchronous.click(driver_url, session, element)
22+
synchronous.close_session(driver_url, session)
23+
24+
25+
if __name__ == "__main__":
26+
main()

samples/sample.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# It opens the WebDriver, navigate to a page and get all links
2+
import asyncio
3+
import time
4+
from caqui import synchronous, asynchronous
5+
from os import getcwd
6+
from tests.constants import PAGE_URL
7+
from caqui.easy.capabilities import CapabilitiesBuilder
8+
9+
BASE_DIR = getcwd()
10+
11+
MAX_CONCURRENCY = 5 # number of webdriver instances running
12+
all_anchors = []
13+
semaphore = asyncio.Semaphore(MAX_CONCURRENCY)
14+
15+
16+
async def get_all_links():
17+
async with semaphore:
18+
driver_url = "http://127.0.0.1:9999"
19+
capabilities = (
20+
CapabilitiesBuilder()
21+
.browser_name("chrome")
22+
.accept_insecure_certs(True)
23+
.page_load_strategy("normal")
24+
.additional_capability(
25+
{"goog:chromeOptions": {"extensions": [], "args": ["--headless"]}}
26+
)
27+
).build()
28+
session = await asynchronous.get_session(driver_url, capabilities)
29+
await asynchronous.go_to_page(
30+
driver_url,
31+
session,
32+
PAGE_URL,
33+
)
34+
35+
all_anchors = []
36+
for i in range(4):
37+
i += 1
38+
locator_value = f"//a[@id='a{i}']"
39+
locator_type = "xpath"
40+
anchors = []
41+
42+
anchors = await asynchronous.find_elements(
43+
driver_url, session, locator_type, locator_value
44+
)
45+
all_anchors.extend(anchors)
46+
47+
texts = []
48+
for anchor in all_anchors:
49+
text = await asynchronous.get_property(driver_url, session, anchor, "href")
50+
texts.append(text)
51+
52+
for text in texts:
53+
print(f"Link found '{text}'")
54+
55+
synchronous.close_session(driver_url, session)
56+
57+
58+
# Reference: https://stackoverflow.com/questions/48483348/how-to-limit-concurrency-with-python-asyncio
59+
async def main():
60+
number_of_websites = range(10)
61+
tasks = [asyncio.ensure_future(get_all_links()) for number in number_of_websites]
62+
await asyncio.gather(*tasks)
63+
64+
65+
if __name__ == "__main__":
66+
start = time.time()
67+
loop = asyncio.get_event_loop()
68+
try:
69+
loop.run_until_complete(main())
70+
finally:
71+
loop.run_until_complete(loop.shutdown_asyncgens())
72+
loop.close()
73+
end = time.time()
74+
print(f"Found 40 links") # 10 websites with 4 links each
75+
print(f"Time: {end-start:.2f} sec")

0 commit comments

Comments
 (0)