/
instagramWithBrowserStack.py
executable file
·145 lines (118 loc) · 4.47 KB
/
instagramWithBrowserStack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import subprocess
import json
import sys
userName = sys.argv[3]
accessKey = sys.argv[4]
appPath = sys.argv[5]
uploadApp = subprocess.check_output(['curl', '-s', '-u', userName+':'+accessKey, '-X', 'POST', 'https://api-cloud.browserstack.com/app-automate/upload', '-F', 'file=@'+appPath])
uploadApp = uploadApp.decode('utf-8')
appID = json.loads(uploadApp)
appID = appID["app_url"]
filePath = sys.argv[6]
postVideo = subprocess.check_output(['curl', '-s', '-u', userName+':'+accessKey, '-X', 'POST', 'https://api-cloud.browserstack.com/app-automate/upload-media', '-F', 'file=@'+filePath])
mediaLink = postVideo.decode('utf-8')
res = json.loads(mediaLink)
mediaLink = res["media_url"]
desired_caps = {
"build": "Python Android",
"device": "Google Pixel 3",
"app": appID,
'browserstack.appium_version': '1.9.1',
"browserstack.uploadMedia": [mediaLink]
}
username = sys.argv[1]
password = sys.argv[2]
caption = sys.argv[7]
driver = webdriver.Remote("https://" + userName + ":" + accessKey + "@hub-cloud.browserstack.com/wd/hub", desired_caps)
time.sleep(5)
logInButton = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ID, "com.instagram.android:id/log_in_button"))
)
logInButton.click()
time.sleep(2)
userID = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ID, "com.instagram.android:id/login_username"))
)
userID.send_keys(username)
passwordBox = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ID, "com.instagram.android:id/password"))
)
passwordBox.send_keys(password)
time.sleep(2)
logIn = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ID, "com.instagram.android:id/button_text"))
)
logIn.click()
time.sleep(5)
uploadMedia = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.XPATH, "//android.widget.Button[@content-desc='Camera']"))
)
uploadMedia.click()
time.sleep(3)
storagePermission = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.XPATH, "//android.widget.Button[@text='Allow']"))
)
storagePermission.click()
time.sleep(5)
chooseFile = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.XPATH, "//android.widget.CheckBox[@index='0']"))
)
chooseFile.click()
time.sleep(5)
cropToggle = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Toggle square"))
)
cropToggle.click()
time.sleep(3)
selectMedia = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Next"))
)
selectMedia.click()
time.sleep(3)
nextStep = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Next"))
)
nextStep.click()
time.sleep(2)
captionBox = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ID, "com.instagram.android:id/caption_text_view"))
)
captionBox.send_keys(caption)
time.sleep(5)
share = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ACCESSIBILITY_ID, "Next"))
)
share.click()
time.sleep(60)
goToProfile = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ID, "com.instagram.android:id/profile_tab"))
)
goToProfile.click()
time.sleep(3)
selectRecentPost = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.XPATH, "//androidx.recyclerview.widget.RecyclerView/android.widget.LinearLayout[@index='1']/android.widget.ImageView[@index='0']"))
)
selectRecentPost.click()
time.sleep(3)
moreFeedOptions = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.ID, "com.instagram.android:id/feed_more_button_stub"))
)
moreFeedOptions.click()
time.sleep(3)
copyLink = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((MobileBy.XPATH, "//android.widget.TextView[@text='Copy Link']"))
)
copyLink.click()
time.sleep(15)
postLink = driver.get_clipboard_text()
print("Instagram Link: " + postLink)
appHash = appID.replace("bs://","")
subprocess.call(['curl', '-s', '-u', userName+':'+accessKey, '-X', 'DELETE', 'https://api-cloud.browserstack.com/app-automate/app/delete/'+appHash])
mediaHash = mediaLink.replace("media://","")
subprocess.call(['curl', '-s', '-u', userName+':'+accessKey, '-X', 'DELETE', 'https://api-cloud.browserstack.com/app-automate/custom_media/delete/'+mediaHash])
driver.quit()