-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
203 lines (191 loc) · 7.21 KB
/
index.js
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
let puppeteer=require("puppeteer");
const {answer}=require("./code");
let browserStartPromise=puppeteer.launch({
headless:false,
defaultViewport:null,
args:["--start-maximized","--disable-notifications"]
});
let page;
(async function fn() {
try{
let browserObj=await browserStartPromise;
console.log("Browser opened");
page= await browserObj.newPage();
console.log("page opened");
await page.goto("https://www.hackerrank.com/auth/login");
await page.type(".ui-tooltip-wrapper input[type='text']","[email protected]");
await page.type(".ui-tooltip-wrapper input[type='password']","userone");
await page.click(".auth-button span");
console.log("algo clicked");
await waitAndClick("div[data-automation='algorithms']",page);
console.log("warmup clicked");
await waitAndClick("input[value='warmup']",page);
await page.waitFor(1000);
console.log("challenge opened");
let quesArr= await page.$$(".challenge-submit-btn",{delay:100});
console.log("no. of questions",quesArr.length);
for(let i=0;i<quesArr.length-3;i++){
quesArr= await page.$$(".challenge-submit-btn",{delay:100});
await questionSolver(page,quesArr[i],answer[i]);
console.log("question solved");
await page.goBack();
await page.waitFor(3000);
}
}
catch(err){
console.log(err);
}
})();
// browserStartPromise.then(function(browserObj){
// console.log("Browser opened");
// let browserTabOpenPromise=browserObj.newPage();
// return browserTabOpenPromise;
// }).then(function(newTab){
// page=newTab;
// console.log("page opened");
// let hackPageOpenPromise=newTab.goto("https://www.hackerrank.com/auth/login");
// return hackPageOpenPromise;
// })
// .then(function(){
// let usernameTypePromise=page.type(".ui-tooltip-wrapper input[type='text']","[email protected]");
// return usernameTypePromise;
// })
// .then(function(){
// let passwordTypePromise=page.type(".ui-tooltip-wrapper input[type='password']","workerw");
// return passwordTypePromise;
// })
// .then(function(){
// let enterPromise=page.click(".auth-button span");
// return enterPromise;
// })
// .then( function(){
// console.log("algo clicked");
// let algoPromise=waitAndClick("div[data-automation='algorithms']",page);
// return algoPromise;
// } )
// .then(function(){
// console.log("warmup clicked");
// let warmupPromise=waitAndClick("input[value='warmup']",page);
// return warmupPromise;
// })
// .then(function(){
// let waitForPromise=page.waitFor(1000);
// return waitForPromise;
// })
// .then(function(){
// console.log("challenge opened");
// let challengePromise=page.$$(".challenge-submit-btn");
// return challengePromise;
// })
// .then(function(quesArr){
// console.log("no. of questions",quesArr.length);
// let qWillBeSolvedPromise=questionSolver(page,quesArr[0],answer[0]);
// // for(let i=1;i<3;i++){
// // qWillBeSolvedPromise=qWillBeSolvedPromise
// // .then(function (){
// // return questionSolver(page,quesArr[i],answer[i]);
// // })
// // }
// return qWillBeSolvedPromise;
// }).then(function(){
// console.log("question solved");
// })
function questionSolver(page,question,answer){
return new Promise(function(resolve,reject){
(async function fn() {
try{
await question.click();;
await waitAndClick(".monaco-editor,no-user-select.vs",page);
await waitAndClick(".checkbox-input",page);
await page.waitForSelector("textarea.custominput",{visible:true});
await page.type("textarea.custominput",answer,{deial:10});
await page.keyboard.down("Control");
await page.keyboard.press("A",{delay:100});
await page.keyboard.press("X",{delay:100});
await page.keyboard.up("Control");
await waitAndClick(".monaco-editor,no-user-select.vs",page);
await page.keyboard.down("Control");
await page.keyboard.press("A",{delay:100});
await page.keyboard.press("V",{delay:100});
await page.keyboard.up("Control");
await page.click(".ui-btn-secondary.pull-right");
await page.waitFor(10000);
resolve();
}
catch(err){
reject(err);
}
})()
// let qWillBeClickedPromise = question.click();
// //code read
// //hk editor->ctrl A + X
// //code type
// qWillBeClickedPromise
// .then(function(){
// //focus
// let waitForEditorPromise=waitAndClick(".monaco-editor,no-user-select.vs",page);
// return waitForEditorPromise;
// })
// .then(function() {
// return waitAndClick(".checkbox-input",page);
// })
// .then(function() {
// return page.waitForSelector("textarea.custominput",{visible:true});
// })
// .then(function() {
// return page.type("textarea.custominput",answer,{delay:10});
// })
// .then(function() {
// let ctrlIsPressed=page.keyboard.down("Control");
// return ctrlIsPressed;
// }).then(function() {
// let AIsPressed=page.keyboard.press("A",{delay:100});
// return AIsPressed;
// }).then(function() {
// return page.keyboard.press("X",{delay:100});
// }).then(function() {
// let ctrlIsPressed=page.keyboard.up("Control");
// return ctrlIsPressed;
// })
// .then(function(){
// //focus
// let waitForEditorPromise=waitAndClick(".monaco-editor,no-user-select.vs",page);
// return waitForEditorPromise;
// }).then(function() {
// let ctrlIsPressed=page.keyboard.down("Control");
// return ctrlIsPressed;
// }).then(function() {
// let AIsPressed=page.keyboard.press("A",{delay:100});
// return AIsPressed;
// }).then(function() {
// return page.keyboard.press("V",{delay:100});
// }).then(function() {
// let ctrlIsPressed=page.keyboard.up("Control");
// return ctrlIsPressed;
// })
// // .then(function() {
// // console.log("submitted");
// // let submitBtnPromise=waitAndClick("span.ui-text");
// // return submitBtnPromise;
// // })
// .then(function() {
// resolve();
// }).catch(function(err) {
// reject(err);
// })
})
}
function waitAndClick(selector,cPage){
return new Promise(function(resolve,reject){
(async function fn() {
try{
await cPage.waitForSelector(selector,{visible:true});
await cPage.click(selector,{delay:1000});
resolve();
}
catch(err){
reject(err);
}
})();
})
}