diff --git a/API/Activities/CalculatorSOAP.xml b/API/Activities/CalculatorSOAP.xml new file mode 100644 index 0000000000..3bd3c2b84a --- /dev/null +++ b/API/Activities/CalculatorSOAP.xml @@ -0,0 +1,559 @@ + + + + + + + + http://www.dneonline.com/calculator.asmx?WSDL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Adds two integers. This is a test WebService. ©DNE Online + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]]> + http://schemas.xmlsoap.org/wsdl/ + + + + http://www.dneonline.com/calculator.asmx + + + + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + No Authorization + No Authorization + + + + + + + + + + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + No Authorization + No Authorization + + + + + + + + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + No Authorization + No Authorization + + + + + + + + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + No Authorization + No Authorization + + + + + + + + SEQUENTIAL + + + + + + CalculatorSoap12 + Add + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + 10\r + 20\r + \r + \r +]]> + + + + + 200 + + + + + + + + + declare namespace ns1='http://tempuri.org/'; +//ns1:AddResult + 30 + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + CalculatorSoap12 + Divide + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + 30\r + 20\r + \r + \r +]]> + + + + + 200 + + + + + + + + + declare namespace ns1='http://tempuri.org/'; +//ns1:DivideResult + 2 + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + CalculatorSoap12 + Multiply + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + 10\r + 2\r + \r + \r +]]> + + + + + 200 + + + + + + + + + declare namespace ns1='http://tempuri.org/'; +//ns1:MultiplyResult + 20 + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + CalculatorSoap12 + Subtract + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + 30\r + 5\r + \r + \r +]]> + + + + + 200 + + + + + + + + + declare namespace ns1='http://tempuri.org/'; +//ns1:SubtractResult + 25 + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + + + + + + + + + + + + + + + // Sample event script to add custom HTTP header to all outgoing REST, SOAP and HTTP(S) calls +// This code is often used for adding custom authentication to ReadyAPI functional tests + +// If hardcoding the token, uncomment and change line 5 +// token = '4567' + +// If your token is parameterized in Project level custom property, uncomment line 8 +// token = request.parent.testCase.testSuite.project.getProperty('auth_token').getValue() + +// To modify all outgoing calls, remove comments from lines 11 to 16 +// headers = request.requestHeaders +// if (headers.containsKey('auth_token2') == false) { +// headers.put('auth_token2', token) +// request.requestHeaders = headers +// } + + + // Save all test step results into files +// Change the directory path in line 5 to a location where you want to store details +// then uncomment lines 5 to 10 + +// filePath = 'C:\\tempOutputDirectory\\' +// fos = new java.io.FileOutputStream(filePath + testStepResult.testStep.label + '.txt', true) +// pw = new java.io.PrintWriter(fos) +// testStepResult.writeTo(pw) +// pw.close() +// fos.close() + + + + \ No newline at end of file diff --git a/API/Activities/PetstoreREST-readyapi-project.xml b/API/Activities/PetstoreREST-readyapi-project.xml new file mode 100644 index 0000000000..1e80951dae --- /dev/null +++ b/API/Activities/PetstoreREST-readyapi-project.xml @@ -0,0 +1,332 @@ + + + + + + + + https://petstore.swagger.io + + + + + + + + + application/json + + + + application/json + 200 + + pet:Response + + + + https://petstore.swagger.io + + No Authorization + No Authorization + + + + + + + + + + + + + status + sold + QUERY + sold + + + + + + application/json + 200 + + Response + + + + https://petstore.swagger.io + + No Authorization + No Authorization + + + + + + status + + + + + + + + + + + + petId + petId + TEMPLATE + petId + + + + + + application/json + + + + application/json + 200 + + ns:Response + + + + https://petstore.swagger.io + + No Authorization + No Authorization + + + + + + petId + + + + + + + + SEQUENTIAL + + + + + + + + truetruetrue]]> + 1021rockyalive]]> + 1022rexieealive]]> + 1023scoopyalive]]> + true + + + true + true + petid + petname + petstatus + true + false + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + { + "id" : ${DataSource#petid}, + "name" : "${DataSource#petname}", + "status" : "${DataSource#petstatus}" +} + + https://petstore.swagger.io/v2/pet + + + + 200 + + + + + $['name'] + ${DataSource#petname} + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + IdTransfer + Response + POST Request + $['id'] + petId + Delete Request + + JSONPATH + true + + + StatusTransfer + Response + POST Request + $['status'] + status + Get Request + JSONPATH + true + + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + + https://petstore.swagger.io/v2/pet/findByStatus + + + + 200 + + + + + $[*]['name'] + true + false + false + false + + + + No Authorization + No Authorization + + + + + + + status + + + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + + https://petstore.swagger.io/v2/pet/10292 + + + + 200 + + + + No Authorization + No Authorization + + + + + + + petId + + + + + + + + Data Source + POST Request + true + + + + + + + + + + + + + + + + + + + + + // Sample event script to add custom HTTP header to all outgoing REST, SOAP and HTTP(S) calls +// This code is often used for adding custom authentication to ReadyAPI functional tests + +// If hardcoding the token, uncomment and change line 5 +// token = '4567' + +// If your token is parameterized in Project level custom property, uncomment line 8 +// token = request.parent.testCase.testSuite.project.getProperty('auth_token').getValue() + +// To modify all outgoing calls, remove comments from lines 11 to 16 +// headers = request.requestHeaders +// if (headers.containsKey('auth_token2') == false) { +// headers.put('auth_token2', token) +// request.requestHeaders = headers +// } + + + // Save all test step results into files +// Change the directory path in line 5 to a location where you want to store details +// then uncomment lines 5 to 10 + +// filePath = 'C:\\tempOutputDirectory\\' +// fos = new java.io.FileOutputStream(filePath + testStepResult.testStep.label + '.txt', true) +// pw = new java.io.PrintWriter(fos) +// testStepResult.writeTo(pw) +// pw.close() +// fos.close() + + + + \ No newline at end of file diff --git a/API/Activities/Project-1-readyapi-project.xml b/API/Activities/Project-1-readyapi-project.xml new file mode 100644 index 0000000000..e198985568 --- /dev/null +++ b/API/Activities/Project-1-readyapi-project.xml @@ -0,0 +1,559 @@ + + + + + + + + http://www.dneonline.com/calculator.asmx?WSDL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Adds two integers. This is a test WebService. ©DNE Online + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]]> + http://schemas.xmlsoap.org/wsdl/ + + + + http://www.dneonline.com/calculator.asmx + + + + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + No Authorization + No Authorization + + + + + + + + + + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + No Authorization + No Authorization + + + + + + + + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + No Authorization + No Authorization + + + + + + + + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + No Authorization + No Authorization + + + + + + + + SEQUENTIAL + + + + + + CalculatorSoap12 + Add + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + 10\r + 20\r + \r + \r +]]> + + + + + 200 + + + + + + + + + declare namespace ns1='http://tempuri.org/'; +//ns1:AddResult + 30 + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + CalculatorSoap12 + Divide + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + 30\r + 20\r + \r + \r +]]> + + + + + 200 + + + + + + + + + declare namespace ns1='http://tempuri.org/'; +//ns1:DivideResult + 2 + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + CalculatorSoap12 + Multiply + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + 10\r + 2\r + \r + \r +]]> + + + + + 200 + + + + + + + + + declare namespace ns1='http://tempuri.org/'; +//ns1:MultiplyResult + 20 + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + CalculatorSoap12 + Subtract + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + 30\r + 5\r + \r + \r +]]> + + + + + 200 + + + + + + + + + declare namespace ns1='http://tempuri.org/'; +//ns1:SubtractResult + 25 + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + + + + + + + + + + + + + + + // Sample event script to add custom HTTP header to all outgoing REST, SOAP and HTTP(S) calls +// This code is often used for adding custom authentication to ReadyAPI functional tests + +// If hardcoding the token, uncomment and change line 5 +// token = '4567' + +// If your token is parameterized in Project level custom property, uncomment line 8 +// token = request.parent.testCase.testSuite.project.getProperty('auth_token').getValue() + +// To modify all outgoing calls, remove comments from lines 11 to 16 +// headers = request.requestHeaders +// if (headers.containsKey('auth_token2') == false) { +// headers.put('auth_token2', token) +// request.requestHeaders = headers +// } + + + // Save all test step results into files +// Change the directory path in line 5 to a location where you want to store details +// then uncomment lines 5 to 10 + +// filePath = 'C:\\tempOutputDirectory\\' +// fos = new java.io.FileOutputStream(filePath + testStepResult.testStep.label + '.txt', true) +// pw = new java.io.PrintWriter(fos) +// testStepResult.writeTo(pw) +// pw.close() +// fos.close() + + + + diff --git a/API/Activities/REST-Activity1-readyapi-project.xml b/API/Activities/REST-Activity1-readyapi-project.xml new file mode 100644 index 0000000000..85cb716ee3 --- /dev/null +++ b/API/Activities/REST-Activity1-readyapi-project.xml @@ -0,0 +1,473 @@ + + + + + + + + https://petstore.swagger.io + + + + + + + + + application/json + 400 + + user:Fault + + + application/json + + + + application/json + 200 + + user:Response + + + + https://petstore.swagger.io + + No Authorization + No Authorization + + + + + + + + + + + + + username + {username} + QUERY + {username} + + + + + password + {password} + QUERY + {password} + + + + + + application/json + 200 + + log:Response + + + + https://petstore.swagger.io + + No Authorization + No Authorization + + + + + + + username + password + + + + + + + + + + + + username + username + TEMPLATE + username + + + + + + application/json + 404 + + tes:Fault + + + application/xml + 405 + + apiResponse + + + application/json + 200 + + tes:Response + + + + https://petstore.swagger.io + + No Authorization + No Authorization + + + + + + username + + + + + + + + username + username + TEMPLATE + username + + + + + + application/json + + + + application/json + 200 + + tes:Response + + + + 404 + + data + + + application/xml + 405 + + apiResponse + + + + https://petstore.swagger.io + + No Authorization + No Authorization + + + + + + username + + + + + + + + + + + + application/json + 200 + + log:Response + + + + https://petstore.swagger.io + + No Authorization + No Authorization + + + + + + + + + SEQUENTIAL + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + { + "id": 3, + "username": "john29", + "firstName": "John", + "lastName": "Doe", + "email": "john@doe.com", + "password": "testuser", + "phone": "234567890", + "userStatus": 0 +} + https://petstore.swagger.io/v2/user + + + + 200 + + + + No Authorization + No Authorization + + + + + + + + + + + UserName + Response + To create a user + $['username'] + Username + To login + + JSONPATH + true + + + Password + Response + To create a user + $['password'] + password + To login + JSONPATH + true + + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + + https://petstore.swagger.io/v2/user/login + + + + 200 + + + + No Authorization + No Authorization + + + + + + + username + password + + + + + + + + + Username + Response + To create a user + $['username'] + Username + To get user information + + JSONPATH + true + + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + + https://petstore.swagger.io/v2/user/testuser29 + + + + 200 + + + + No Authorization + No Authorization + + + + + + + username + + + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + + https://petstore.swagger.io/v2/user/logout + + + + 200 + + + + No Authorization + No Authorization + + + + + + + + + + + Username + Response + To create a user + $['username'] + Username + To delete a user + + JSONPATH + true + + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + + https://petstore.swagger.io/v2/user/testuser29 + + + + 200 + + + + No Authorization + No Authorization + + + + + + + username + + + + + + + + + + + + + + + + + + + + + + + // Sample event script to add custom HTTP header to all outgoing REST, SOAP and HTTP(S) calls +// This code is often used for adding custom authentication to ReadyAPI functional tests + +// If hardcoding the token, uncomment and change line 5 +// token = '4567' + +// If your token is parameterized in Project level custom property, uncomment line 8 +// token = request.parent.testCase.testSuite.project.getProperty('auth_token').getValue() + +// To modify all outgoing calls, remove comments from lines 11 to 16 +// headers = request.requestHeaders +// if (headers.containsKey('auth_token2') == false) { +// headers.put('auth_token2', token) +// request.requestHeaders = headers +// } + + + // Save all test step results into files +// Change the directory path in line 5 to a location where you want to store details +// then uncomment lines 5 to 10 + +// filePath = 'C:\\tempOutputDirectory\\' +// fos = new java.io.FileOutputStream(filePath + testStepResult.testStep.label + '.txt', true) +// pw = new java.io.PrintWriter(fos) +// testStepResult.writeTo(pw) +// pw.close() +// fos.close() + + + + \ No newline at end of file diff --git a/API/Activities/REST-Activity4-readyapi-project.xml b/API/Activities/REST-Activity4-readyapi-project.xml new file mode 100644 index 0000000000..acc532492b --- /dev/null +++ b/API/Activities/REST-Activity4-readyapi-project.xml @@ -0,0 +1,174 @@ + + + + + + + + http://ipwhois.app + + + + + + + + + IP + IP + TEMPLATE + IP + + + + + + application/json; charset=utf-8 + 200 + + json:Response + + + + 0 + + data + + + + http://ipwhois.app + + No Authorization + No Authorization + + + + + + IP + + + + + + + + SEQUENTIAL + + + + + + + + C:/Users/004PA4744/Desktop/FST/FST_API/Activity4.txt + , + true + Cp1252 + false + + + true + true + IP + Address + true + false + + + + + + + + <xml-fragment/> + + http://ipwhois.app + + http://ipwhois.app/json/ + + + + 200 + + + + + $['country'] + "India" + false + false + false + + + + No Authorization + No Authorization + + + + + + + IP + + + + + + + + Data Source + Request 1 + true + + + + + + + + + + + + + + + + + + + + + // Sample event script to add custom HTTP header to all outgoing REST, SOAP and HTTP(S) calls +// This code is often used for adding custom authentication to ReadyAPI functional tests + +// If hardcoding the token, uncomment and change line 5 +// token = '4567' + +// If your token is parameterized in Project level custom property, uncomment line 8 +// token = request.parent.testCase.testSuite.project.getProperty('auth_token').getValue() + +// To modify all outgoing calls, remove comments from lines 11 to 16 +// headers = request.requestHeaders +// if (headers.containsKey('auth_token2') == false) { +// headers.put('auth_token2', token) +// request.requestHeaders = headers +// } + + + // Save all test step results into files +// Change the directory path in line 5 to a location where you want to store details +// then uncomment lines 5 to 10 + +// filePath = 'C:\\tempOutputDirectory\\' +// fos = new java.io.FileOutputStream(filePath + testStepResult.testStep.label + '.txt', true) +// pw = new java.io.PrintWriter(fos) +// testStepResult.writeTo(pw) +// pw.close() +// fos.close() + + + + \ No newline at end of file diff --git a/API/Activities/REST-Activity5-readyapi-project.xml b/API/Activities/REST-Activity5-readyapi-project.xml new file mode 100644 index 0000000000..4d2922f276 --- /dev/null +++ b/API/Activities/REST-Activity5-readyapi-project.xml @@ -0,0 +1,167 @@ + + + + + + + + http://ipwhois.app + + + + + + + + + IP + IP + TEMPLATE + IP + + + + + + application/json; charset=utf-8 + 200 + + ns:Response + + + + http://ipwhois.app + + No Authorization + No Authorization + + + + + + IP + + + + + + + + SEQUENTIAL + + + + + + + + C:/Users/004PA4744/Desktop/FST/FST_API/Activity5.xlsx + + A2 + false + false + + + false + false + IP Address + true + false + + + + + + + + <xml-fragment/> + + http://ipwhois.app + + http://ipwhois.app/json/164.172.55.44 + + + + 200 + + + + + $['country'] + "Norway" + false + false + false + + + + No Authorization + No Authorization + + + + + + + IP + + + + + + + + DataSource + Request 1 + true + + + + + + + + + + + + + + + + + + + + + // Sample event script to add custom HTTP header to all outgoing REST, SOAP and HTTP(S) calls +// This code is often used for adding custom authentication to ReadyAPI functional tests + +// If hardcoding the token, uncomment and change line 5 +// token = '4567' + +// If your token is parameterized in Project level custom property, uncomment line 8 +// token = request.parent.testCase.testSuite.project.getProperty('auth_token').getValue() + +// To modify all outgoing calls, remove comments from lines 11 to 16 +// headers = request.requestHeaders +// if (headers.containsKey('auth_token2') == false) { +// headers.put('auth_token2', token) +// request.requestHeaders = headers +// } + + + // Save all test step results into files +// Change the directory path in line 5 to a location where you want to store details +// then uncomment lines 5 to 10 + +// filePath = 'C:\\tempOutputDirectory\\' +// fos = new java.io.FileOutputStream(filePath + testStepResult.testStep.label + '.txt', true) +// pw = new java.io.PrintWriter(fos) +// testStepResult.writeTo(pw) +// pw.close() +// fos.close() + + + + \ No newline at end of file diff --git a/API/Activities/REST-Activity6-readyapi-project.xml b/API/Activities/REST-Activity6-readyapi-project.xml new file mode 100644 index 0000000000..6791dc1af9 --- /dev/null +++ b/API/Activities/REST-Activity6-readyapi-project.xml @@ -0,0 +1,263 @@ + + + + + + + + http://ipwhois.app + + + + + + + + + IP + IP + TEMPLATE + IP + + + + + + application/json; charset=utf-8 + 200 + + ns:Response + + + + http://ipwhois.app + + No Authorization + No Authorization + + + + + + IP + + + + + + + + SEQUENTIAL + + + + + + + + 10 + 1 + -1 + COMP + IP + 0 + false + IPv4 + + + + false + false + IP + true + false + + + + + + + + <xml-fragment/> + + http://ipwhois.app + + http://ipwhois.app/json/90.205.25.236 + + + + 200 + + + + + $['city'] + true + false + false + false + + + + No Authorization + No Authorization + + + + + + + IP + + + + + + + + + city + Response + Request 1 + $['city'] + city_name + DataSink + + JSONPATH + true + + + latitude + Response + Request 1 + $['latitude'] + latitude + DataSink + + JSONPATH + true + + + longitude + Response + Request 1 + $['longitude'] + longitude + DataSink + + JSONPATH + true + + + + + + + + + com.mysql.jdbc.Driver + jdbc:mysql://db4free.net:3306/fstm1db?user=fstm1db&password=PASS_VALUE + 6Y6NowPybq + <None> + insert into coordinates(city_name,latitude,longitude) values (?,?,?); + false + + + + + city_name + Kidlington + + + latitude + 51.823398 + + + longitude + -1.290459 + + + + + + + + DataSource + Request 1 + true + + + + + + b4af5b45-902e-4b19-95af-a2b5110ab708 + NONE + + + + 3d88d1ea-8e51-462d-b6d6-17176548d7ae + NONE + + + + b53906d7-dd93-4763-a503-df1a7206b84a + NONE + + + + 730fbb22-77b4-44f3-91ee-d1791a65990d + NONE + + + + 8c2ff09e-9dec-48a2-a70e-ff8f1c0cd2e6 + NONE + + + + + + + + + + + + + + + + + + + // Sample event script to add custom HTTP header to all outgoing REST, SOAP and HTTP(S) calls +// This code is often used for adding custom authentication to ReadyAPI functional tests + +// If hardcoding the token, uncomment and change line 5 +// token = '4567' + +// If your token is parameterized in Project level custom property, uncomment line 8 +// token = request.parent.testCase.testSuite.project.getProperty('auth_token').getValue() + +// To modify all outgoing calls, remove comments from lines 11 to 16 +// headers = request.requestHeaders +// if (headers.containsKey('auth_token2') == false) { +// headers.put('auth_token2', token) +// request.requestHeaders = headers +// } + + + // Save all test step results into files +// Change the directory path in line 5 to a location where you want to store details +// then uncomment lines 5 to 10 + +// filePath = 'C:\\tempOutputDirectory\\' +// fos = new java.io.FileOutputStream(filePath + testStepResult.testStep.label + '.txt', true) +// pw = new java.io.PrintWriter(fos) +// testStepResult.writeTo(pw) +// pw.close() +// fos.close() + + + + \ No newline at end of file diff --git a/API/Project/REST-Project-2-soapui-project.xml b/API/Project/REST-Project-2-soapui-project.xml new file mode 100644 index 0000000000..f1c805298f --- /dev/null +++ b/API/Project/REST-Project-2-soapui-project.xml @@ -0,0 +1,8 @@ + +https://api.github.comkeyIdkeyIdTEMPLATEkeyIdapplication/json; charset=utf-8200api:Responsehttps://api.github.comNo AuthorizationididTEMPLATEid204dataapplication/jsonapplication/json; charset=utf-8404ns:Fault204data204data204data204data204data204data204data<xml-fragment/>https://api.github.comNo Authorizationidapplication/json; charset=utf-8401keys:Faultapplication/jsonapplication/json; charset=utf-8201keys:Response<xml-fragment/>https://api.github.comNo AuthorizationTestSuite generated for REST Service [https://api.github.com]SEQUENTIAL<xml-fragment/>https://api.github.com +{ + "title": "TestKey", + "key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIB59q+e1or+zD83hVJotk6DUnZt9lXbWkjnYQyyI8bW" +} + +https://api.github.com/user/keys201No AuthorizationNo AuthorizationidResponsePOST Request$['id']idDelete RequestJSONPATHJSONPATHtruekeyResponsePOST Request$['key']keyIdGET RequestJSONPATHJSONPATHtrue<xml-fragment/>https://api.github.comhttps://api.github.com/200No Authorization<xml-fragment/>https://api.github.comhttps://api.github.com/user/keys/133432776204No AuthorizationNo AuthorizationidGitHub Token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HEADERAUTHORIZATION_CODE_GRANTAUTOMATICENTERED_MANUALLYENTERED_MANUALLY \ No newline at end of file diff --git a/API/Project/RestAssuredProject.java b/API/Project/RestAssuredProject.java new file mode 100644 index 0000000000..c062e31474 --- /dev/null +++ b/API/Project/RestAssuredProject.java @@ -0,0 +1,80 @@ +package Project; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.lessThanOrEqualTo; + +import java.util.HashMap; +import java.util.Map; + +import org.hamcrest.Matchers; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.restassured.builder.RequestSpecBuilder; +import io.restassured.builder.ResponseSpecBuilder; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; +import io.restassured.specification.ResponseSpecification; + +public class RestAssuredProject { + // Declare Request and Response specifications objects + + RequestSpecification RequestSpec; + ResponseSpecification ResponseSpec; + int keyId; + String sshKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIB59q+e1or+zD83hVJotk6DUnZt9lXbWkjnYQyyI8bW"; + + @BeforeClass + public void setUp() { + // Create request specification + RequestSpec = new RequestSpecBuilder(). + setBaseUri("https://api.github.com/user/keys"). + addHeader("Content-Type","application/json"). + addHeader("Authorization", "Bearer ...."). + addHeader("X-GitHub-Api-Version", "2022-11-28"). + build(); + + // Create a response Specification + ResponseSpec = new ResponseSpecBuilder(). + expectBody("title",Matchers.equalTo("TestAPIKey")). + expectBody("key", Matchers.equalTo(sshKey)). + expectResponseTime(lessThanOrEqualTo(5000L)). + build(); + } + + @Test(priority = 1) + //POST + public void postRequestTest() { + Map reqBody = new HashMap<>(); + reqBody.put("title", "TestAPIKey"); + reqBody.put("key", sshKey); + // Send request and save the response + Response response = given().spec(RequestSpec).body(reqBody). + when().post(); + // Extract PetId from the response + this.keyId = response.then().extract().path("id"); + // Assertions + response.then().spec(ResponseSpec); + + } + //GET + @Test(priority = 2) + public void getRequestTest() { + // Send request, get request, Assert + given().spec(RequestSpec).pathParam("keyId",this.keyId). + when().get("/{keyId}"). + then().spec(ResponseSpec).body("title",equalTo("TestAPIKey")); + + } + //DELETE + @Test(priority = 3) + public void deleteRequestTest() { + // Send request, get request, Assert + given().spec(RequestSpec).pathParam("KeyId",this.keyId). + // log().all(). --> this prints all the values + when().delete("/{KeyId}"). + then().statusCode(204); + + } +} diff --git a/Cucumber/Activities/Activity1.feature b/Cucumber/Activities/Activity1.feature new file mode 100644 index 0000000000..a021f3fc8e --- /dev/null +++ b/Cucumber/Activities/Activity1.feature @@ -0,0 +1,8 @@ +@Activity1 +Feature: Basic Syntax + +Scenario: test the TSO home page + Given the user is on TS homepage + When they click on the about us link + Then they are redirected to the about us page + \ No newline at end of file diff --git a/Cucumber/Activities/Activity2.feature b/Cucumber/Activities/Activity2.feature new file mode 100644 index 0000000000..f70490d686 --- /dev/null +++ b/Cucumber/Activities/Activity2.feature @@ -0,0 +1,8 @@ +@Activity2 +Feature: Activity to test the login feature + +Scenario: Successful login + Given the user is on the login page + When the user enters username and password + And clicks the submit button + Then get the confirmation message and verify it \ No newline at end of file diff --git a/Cucumber/Activities/Activity3.feature b/Cucumber/Activities/Activity3.feature new file mode 100644 index 0000000000..704cc54fc5 --- /dev/null +++ b/Cucumber/Activities/Activity3.feature @@ -0,0 +1,30 @@ +@Activity3 +Feature: Testing with Tags + + @SimpleAlert @SmokeTest + Scenario: Test for Simple Alert + Given User is on the page + When User clicks the Simple Alert button + Then Alert opens + And Read the text from it and print it + And Close the alert + And Read the result text + + @ConfirmAlert + Scenario: Test for Confirm Alert + Given User is on the page + When User clicks the Confirmation Alert button + Then Alert opens + And Read the text from it and print it + And Close the alert with Cancel + And Read the result text + + @PromptAlert + Scenario: Test for Prompt Alert + Given User is on the page + When User clicks the Prompt Alert button + Then Alert opens + And Read the text from it and print it + And Write a custom message in it + And Close the alert + And Read the result text \ No newline at end of file diff --git a/Cucumber/Activities/Activity4.feature b/Cucumber/Activities/Activity4.feature new file mode 100644 index 0000000000..e724f90588 --- /dev/null +++ b/Cucumber/Activities/Activity4.feature @@ -0,0 +1,8 @@ +@Activity4 +Feature: Data driven test without Examples + + Scenario: Testing with correct data from inputs + Given the user is on the login page + When the user enters "admin" and "password" + And clicks the submit button + Then get the confirmation text and verify message as "Welcome Back, Admin!" \ No newline at end of file diff --git a/Cucumber/Activities/Activity5.feature b/Cucumber/Activities/Activity5.feature new file mode 100644 index 0000000000..22f75d5e6c --- /dev/null +++ b/Cucumber/Activities/Activity5.feature @@ -0,0 +1,14 @@ +@Activity5 +Feature: Data driven test with Examples + + Scenario Outline: Testing with Data from Scenario + Given the user is on the login page + When the user enters "" and "" + And clicks the submit button + Then get the confirmation text and verify message as "Invalid credentials" + + Examples: + | Usernames | Passwords | + | admin | password123 | + | admin | wrongPassword | + | admin | password | \ No newline at end of file diff --git a/Cucumber/Activities/Activity6.feature b/Cucumber/Activities/Activity6.feature new file mode 100644 index 0000000000..bde39784d3 --- /dev/null +++ b/Cucumber/Activities/Activity6.feature @@ -0,0 +1,10 @@ +@Activity6 +Feature: To test input with Datatables + +Scenario: Adding items to a to-do list + Given user is on the To-Do list page + When user adds the following tasks + | task1 | + | task2 | + | task3 | + Then they can see the task added to the list \ No newline at end of file diff --git a/Cucumber/Activities/AlertSteps.java b/Cucumber/Activities/AlertSteps.java new file mode 100644 index 0000000000..c0a13a6ddb --- /dev/null +++ b/Cucumber/Activities/AlertSteps.java @@ -0,0 +1,64 @@ +package StepDefination; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; + +import io.cucumber.java.en.And; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class AlertSteps extends BaseClass { + Alert alert; + @Given("User is on the page") + public void openPage() { + // Open browser + driver.get("https://training-support.net/webelements/alerts"); + } + @When("User clicks the Simple Alert button") + public void openSimpleAlert() { + driver.findElement(By.id("simple")).click(); + } + + @When("User clicks the Confirmation Alert button") + public void openConfirmAlert() { + driver.findElement(By.id("confirmation")).click(); + } + + @When("User clicks the Prompt Alert button") + public void openPromptAlert() { + driver.findElement(By.id("prompt")).click(); + } + + @Then("Alert opens") + public void switchFocus() { + alert = driver.switchTo().alert(); + } + + @And("Read the text from it and print it") + public void readAlert() { + System.out.println("Alert says: " + alert.getText()); + } + + @And("Write a custom message in it") + public void writeToPrompt() { + alert.sendKeys("Custom Message"); + } + + @And("Close the alert") + public void closeAlert() { + alert.accept(); + } + + @And("Close the alert with Cancel") + public void closeAlertWithCAncel() { + alert.dismiss(); + } + + @And("Read the result text") + public void readResultText() { + String message = driver.findElement(By.id("result")).getText(); + System.out.println("Action performed: " + message); + } + +} diff --git a/Cucumber/Activities/BaseClass.java b/Cucumber/Activities/BaseClass.java new file mode 100644 index 0000000000..6f9c07d0b2 --- /dev/null +++ b/Cucumber/Activities/BaseClass.java @@ -0,0 +1,10 @@ +package StepDefination; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class BaseClass { + + static WebDriver driver; + static WebDriverWait wait; +} diff --git a/Cucumber/Activities/DataTableExample.java b/Cucumber/Activities/DataTableExample.java new file mode 100644 index 0000000000..d553c485ba --- /dev/null +++ b/Cucumber/Activities/DataTableExample.java @@ -0,0 +1,35 @@ +package StepDefination; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.List; +import io.cucumber.datatable.DataTable; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import org.openqa.selenium.By; + +public class DataTableExample extends BaseClass { + + @Given("user is on the To-Do list page") + public void openPage() { + driver.get("https://training-support.net/webelements/todo-list"); + assertEquals(driver.getTitle(), "Selenium: To-Do List"); + } + + @When("user adds the following tasks") + public void inputTasks(DataTable inputTasks) throws InterruptedException { + List tasks = inputTasks.asList(); + System.out.println(tasks); + + for(String task : tasks) { + driver.findElement(By.id("todo-input")).sendKeys(task); + driver.findElement(By.id("todo-add")).click(); + Thread.sleep(2000); + } + } + + @Then("they can see the task added to the list") + public void verifyResults() { + System.out.println("All tasks present"); + } +} diff --git a/Cucumber/Activities/Fixtures.java b/Cucumber/Activities/Fixtures.java new file mode 100644 index 0000000000..c97be23b36 --- /dev/null +++ b/Cucumber/Activities/Fixtures.java @@ -0,0 +1,24 @@ +package StepDefination; + +import java.time.Duration; + +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; + +import io.cucumber.java.AfterAll; +import io.cucumber.java.BeforeAll; + +public class Fixtures extends BaseClass { + @BeforeAll + public static void setUp() { + // Initialize Firefox Driver + driver = new FirefoxDriver(); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + } + + @AfterAll + public static void tearDown() { + // Close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/LoginSteps.java b/Cucumber/Activities/LoginSteps.java new file mode 100644 index 0000000000..4106c20e72 --- /dev/null +++ b/Cucumber/Activities/LoginSteps.java @@ -0,0 +1,71 @@ +package StepDefination; + +import org.junit.jupiter.api.Assertions; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import io.cucumber.java.en.And; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class LoginSteps extends BaseClass { + @Given("the user is on the login page") + public void openPage() { + // Open the login page + driver.get("https://training-support.net/webelements/login-form"); + // Assert page title + Assertions.assertEquals("Selenium: Login Form", driver.getTitle()); + } + + @When("the user enters username and password") + public void enterCredentials() { + // Find username field and enter username + driver.findElement(By.id("username")).sendKeys("admin"); + // Find password field and enter password + driver.findElement(By.id("password")).sendKeys("password"); + } + + @When("the user enters {string} and {string}") + public void enterCredentialsFromInputs(String username, String password) { + // Find the input fields + WebElement usernameField = driver.findElement(By.id("username")); + WebElement passwordField = driver.findElement(By.id("password")); + // Clear the fields + usernameField.clear(); + passwordField.clear(); + // Find username field and enter username + usernameField.sendKeys(username); + // Find password field and enter password + passwordField.sendKeys(password); + } + + @And("clicks the submit button") + public void clickSubmit() { + // Find the submit button and click it + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + } + + @Then("get the confirmation message and verify it") + public void confirmMessage() { + // Find the confirmation message + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.cssSelector("h2.mt-5"), "Welcome")); + String message = driver.findElement(By.cssSelector("h2.mt-5")).getText(); + // Assert message + Assertions.assertEquals("Welcome Back, Admin!", message); + } + + @Then("get the confirmation text and verify message as {string}") + public void confirmMessageAsInput(String expectedMessage) { + // Find the message + String message = "NOT FOUND"; + if (expectedMessage.contains("Invalid")) { + message = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("h2#subheading"))).getText(); + } else { + message = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("h2.mt-5"))).getText(); + } + // Assert message + Assertions.assertEquals(expectedMessage, message); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/TSHomePageSteps.java b/Cucumber/Activities/TSHomePageSteps.java new file mode 100644 index 0000000000..09a6fca5e1 --- /dev/null +++ b/Cucumber/Activities/TSHomePageSteps.java @@ -0,0 +1,33 @@ +package StepDefination; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class TSHomePageSteps extends BaseClass { + @Given("the user is on TS homepage") + public void openTSHomepage() throws Throwable{ + // Open the browser + driver.get("https://training-support.net"); + assertEquals(driver.getTitle(), "Training Support"); + } + + @When("they click on the about us link") + public void clickButton() throws Throwable { + driver.findElement(By.linkText("About Us")).click(); + } + + @Then("they are redirected to the about us page") + public void aboutUsPage() throws Throwable { + wait.until(ExpectedConditions.titleIs("About Training Support")); + String pageHeading = driver.findElement(By.cssSelector("h1.text-center")).getText(); + + System.out.println("New page title is: " + pageHeading); + assertEquals(pageHeading, "About Us"); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/TestRunner.java b/Cucumber/Activities/TestRunner.java new file mode 100644 index 0000000000..906aa2c25f --- /dev/null +++ b/Cucumber/Activities/TestRunner.java @@ -0,0 +1,28 @@ +package TestRunner; +import org.junit.platform.suite.api.Suite; +import org.junit.platform.suite.api.IncludeEngines; +import org.junit.platform.suite.api.ConfigurationParameter; +import org.junit.platform.suite.api.SelectClasspathResource; + +import io.cucumber.junit.platform.engine.Constants; + +@Suite +@IncludeEngines("cucumber") +@SelectClasspathResource("Features") +@ConfigurationParameter( + key = Constants.GLUE_PROPERTY_NAME, + value = "StepDefination") +@ConfigurationParameter( + key = Constants.FILTER_TAGS_PROPERTY_NAME, + value = "@Activity3") +@ConfigurationParameter( + key = Constants.PLUGIN_PROPERTY_NAME, + value = "pretty, html:Reports/HTML_Report.html, junit:Reports/XML_Report.xml, json:Reports/JSON_Report.json" + ) +@ConfigurationParameter( + key = Constants.PLUGIN_PUBLISH_ENABLED_PROPERTY_NAME, + value = "true" + ) +public class TestRunner { + +} diff --git a/Java/Activities/Activity1.java b/Java/Activities/Activity1.java new file mode 100644 index 0000000000..b103304155 --- /dev/null +++ b/Java/Activities/Activity1.java @@ -0,0 +1,18 @@ +package activities; + +public class Activity1 { + public static void main(String[] args) { + + Car carName = new Car(); + carName.make = 2014; + carName.color = "Black"; + carName.transmission = "Manual"; + + carName.displayCharacteristics(); + carName.accelarate(); + carName.brake(); + + + } + +} diff --git a/Java/Activities/Activity10.java b/Java/Activities/Activity10.java new file mode 100644 index 0000000000..0e34b7a0fa --- /dev/null +++ b/Java/Activities/Activity10.java @@ -0,0 +1,50 @@ +package activities; + +import java.util.HashSet; +import java.util.Set; + +public class Activity10 { + public static void main(String[] args) + { + Set numSet = new HashSet<>(); // HashSet wont store the order which we given thats why we will get output in different order + + numSet.add(100); // object - will store both the integer and Strings + numSet.add(12145); + numSet.add(12467); + numSet.add(86432); + numSet.add(34532); + numSet.add("Rupesh"); + + // to print all the values + for(Object num : numSet) + { + System.out.println(num); + } + + // Size of set + System.out.println("Size of Set is: "+ numSet.size()); + + // remove value --> here it will remove value directly because we won't have index + numSet.remove(12145); + + System.out.println("Size of Set after removing value is: "+ numSet.size()); + + //contain - searching the values + System.out.println("does have present: "+ numSet.contains(1001)); + + // print values without loop + System.out.println(numSet); + + // to replace the value +// "Rupesh".replace("h", "H"); +// System.out.println(numSet); +// //numSet.replace("Rupesh","Harish"); + + // clear all the values in Set + numSet.clear(); + System.out.println(numSet); + + + } + +} diff --git a/Java/Activities/Activity11.java b/Java/Activities/Activity11.java new file mode 100644 index 0000000000..fd273d1b4f --- /dev/null +++ b/Java/Activities/Activity11.java @@ -0,0 +1,40 @@ +package activities; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +public class Activity11 { + public static void main(String[] args) { + Map colour = new HashMap<>(); + + colour.put(100, "Red"); + colour.put(101, "Green"); + colour.put(102, "Yellow"); + colour.put(103, "White"); + colour.put(104, "Black"); + + for(Entry item : colour.entrySet()) + { + System.out.println(item.getKey() + ": "+ item.getValue()); + } + // to get the only keys + for(int key: colour.keySet()) + { + System.out.println(key); // this will give key + //System.out.println(colour.get(key)); // this will give value of that key + } + + // to remove the key + colour.remove(100); + + // to check the value is present or not + + System.out.println("value present or not: "+ colour.containsValue("Red")); + + // Size of map + System.out.println("Size of map is: "+ colour.size()); + + + } +} diff --git a/Java/Activities/Activity12.java b/Java/Activities/Activity12.java new file mode 100644 index 0000000000..bbcacfcd48 --- /dev/null +++ b/Java/Activities/Activity12.java @@ -0,0 +1,23 @@ +package activities; + +interface Addable { + + int add(int a, int b); +} +public class Activity12 { + public static void main(String[] args) { + + // Lambda function with out data type + Addable add1 = (a,b) -> (a+b); + System.out.println("Add1 value is : "+ add1.add(5,8)); + + // Lambda function with data type + Addable add2 = (int a, int b) -> { + return (a+b); + }; + System.out.println("Add2 value is :" +add2.add(3, 6)); + + + } + +} diff --git a/Java/Activities/Activity13.java b/Java/Activities/Activity13.java new file mode 100644 index 0000000000..2e69f97f3f --- /dev/null +++ b/Java/Activities/Activity13.java @@ -0,0 +1,33 @@ +package activities; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.Scanner; + +public class Activity13 { + public static void main(String[] args) { + + //Creating an integer list + List intList = new ArrayList<>(); + + System.out.println("Enter the values into the list"); + // to pass the inputs dynamically + Scanner scan = new Scanner(System.in); + + // Generating random values we use this Random() + Random rand = new Random(); + + while(scan.hasNextInt()) { // It takes the inputs until character is passed in console + intList.add(scan.nextInt()); // Here entered values are stores in List + } + System.out.println("List of values: "+ intList); + + //int getIndex = rand.nextInt(intList.size()-1); // this is give random index every time we run the program + int getIndex = intList.size()-1; // this is to get the original size of array + + System.out.println("Index value is: "+ getIndex); + + System.out.println("Value at index is : "+ intList.get(getIndex)); + } +} diff --git a/Java/Activities/Activity14.java b/Java/Activities/Activity14.java new file mode 100644 index 0000000000..b75dee6f47 --- /dev/null +++ b/Java/Activities/Activity14.java @@ -0,0 +1,49 @@ +package activities; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; + +import org.apache.commons.io.FileUtils; + +public class Activity14 { + public static void main(String[] args) throws IOException { + try { + // File file = new File("src/main/resources/newfile.txt"); + + // System path + + File file = new File("C:\\Users\\004PA4744\\Desktop\\Java Course\\newfile.txt"); + + boolean fStatus = file.createNewFile(); + + if(fStatus) + { + System.out.println("File created successfully!"); + FileUtils.writeStringToFile(file, "Hello!! \nThis is Rupesh \nBye!", Charset.defaultCharset()); + } + else + { + System.out.println("File already exists at this path."); + } + + // Read file + System.out.println("Data in file: " + FileUtils.readFileToString(file, "UTF8")); + + // Create directory + File destDir = new File("src/main/resources/destDir"); + // Copy file to directory + FileUtils.copyFileToDirectory(file, destDir); + + // Get file from new directory + File newFile = FileUtils.getFile(destDir, "newfile.txt"); + // Read data from file + String newFileData = FileUtils.readFileToString(newFile, "UTF8"); + // Print it + System.out.println("Data in new file: " + newFileData); + + } catch(IOException errMessage) { + System.out.println(errMessage); + } + } +} diff --git a/Java/Activities/Activity2.java b/Java/Activities/Activity2.java new file mode 100644 index 0000000000..825f63953a --- /dev/null +++ b/Java/Activities/Activity2.java @@ -0,0 +1,29 @@ +package activities; + +public class Activity2 { + public static void main(String[] args) { + + int[] numArr = {10, 77, 10, 54, -11, 10}; + + int searchNum = 10; + int fixedSum = 30; + + System.out.println("Result: " + result(numArr, searchNum, fixedSum)); + } + + public static boolean result(int[] numbers, int searchNum, int fixedSum) { + int temp_sum = 0; + for (int number : numbers) { + // for(int i=0; i fixedSum) { + break; + } + } + + return temp_sum == fixedSum; + } +} \ No newline at end of file diff --git a/Java/Activities/Activity3.java b/Java/Activities/Activity3.java new file mode 100644 index 0000000000..b66a2d7abb --- /dev/null +++ b/Java/Activities/Activity3.java @@ -0,0 +1,53 @@ +package activities; + +class conv +{ + public void getResult(String name,double result) + { + System.out.println(String.format(name +"%.2f",result)+" Earth Years old"); + } +} +public class Activity3 { + public static void main(String[] args) { + double seconds = 1000000000; + double result; + + double EarthSeconds = 31557600; + double MercurySeconds = 0.2408467; + double VenusSeconds = 0.61519726; + double MarsSeconds = 1.8808158; + double JupiterSeconds = 11.862615; + double SaturnSeconds = 29.447498; + double UranusSeconds = 84.016846; + double NeptuneSeconds = 164.79132; + + conv obj = new conv(); + result = (seconds / EarthSeconds / MercurySeconds); + obj.getResult("Age on Mercury: ",result); + + result= (seconds / EarthSeconds / VenusSeconds); + obj.getResult("Age on Venus: ",result); + + result=(seconds / EarthSeconds); + obj.getResult("Age on Earth: ",result); + + result=(seconds / EarthSeconds / MarsSeconds); + obj.getResult("Age on Mars: ",result); + + result=(seconds / EarthSeconds / JupiterSeconds); + obj.getResult("Age on Jupiter: ",result); + + result= (seconds / EarthSeconds / SaturnSeconds); + obj.getResult("Age on Saturn: ",result); + + result= (seconds / EarthSeconds / UranusSeconds); + obj.getResult("Age on Uranus: ",result); + + result= (seconds / EarthSeconds / NeptuneSeconds); + obj.getResult("Age on Neptune: ",result); + + + } + +} + diff --git a/Java/Activities/Activity4.java b/Java/Activities/Activity4.java new file mode 100644 index 0000000000..7210d76ce9 --- /dev/null +++ b/Java/Activities/Activity4.java @@ -0,0 +1,30 @@ +package activities; +import java.util.Arrays; + +public class Activity4 { + + static void ascendingSort(int array[]) { + System.out.println("Before sorting the array : "); + System.out.println(Arrays.toString(array)); + + for (int i = 1; i < array.length; i++) { + int key = array[i]; + int j = i - 1; + + while (j >= 0 && key < array[j]) { + array[j + 1] = array[j]; + --j; + } + array[j + 1] = key; + } + } + + public static void main(String args[]) { + int[] data = { 9, 5, 1, 4, 3 }; + ascendingSort(data); + + System.out.println("After Sorting the array in Ascending order: "); + // System.out.println(data); + System.out.println(Arrays.toString(data)); + } +} diff --git a/Java/Activities/Activity5.java b/Java/Activities/Activity5.java new file mode 100644 index 0000000000..261111251c --- /dev/null +++ b/Java/Activities/Activity5.java @@ -0,0 +1,33 @@ +package activities; + +abstract class Book +{ + String title; + +// public void setTitle(String str) +// { +// title =str; +// } + public String getTitle() + { + return title; + } +} + +class MyBook extends Book +{ + public void setTitle(String str) + { + title =str; + } +} +public class Activity5 { + public static void main(String [] arr) + { + MyBook obj = new MyBook(); + obj.setTitle("Hover Car Racer"); + + System.out.println("The Title is : "+ obj.title); + } + +} diff --git a/Java/Activities/Activity6.java b/Java/Activities/Activity6.java new file mode 100644 index 0000000000..09f859b42e --- /dev/null +++ b/Java/Activities/Activity6.java @@ -0,0 +1,66 @@ +package activities; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +class Plane { + private List passengers; + private int maxPassengers; + private Date lastTimeTookOf; + private Date lastTimeLanded; + + public Plane(int maxPassengers) { + this.maxPassengers = maxPassengers; + this.passengers = new ArrayList<>(); // creating array with in the given range(<>) + } + + public void onboard(String passengerName) { + if(passengers.size() <= maxPassengers) { + this.passengers.add(passengerName); // adding elements into array + } else { + System.out.println("Plane is full"); + } + } + + public Date takeOff() { + this.lastTimeTookOf = new Date(); // getting date from system + return lastTimeTookOf; + } + + public void land() { + this.lastTimeLanded = new Date(); + this.passengers.clear(); // here we are clearing the data in array + } + + public Date getLastTimeLanded() { + return lastTimeLanded; + } + + public List getPassengers() { // List --> [] output + return passengers; // Since passengers is array we have to declare List + } +} + +public class Activity6 { + + public static void main(String[] args) throws InterruptedException { + //There is a plane with max 10 passengers + Plane plane = new Plane(10); + //Add passengers on the list + plane.onboard("John"); + plane.onboard("Steve"); + plane.onboard("Anna"); + //Plane takes off + System.out.println("Plane took off at: " + plane.takeOff()); + //Print list of people on board + System.out.println("People on the plane: " + plane.getPassengers()); + //Flying..... + Thread.sleep(5000); + //Plane has landed + plane.land(); + //Plane lands + System.out.println("Plane landed at: " + plane.getLastTimeLanded()); + System.out.println("People on the plane after landing: " + plane.getPassengers()); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity7.java b/Java/Activities/Activity7.java new file mode 100644 index 0000000000..7abb76c843 --- /dev/null +++ b/Java/Activities/Activity7.java @@ -0,0 +1,71 @@ +package activities; + +interface BicycleParts { + public int tyres = 2; + public int maxSpeed = 25; +} + +interface BicycleOperations { + public void applyBrake(int decrement); + public void speedUp(int increment); +} + +//Base class +class Bicycle implements BicycleParts, BicycleOperations { + + public int gears; + public int currentSpeed; + + //the Bicycle class has one constructor + public Bicycle(int gears, int currentSpeed) { + this.gears = gears; + this.currentSpeed = currentSpeed; + } + + //Bicycle class has three methods + public void applyBrake(int decrement) { + currentSpeed -= decrement; + System.out.println("Current speed: " + currentSpeed); + } + + public void speedUp(int increment) { + currentSpeed += increment; + System.out.println("Current speed: " + currentSpeed); + } + + //Method to print info of Bicycle + public String bicycleDesc() { + return("No of gears are "+ gears + "\nSpeed of bicycle is " + maxSpeed); + } +} + +//Derived class +class MountainBike extends Bicycle { + + //The MountainBike subclass adds one more field + public int seatHeight; + + //The MountainBike subclass has one constructor + public MountainBike(int gears, int currentSpeed, int startHeight) { + //Invoking base-class(Bicycle) constructor + super(gears, currentSpeed); + seatHeight = startHeight; + } + + // the MountainBike subclass adds one more method + public void setHeight(int newValue) { + seatHeight = newValue; + } + + public String bicycleDesc() { + return (super.bicycleDesc()+ "\nSeat height is " + seatHeight); + } +} +public class Activity7 { + public static void main(String args[]) { + MountainBike mb = new MountainBike(3, 0, 25); + System.out.println(mb.bicycleDesc()); + mb.speedUp(20); + mb.applyBrake(5); + } +} diff --git a/Java/Activities/Activity8.java b/Java/Activities/Activity8.java new file mode 100644 index 0000000000..220958fad4 --- /dev/null +++ b/Java/Activities/Activity8.java @@ -0,0 +1,39 @@ +package activities; + +class CustomException extends Exception +{ + private String message = null; + + public void CustomException(String message) + { + this.message = message; + } + public String getMessage() + { + return message; + } +} +public class Activity8 { + public static void main(String[] args) + { + CustomException obj = new CustomException(); + obj.CustomException(null); + // System.out.println(obj.getMessage()); + String str = obj.getMessage(); + if (str == null) + { + System.out.println("String value is Null"); + } + else + System.out.println(str); + } +// static void exceptionTest(String str) throws CustomException +// { +// if (str == null) +// { +// System.out.println("String value is Null"); +// } +// else +// System.out.println(str); +// } +} diff --git a/Java/Activities/Activity9.java b/Java/Activities/Activity9.java new file mode 100644 index 0000000000..c91310461d --- /dev/null +++ b/Java/Activities/Activity9.java @@ -0,0 +1,33 @@ +package activities; + +import java.util.ArrayList; +import java.util.List; + +public class Activity9 { + public static void main(String[] args) + { + List strList = new ArrayList<>(); + + strList.add("Apple"); + strList.add(0,"Mango"); + strList.add(1,"pineapple"); + strList.add("Papaya"); + strList.add("Mango"); + + for(String name : strList) + { + System.out.println(name); + + } + System.out.println("3rd value is: "+ strList.get(2)); + System.out.println("does Mango exists:" + strList.contains("Mango")); + System.out.println("Size of list :"+ strList.size()); + strList.remove("Mango"); + System.out.println("After remove Mango Size of list is :"+ strList.size()); + + strList.clear(); + System.out.println("no value "+ strList); + + + } +} diff --git a/Java/Activities/Car.java b/Java/Activities/Car.java new file mode 100644 index 0000000000..cd326b7b54 --- /dev/null +++ b/Java/Activities/Car.java @@ -0,0 +1,28 @@ +package activities; + +public class Car { + + String color; + String transmission; + int make; + int tyres; + int doors; + + public Car() { + tyres = 4; + doors = 4; + } + public void displayCharacteristics() { + System.out.println(color); + System.out.println(transmission); + System.out.println(make); + System.out.println(tyres); + System.out.println(doors); + } + public void accelarate() { + System.out.println("Car is moving forward."); + } + public void brake() { + System.out.println("Car has stopped."); + } +} diff --git a/Python/Activities/Activity1.py b/Python/Activities/Activity1.py new file mode 100644 index 0000000000..ff7b441573 --- /dev/null +++ b/Python/Activities/Activity1.py @@ -0,0 +1,9 @@ +# Take user name & age as input +# Calculate when they will turn 100 years + +name =input("Enter the name : ") +age = int(input("Enter the age : ")) + +year = (100-age)+2025 + +print(f"{name} will turn 100 years in {year}") \ No newline at end of file diff --git a/Python/Activities/Activity10.py b/Python/Activities/Activity10.py new file mode 100644 index 0000000000..b352f05fbc --- /dev/null +++ b/Python/Activities/Activity10.py @@ -0,0 +1,10 @@ +#inp_val = input("enter 5 input values: ") #--> by default it will take list with strings as input +#num_list = inp_val.split(",") #--> here we are seperating string with ',' +#num_tuple = tuple(num_list) #--> since input is list we are converting into tuple + +num_tuple = tuple(input("Enter 5 values: ").split(",")) + +print("Numbers divisible by 5 is : ") +for number in num_tuple: + if int(number) % 5 == 0: + print(number) \ No newline at end of file diff --git a/Python/Activities/Activity11.py b/Python/Activities/Activity11.py new file mode 100644 index 0000000000..2ff7d2e385 --- /dev/null +++ b/Python/Activities/Activity11.py @@ -0,0 +1,13 @@ +fruit_market = { + "apple": 40, + "grape": 30, + "pineapple": 60, + "mango": 80 +} + +user_input = input("enter the fruit your looking : ").lower() + +if user_input in fruit_market: + print(user_input +" is available") +else: + print(user_input +" is not available") diff --git a/Python/Activities/Activity12.py b/Python/Activities/Activity12.py new file mode 100644 index 0000000000..382dacc34a --- /dev/null +++ b/Python/Activities/Activity12.py @@ -0,0 +1,13 @@ +# Define function to calculate sum +def calculateSum(num): + if num != 0: + # Recursive function call + return num + calculateSum(num-1) + else: + return 0 + +# Call calculateSum() function +res = calculateSum(15) + +# Print result +print(res) \ No newline at end of file diff --git a/Python/Activities/Activity13.py b/Python/Activities/Activity13.py new file mode 100644 index 0000000000..b34ada9434 --- /dev/null +++ b/Python/Activities/Activity13.py @@ -0,0 +1,9 @@ +def sum(numbers): + result = 0 + for number in numbers: + result += number + return result +num_list = [20,30,40,50] + +sum_list =sum(num_list) +print("sum of values in list is : " +str(sum_list)) \ No newline at end of file diff --git a/Python/Activities/Activity14.py b/Python/Activities/Activity14.py new file mode 100644 index 0000000000..0c824d80dc --- /dev/null +++ b/Python/Activities/Activity14.py @@ -0,0 +1,14 @@ +def fibonacci(number): + if number <= 1: + return number + else: + return(fibonacci(number-1) + fibonacci(number-2)) + +nterms = int(input("Enter a number: ")) + +if nterms <= 0: + print("Please enter a positive number") +else: + print("Fibonacci Sequence: ") + for i in range(nterms): + print(fibonacci(i)) \ No newline at end of file diff --git a/Python/Activities/Activity15.py b/Python/Activities/Activity15.py new file mode 100644 index 0000000000..08e3ca65e9 --- /dev/null +++ b/Python/Activities/Activity15.py @@ -0,0 +1,15 @@ +try: + print(x) +except: + print("X is not defined") + + +#try: +# x =5 +# if x %2 == 0: +# print(x) +#except NameError: +# print("X is not defined") +#else: +# print("this is else") + diff --git a/Python/Activities/Activity16.py b/Python/Activities/Activity16.py new file mode 100644 index 0000000000..ba3346158f --- /dev/null +++ b/Python/Activities/Activity16.py @@ -0,0 +1,24 @@ +class car: + def __init__(self,manufacturer, model, make, transmission, color): + self.manufacturer = manufacturer + self.model = model + self.make =make + self.transmission = transmission + self.color = color + def accelerate(self): + print(self.manufacturer + " " + self.model + " has started moving") + def stop(self): + print(self.manufacturer + " " + self.model + " has stopped moving") + +car1 = car("Toyota", "Corolla", "2015", "Manual", "White") +car2 = car("Maruti", "800", "2013", "Manual", "Red") +car3 = car("Suzuki", "Swift", "2017", "Automatic", "Black") + +car1.accelerate() +car1.stop() + +car2.accelerate() +car2.stop() + +car3.accelerate() +car3.stop() \ No newline at end of file diff --git a/Python/Activities/Activity17_18.py b/Python/Activities/Activity17_18.py new file mode 100644 index 0000000000..60822a3008 --- /dev/null +++ b/Python/Activities/Activity17_18.py @@ -0,0 +1,37 @@ +import pandas as pd + +# create dataset +data ={ + "Usernames": ["admin", "Charles", "Deku"], + "Passwords": ["password", "Charl13", "AllMight"] + } + +#convert dataset into dataframe or table +df=pd.DataFrame(data) + +# Write the dataframe into csv.file +# df.to_csv("./Activities/sample.csv") # . --> represents current file,, .. --> reperesents parent folder +#df.to_csv("C:\Users\004PA4744\Desktop\FST\FST Python\sample.csv") +df.to_csv("./Activities/sample.csv", index=False) # index =false --> don't give row numbers + +# to Read the data +input_data = pd.read_csv("./Activities/sample.csv") + +# to print only user names +print(input_data["Usernames"]) + +# to print user name and passwords from 2nd row +print(input_data["Usernames"][1],input_data["Passwords"][1]) + +#Sort the Usernames column in ascending order +print("====================================") +print("Data sorted in ascending Usernames:") +#print(df.sort_values('Usernames')) +print(input_data.sort_values('Usernames')) + +#Sort the Passwords column in descending order +print("====================================") +print("Data sorted in descending Passwords:") +print(df.sort_values('Passwords', ascending=False)) + + diff --git a/Python/Activities/Activity19_20.py b/Python/Activities/Activity19_20.py new file mode 100644 index 0000000000..ac1056c06c --- /dev/null +++ b/Python/Activities/Activity19_20.py @@ -0,0 +1,44 @@ +import pandas +from pandas import ExcelWriter + +# Create a dictionary that will be used to create the DataFrame +data = { + 'FirstName':["Satvik", "Avinash", "Lahri"], + 'LastName':["Shah", "Kati", "Rath"], + 'Email':["satshah@example.com", "avinashK@example.com", "lahri.rath@example.com"], + 'PhoneNumber':["4537829158", "4892184058", "4528727830"] +} + +# Create the DataFrame that will be written to the excel file +dataframe = pandas.DataFrame(data) + +# Print the dataframe +print(dataframe) + +# Write the dataframe to a Excel file +writer = ExcelWriter('./Activities/sample.xlsx') +dataframe.to_excel(writer, 'Sheet1', index = False) + +# Commit data to the Excel file +writer.close() + +# Read data from Excel sheet +dataframe = pandas.read_excel('./Activities/sample.xlsx') + +# Print the dataframe +print("===========Reading starts form here =========================") +print(dataframe) + +# Print the number of rows and columns +print("====================================") +print("Number of rows and columns:", dataframe.shape) + +# Print the data in the emails column only +print("====================================") +print("Emails:") +print(dataframe['Email']) + +# Sort the data based on FirstName in ascending order and print the data +print("====================================") +print("Sorted data:") +print(dataframe.sort_values('FirstName')) \ No newline at end of file diff --git a/Python/Activities/Activity2.py b/Python/Activities/Activity2.py new file mode 100644 index 0000000000..16c958c1a6 --- /dev/null +++ b/Python/Activities/Activity2.py @@ -0,0 +1,7 @@ +number = int(input("Enter the value : ")) +if number % 2 == 0 : + print(f"{number} is EVEN number") +elif number %2 != 0 : + print(f"{number} is ODD number") +else : + print("Enter valid number") \ No newline at end of file diff --git a/Python/Activities/Activity3_4.py b/Python/Activities/Activity3_4.py new file mode 100644 index 0000000000..5c0df7f6a9 --- /dev/null +++ b/Python/Activities/Activity3_4.py @@ -0,0 +1,23 @@ +result = 'play' +while True: + input1 = input("Enter player1 choice : ").lower() + input2 = input("Enter player2 choice : ").lower() + if input1 == 'rock' and input2 == 'paper': + print("player2 wins!!") + elif input1 =='paper' and input2 =='rock': + print("Player1 wins!!") + elif input1 =='sissor' and input2 =='paper': + print("Player1 wins!!") + elif input1 == input2: + print("It's Draw") + else: + print("Enter valid options") + user_input =input("Enter 'yes' if you want to play again : ").lower() + if user_input == 'yes': + pass + else: + break +print("Thanks for playing!!") + + + diff --git a/Python/Activities/Activity5.py b/Python/Activities/Activity5.py new file mode 100644 index 0000000000..10f1c4d1a9 --- /dev/null +++ b/Python/Activities/Activity5.py @@ -0,0 +1,4 @@ +number = int(input("Enter the value : ")) + +for i in range(1,11): + print(number, ' x ', i, ' = ', number*i) \ No newline at end of file diff --git a/Python/Activities/Activity6.py b/Python/Activities/Activity6.py new file mode 100644 index 0000000000..6e379ce9ec --- /dev/null +++ b/Python/Activities/Activity6.py @@ -0,0 +1,3 @@ +for i in range(10): + print(str(i) * i) #str(i) --> converts i to string and prints i times + \ No newline at end of file diff --git a/Python/Activities/Activity7.py b/Python/Activities/Activity7.py new file mode 100644 index 0000000000..a2ad4d7bff --- /dev/null +++ b/Python/Activities/Activity7.py @@ -0,0 +1,7 @@ +numbers = input("Enter a sequence of comma separated values: ").split(",") + +sum = 0 +for number in numbers: + sum += int(number) + +print(sum) \ No newline at end of file diff --git a/Python/Activities/Activity8.py b/Python/Activities/Activity8.py new file mode 100644 index 0000000000..0bfb614047 --- /dev/null +++ b/Python/Activities/Activity8.py @@ -0,0 +1,10 @@ +num_list = [1,5,17,40,1] +#num_list = ["Apple","Orange","apple"] +#first_value = num_list[0] +#last_value = num_list[-1] + +#if first_value == last_value: +if num_list[0] == num_list[-1]: + print("True") +else: + print("False") \ No newline at end of file diff --git a/Python/Activities/Activity9.py b/Python/Activities/Activity9.py new file mode 100644 index 0000000000..447f94e16c --- /dev/null +++ b/Python/Activities/Activity9.py @@ -0,0 +1,15 @@ +list1 = [2,5,7,9,6] +list2 = [1,5,9,6] + +list3 =[] + +for num in list1 : + if num % 2 != 0: + list3.append(num) + +for num in list2 : + if num % 2 == 0: + list3.append(num) + +print("Values in list 3 is :\n",list3) + diff --git a/Python/Activities/test_activity21-22.py b/Python/Activities/test_activity21-22.py new file mode 100644 index 0000000000..85238ba874 --- /dev/null +++ b/Python/Activities/test_activity21-22.py @@ -0,0 +1,31 @@ +import pytest + +@pytest.mark.activity +def test_addition(): + num1 = 10 + num2 = 5 + sum = num1+num2 + assert sum==15 + +@pytest.mark.activity +def test_subtraction(): + num1 = 10 + num2 = 5 + sub = num1 - num2 + assert sub == 5 + +@pytest.mark.activity +def test_product(): + num1 = 10 + num2 = 5 + mul = num1 * num2 + assert mul == 50 + +@pytest.mark.activity +#@pytest.mark.skip +@pytest.mark.xfail +def test_division(): + num1 = 10 + num2 = 5 + div = num1 / num2 + assert div == 30 diff --git a/Python/Activities/test_activity23.py b/Python/Activities/test_activity23.py new file mode 100644 index 0000000000..70cff7c05e --- /dev/null +++ b/Python/Activities/test_activity23.py @@ -0,0 +1,19 @@ +import pytest + +@pytest.mark.activity23 +@pytest.mark.skip +def test_sum(num_list): + # Initialize sum + sum = 0 + # Add number in the list + for n in num_list: + sum += n + # Assertion + assert sum == 55 + +@pytest.mark.activity23 +def test_sum1(num_list1): + sum =0 + for n in num_list1: + sum += n + assert sum == 1180 diff --git a/Python/Activities/test_activity24.py b/Python/Activities/test_activity24.py new file mode 100644 index 0000000000..b205e433ef --- /dev/null +++ b/Python/Activities/test_activity24.py @@ -0,0 +1,14 @@ +import pytest + +@pytest.mark.activity24 +@pytest.mark.parametrize("earned, spent, expected", [ (30, 10, 20), (20, 2, 18), ]) +def test_transactions(wallet_amount, earned, spent, expected): + + # Add money to your wallet + wallet_amount += earned + + # Subtract amount from wallet + wallet_amount -= spent + + # Assertion + assert wallet_amount == expected \ No newline at end of file diff --git a/Rest_Assured/Activities/ConsumerTest.java b/Rest_Assured/Activities/ConsumerTest.java new file mode 100644 index 0000000000..a43e9a0dff --- /dev/null +++ b/Rest_Assured/Activities/ConsumerTest.java @@ -0,0 +1,165 @@ +package Examples; + +import au.com.dius.pact.consumer.MockServer; +import au.com.dius.pact.consumer.dsl.DslPart; +import au.com.dius.pact.consumer.dsl.PactDslJsonArray; +import au.com.dius.pact.consumer.dsl.PactDslJsonBody; +import au.com.dius.pact.consumer.dsl.PactDslWithProvider; +import au.com.dius.pact.consumer.junit5.PactConsumerTestExt; +import au.com.dius.pact.consumer.junit5.PactTestFor; +import au.com.dius.pact.core.model.V4Pact; +import au.com.dius.pact.core.model.annotations.Pact; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import java.util.HashMap; +import java.util.Map; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; + +@ExtendWith(PactConsumerTestExt.class) +public class ConsumerTest { + // Set the headers + Map headers = new HashMap<>(); + + // Create the Fragment for POST request + @Pact(consumer = "UserConsumer", provider = "UserProvider") + public V4Pact createPostFragment(PactDslWithProvider builder) { + // Set headers + headers.put("Content-Type", "application/json"); + // Create the JSON body + DslPart reqResBody = new PactDslJsonBody() + .numberType("id", 123) + .stringType("firstName", "Saahil") + .stringType("lastName", "Sharma") + .stringType("email", "saahil@example.com"); + // Create the contract(Pact) + return builder.given("POST Request") + .uponReceiving("A request to create a user") + .method("POST") + .path("/api/users") + .headers(headers) + .body(reqResBody) + .willRespondWith() + .status(201) + .body(reqResBody) + .toPact(V4Pact.class); + } + + // Create the Fragment for Get request + @Pact(consumer = "UserConsumer", provider = "UserProvider") + public V4Pact createGetFragment(PactDslWithProvider builder) { + // Set headers + headers.put("Content-Type", "application/json"); + // Create the JSON body + DslPart reqResBody = new PactDslJsonBody() + .numberType("id", 1) + .stringType("firstName", "Saahil") + .stringType("lastName", "Sharma") + .stringType("email", "saahil@example.com"); + // Create the contract(Pact) + return builder.given("GET Request") + .uponReceiving("A request to get a user") + .method("GET") + .path("/api/users") + .headers(headers) + .pathFromProviderState("/api/users/{id}", "/api/users/1") + .willRespondWith() + .status(200) + .body(reqResBody) + .toPact(V4Pact.class); + } + + // Create the Fragment for Get request + @Pact(consumer = "UserConsumer", provider = "UserProvider") + public V4Pact createGetAllFragment(PactDslWithProvider builder) { + // Set headers + headers.put("Content-Type", "application/json"); + // Create the JSON body + DslPart arrResBody = PactDslJsonArray.arrayMaxLike(2) + .numberType("id", 1) + .stringType("firstName", "Gretel") + .stringType("lastName", "") + .stringType("email", "gretel@example.com") + .numberType("id", 2) + .stringType("firstName", "Hansel") + .stringType("lastName", "") + .stringType("email", "hansel@example.com"); + + // Create the contract(Pact) + return builder.given("GET ALL Request") + .uponReceiving("A request to get all users") + .method("GET") + .path("/api/users") + .headers(headers) + .willRespondWith() + .status(200) + .body(arrResBody) + .toPact(V4Pact.class); + } + + // Create the Fragment for Get request + @Pact(consumer = "UserConsumer", provider = "UserProvider") + public V4Pact createDeleteFragment(PactDslWithProvider builder) { + // Set headers + headers.put("Content-Type", "application/json"); + // Create the contract(Pact) + return builder.given("DELETE Request") + .uponReceiving("A request to delete a user") + .method("DELETE") + .path("/api/users") + .headers(headers) + .pathFromProviderState("/api/users/{id}", "/api/users/1") + .willRespondWith() + .status(204) + .toPact(V4Pact.class); + } + + // Consumer test with mock provider + @Test + @PactTestFor(providerName = "UserProvider", pactMethod = "createPostFragment") + public void postRequestTest(MockServer mockServer) { + // Create a request body + Map reqBody = new HashMap<>(); + reqBody.put("id", 123); + reqBody.put("firstName", "Saahil"); + reqBody.put("lastName", "Sharma"); + reqBody.put("email", "saahil@example.com"); + + // Send request, get response, assert response + given().baseUri(mockServer.getUrl() + "/api/users").headers(headers).body(reqBody).log().all(). + when().post(). + then().log().all().statusCode(201).body("email", equalTo("saahil@example.com")); + } + + // Consumer test with mock provider + @Test + @PactTestFor(providerName = "UserProvider", pactMethod = "createGetFragment") + public void getRequestTest(MockServer mockServer) { + // Send request, get response, assert response + given().baseUri(mockServer.getUrl() + "/api/users").headers(headers).log().all(). + when().get("/1"). + then().statusCode(200).log().all(); + } + + // Consumer test with mock provider + @Test + @PactTestFor(providerName = "UserProvider", pactMethod = "createDeleteFragment") + public void deleteRequestTest(MockServer mockServer) { + // Send request, get response, assert response + given().baseUri(mockServer.getUrl() + "/api/users").headers(headers).log().all(). + when().delete("/1"). + then().statusCode(204).log().all(); + } + + // Consumer test with mock provider + @Test + @PactTestFor(providerName = "UserProvider", pactMethod = "createGetAllFragment") + public void getAllRequestTest(MockServer mockServer) { + // Send request, get response, assert response + given().baseUri(mockServer.getUrl() + "/api/users").headers(headers).log().all(). + when().get(). + then().statusCode(200).log().all(); + } +} \ No newline at end of file diff --git a/Rest_Assured/Activities/HelloRest.java b/Rest_Assured/Activities/HelloRest.java new file mode 100644 index 0000000000..68820ee917 --- /dev/null +++ b/Rest_Assured/Activities/HelloRest.java @@ -0,0 +1,68 @@ +package Examples; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.equalTo; + +import org.hamcrest.Matchers; +import org.testng.annotations.Test; + +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import io.restassured.response.Response; + +public class HelloRest { + + String baseURI; + @Test (priority =1) + public void helloRest() { + + // Specify the base URL to the RESTful web service + baseURI = "https://petstore.swagger.io/v2/pet"; + + // Make a request to the server by specifying the method Type and + // resource to send the request to. + // Store the response received from the server for later use. + Response response = + given().contentType(ContentType.JSON) // Set headers + .when().get(baseURI + "/findByStatus?status=sold"); // Run GET request + + // Print the status code +// System.out.println(response.statusCode()); +// System.out.println("==============================="); +// // Print the response headers +// System.out.println(response.getHeaders().asList()); +// System.out.println("==============================="); +// // Print the response body +// System.out.println(response.getBody().asString()); +// System.out.println("==============================="); +// System.out.println(response.getBody().asPrettyString()); + + // Now let us print the body of the message to see what response + // we have received from the server +// String responseBody = response.getBody().asString(); +// System.out.println("Response Body is => " + responseBody); + + response.prettyPrint(); + // Extract properties from the response + String petStatus = response.then().extract().path("[0].status"); + + // Assertions + response.then().statusCode(200); + response.then().body("[0].status", equalTo("sold")); + + } + @Test(priority =2) + public void getResponseWithPathParm() { + // Send request, get response, and assert + RestAssured.given(). // Request Specification + baseUri("https://petstore.swagger.io/v2/pet"). + header("Content-Type", "application/json"). // Request content type + pathParam("petId", 12). + when().get("/{petId}"). + then(). + statusCode(200). + body("[0].status", Matchers.equalTo("sold")). + body("[0].name", Matchers.equalTo("doggie")); + + } +} diff --git a/Rest_Assured/Activities/ProviderTest.java b/Rest_Assured/Activities/ProviderTest.java new file mode 100644 index 0000000000..498f22a41e --- /dev/null +++ b/Rest_Assured/Activities/ProviderTest.java @@ -0,0 +1,43 @@ +package Examples; + +import au.com.dius.pact.provider.junit5.HttpTestTarget; +import au.com.dius.pact.provider.junit5.PactVerificationContext; +import au.com.dius.pact.provider.junit5.PactVerificationInvocationContextProvider; +import au.com.dius.pact.provider.junitsupport.Provider; +import au.com.dius.pact.provider.junitsupport.State; +import au.com.dius.pact.provider.junitsupport.loader.PactFolder; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.api.extension.ExtendWith; + +@Provider("UserProvider") +@PactFolder("target/pacts") +public class ProviderTest { + @BeforeEach + public void setUp(PactVerificationContext context) { + HttpTestTarget target = new HttpTestTarget("localhost", 8585); + context.setTarget(target); + } + + @TestTemplate + @ExtendWith(PactVerificationInvocationContextProvider.class) + public void providerTest(PactVerificationContext context) { + context.verifyInteraction(); + } + +// @State("POST Request") +// public void state1() { +// } + +// @State("GET Request") +// public void state2() { +// } +// +// @State("DELETE Request") +// public void state3() { +// } + +// @State("GET ALL Request") +// public void state4() { +// } +} \ No newline at end of file diff --git a/Rest_Assured/Activities/SpecificationTest.java b/Rest_Assured/Activities/SpecificationTest.java new file mode 100644 index 0000000000..d9ff7cd2d9 --- /dev/null +++ b/Rest_Assured/Activities/SpecificationTest.java @@ -0,0 +1,77 @@ +package Examples; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static io.restassured.RestAssured.given; + +import java.util.HashMap; +import java.util.Map; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.restassured.builder.RequestSpecBuilder; +import io.restassured.builder.ResponseSpecBuilder; +import io.restassured.response.Response; +import io.restassured.specification.RequestSpecification; +import io.restassured.specification.ResponseSpecification; + +public class SpecificationTest { + // Declare Request and Response specifications objects + + RequestSpecification RequestSpec; + ResponseSpecification ResponseSpec; + int petId; + + @BeforeClass + public void setUp() { + // Create request specification + RequestSpec = new RequestSpecBuilder(). + setBaseUri("https://petstore.swagger.io/v2/pet"). + addHeader("Content-Type","application/json"). + build(); + + // Create a response Specification + ResponseSpec = new ResponseSpecBuilder(). + expectStatusCode(200). + expectBody("status",equalTo("alive")). + expectResponseTime(lessThanOrEqualTo(5000L)). + build(); + } + + @Test(priority = 1) + //POST https://petstore.swagger.io/v2/pet + public void postRequestTest() { + Map reqBody = new HashMap<>(); + reqBody.put("id", 10234); + reqBody.put("name", "Rocky"); + reqBody.put("status", "alive"); + // Send request and save the response + Response response = given().spec(RequestSpec).body(reqBody). + when().post(); + // Extract PetId from the response + this.petId = response.then().extract().path("id"); + // Assertions + response.then().spec(ResponseSpec); + + } + //GET https://petstore.swagger.io/v2/pet/{petId} + @Test(priority = 2) + public void getRequestTest() { + // Send request, get request, Assert + given().spec(RequestSpec).pathParam("petId",this.petId). + when().get("/{petId}"). + then().spec(ResponseSpec).body("name",equalTo("Rocky")); + + } + //DELETE https://petstore.swagger.io/v2/pet/{petId} + @Test(priority = 3) + public void deleteRequestTest() { + // Send request, get request, Assert + given().spec(RequestSpec).pathParam("petId",this.petId). + // log().all(). --> this prints all the values + when().delete("/{petId}"). + then().statusCode(200); + + } +} diff --git a/SQL/Activities/Activity1-5.sql b/SQL/Activities/Activity1-5.sql new file mode 100644 index 0000000000..280c4fe30e --- /dev/null +++ b/SQL/Activities/Activity1-5.sql @@ -0,0 +1,42 @@ +--Activity 1 (create a salesman table) +drop table salesman; + +create table salesman( + salesman_id int primary key, + salesman_name varchar(20) not null, + salesman_city varchar(20), + commission int); + +Describe salesman; + +-- Activity 2 ( insert data into table) +insert all + into salesman values(1001,'Rupesh','Cherlopalli',15) + into salesman values(1002,'Pradeep','Tirupati',20) + into salesman values(1003,'Vishnu','Tirupati',25) + into salesman values(1004,'Rajendra','Rajempeta',30) + into salesman values(1005,'Giri','Leelamahal',35) +select 1 from dual; + +Select * from salesman; + +-- Activity 3 (Select statements) +select salesman_id,salesman_city from salesman; + +Select * from salesman +where salesman_city='Tirupati'; + +select salesman_name,commission from salesman +where salesman_name ='Rupesh'; + +-- Activity4 (Alter & Update) +Alter table salesman ADD(grade int); + +update salesman set grade =100; +select * from salesman; + +-- Activity5 +update salesman set grade = 200 where salesman_name ='Rupesh'; +update salesman set grade = 300 where salesman_city ='Tirupati'; +update salesman set salesman_name = 'Giri Prasad' where salesman_name ='Giri'; +select * from salesman; diff --git a/SQL/Activities/Activity6-8.sql b/SQL/Activities/Activity6-8.sql new file mode 100644 index 0000000000..c32295c886 --- /dev/null +++ b/SQL/Activities/Activity6-8.sql @@ -0,0 +1,66 @@ +-- Activity 6 ------------------ +-- Create a table named orders +create table orders( + order_no int primary key, purchase_amount float, order_date date, + customer_id int, salesman_id int); + +-- Add values to the table +INSERT ALL + INTO orders VALUES(70001, 150.5, TO_DATE('2012/10/05', 'YYYY/MM/DD'), 3005, 5002) + INTO orders VALUES(70009, 270.65, TO_DATE('2012/09/10', 'YYYY/MM/DD'), 3001, 5005) + INTO orders VALUES(70002, 65.26, TO_DATE('2012/10/05', 'YYYY/MM/DD'), 3002, 5001) + INTO orders VALUES(70004, 110.5, TO_DATE('2012/08/17', 'YYYY/MM/DD'), 3009, 5003) + INTO orders VALUES(70007, 948.5, TO_DATE('2012/09/10', 'YYYY/MM/DD'), 3005, 5002) + INTO orders VALUES(70005, 2400.6, TO_DATE('2012/07/27', 'YYYY/MM/DD'), 3007, 5001) + INTO orders VALUES(70008, 5760, TO_DATE('2012/08/15', 'YYYY/MM/DD'), 3002, 5001) + INTO orders VALUES(70010, 1983.43, TO_DATE('2012/10/10', 'YYYY/MM/DD'), 3004, 5006) + INTO orders VALUES(70003, 2480.4, TO_DATE('2012/10/10', 'YYYY/MM/DD'), 3009, 5003) + INTO orders VALUES(70012, 250.45, TO_DATE('2012/06/27', 'YYYY/MM/DD'), 3008, 5002) + INTO orders VALUES(70011, 75.29, TO_DATE('2012/08/17', 'YYYY/MM/DD'), 3003, 5007) + INTO orders VALUES(70013, 3045.6, TO_DATE('2012/04/25', 'YYYY/MM/DD'), 3002, 5001) +SELECT 1 FROM DUAL; + +Describe orders; +-- Get all salesman ids without any repeated values +Select Distinct salesman_id from orders; +-- Display the order number ordered by date in ascending order +select order_no from orders +order by order_date asc; +-- Display the order number ordered by purchase amount in descending order +select order_no from orders +order by purchase_amount desc; +-- Display the full data of orders that have purchase amount less than 500. +select * from Orders +where purchase_amount < 500; +-- Display the full data of orders that have purchase amount between 1000 and 2000. +select * from Orders +where purchase_amount between 1000 and 2000; + +-- Activity 7 --------------- +-- Write an SQL statement to find the total purchase amount of all orders. +select SUM(purchase_amount) AS "Total sum" from orders; + +-- Write an SQL statement to find the average purchase amount of all orders. +select AVG(purchase_amount) AS "Average" from orders; + +-- Write an SQL statement to get the maximum purchase amount of all the orders. +select MAX(purchase_amount) AS "Maximum" from orders; + +-- Write an SQL statement to get the minimum purchase amount of all the orders. +select MIN(purchase_amount) AS "Minumum" from orders; + +-- Write an SQL statement to find the number of salesmen listed in the table. +select COUNT(distinct salesman_id) AS "Total count" from orders; + +-- Activity 8 ------------------- +-- Write an SQL statement to find the highest purchase amount ordered by the each customer with their ID and highest purchase amount. +select customer_id,max(purchase_amount) from orders +group by customer_id,purchase_amount; +-- Write an SQL statement to find the highest purchase amount on '2012-08-17' for each salesman with their ID. +select salesman_id,max(purchase_amount) from orders +where order_date = TO_DATE('2012/08/17', 'YYYY/MM/DD') +group by salesman_id,purchase_amount; +-- Write an SQL statement to find the highest purchase amount with their ID and order date, for only those customers who have a higher purchase amount within the list [2030, 3450, 5760, 6000]. +select customer_id,salesman_id,order_date,purchase_amount from orders +group by customer_id,salesman_id,order_date,purchase_amount +having max(purchase_amount) in (2030, 3450, 5760, 6000); \ No newline at end of file diff --git a/SQL/Activities/Activity9-11.sql b/SQL/Activities/Activity9-11.sql new file mode 100644 index 0000000000..806da2f5ad --- /dev/null +++ b/SQL/Activities/Activity9-11.sql @@ -0,0 +1,55 @@ +--Activity 9 ------------ +-- Write an SQL statement to know which salesman are working for which customer. +SELECT a.customer_name AS "Customer Name", a.city, b.salesman_name AS "Salesman", b.commission FROM customers a +INNER JOIN salesman b ON a.salesman_id=b.salesman_id; + +-- Write an SQL statement to make a list of customers in ascending order with a salesman that have a grade less than 300 +SELECT a.customer_name, a.city, a.grade, b.salesman_name AS "Salesman", b.salesman_city FROM customers a +LEFT OUTER JOIN salesman b ON a.salesman_id=b.salesman_id WHERE a.grade<300 +ORDER BY a.customer_id; +-- Write an SQL statement to find the list of customers who appointed a salesman for their jobs who gets a commission of more than 12% +SELECT a.customer_name AS "Customer Name", a.city, b.salesman_name AS "Salesman", b.commission FROM customers a +INNER JOIN salesman b ON a.salesman_id=b.salesman_id +WHERE b.commission>12; + +-- Write an SQL statement to find the following details of an order - order number, order date, purchase amount of order, which customer gives the order and which salesman works for that customer and commission rate they get for the order. +SELECT a.order_no, a.order_date, a.purchase_amount, b.customer_name AS "Customer Name", b.grade, c.salesman_name AS "Salesman", c.commission FROM orders a +INNER JOIN customers b ON a.customer_id=b.customer_id +INNER JOIN salesman c ON a.salesman_id=c.salesman_id; + +--Activity 10 --------------- +-- Write a query to find all the orders issued against the salesman who may works for customer whose id is 3007. +SELECT * FROM orders +WHERE salesman_id=(SELECT DISTINCT salesman_id FROM orders WHERE customer_id=3007); + +-- Write a query to find all orders attributed to a salesman in New York. +SELECT * FROM orders +WHERE salesman_id IN (SELECT salesman_id FROM salesman WHERE salesman_city='New York'); + +-- Write a query to count the customers with grades above New York's average. +SELECT grade, COUNT(*) FROM customers +GROUP BY grade HAVING grade>(SELECT AVG(grade) FROM customers WHERE city='New York'); + +-- Write a query to extract the data from the orders table for those salesman who earned the maximum commission +SELECT order_no, purchase_amount, order_date, salesman_id FROM orders +WHERE salesman_id IN( SELECT salesman_id FROM salesman +WHERE commission=( SELECT MAX(commission) FROM salesman)); + +--Activity 11 ------------------- +-- Write a query that produces the name and number of each salesman and each customer with more than one current order. Put the results in alphabetical order +SELECT customer_id, customer_name FROM customers a +WHERE 1<(SELECT COUNT(*) FROM orders b WHERE a.customer_id = b.customer_id) +UNION +SELECT salesman_id, salesman_name FROM salesman a +WHERE 1<(SELECT COUNT(*) FROM orders b WHERE a.salesman_id = b.salesman_id) +ORDER BY customer_name; + +-- Write a query to make a report of which salesman produce the largest and smallest orders on each date. +SELECT a.salesman_id, a.salesman_name, o.order_no, 'highest on', o.order_date, o.purchase_amount FROM salesman a, orders o +WHERE a.salesman_id=o.salesman_id +AND o.purchase_amount=(SELECT MAX(purchase_amount) FROM orders c WHERE c.order_date = o.order_date) +UNION +SELECT a.salesman_id, a.salesman_name, o.order_no, 'lowest on', o.order_date, o.purchase_amount FROM salesman a, orders o +WHERE a.salesman_id=o.salesman_id +AND o.purchase_amount=(SELECT MIN(purchase_amount) FROM orders c WHERE c.order_date = o.order_date) +ORDER BY order_date; diff --git a/Selenium/Activities/Activity1.java b/Selenium/Activities/Activity1.java new file mode 100644 index 0000000000..e0085e5e24 --- /dev/null +++ b/Selenium/Activities/Activity1.java @@ -0,0 +1,33 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity1 { + + public static void main(String[] args) { + // initialize WebDriver + WebDriver driver = new FirefoxDriver(); //ChromeDriver() , EdgeDriver() + + // open the web page + driver.get("https://training-support.net/"); + + //verify the title to check if we are in right page or not + System.out.println("Page Title is: "+ driver.getTitle()); + + //interact with elements in page + // Click on the about us button + + driver.findElement(By.className("card")).click(); + //driver.findElement(By.css**) --> with CSS we can give multiple classes + //driver.findElement(By.linkText("About Us")).click(); + + // verify the title in the about page + System.out.println("New Page Title is: "+ driver.getTitle()); + + //Close + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity1.py b/Selenium/Activities/Activity1.py new file mode 100644 index 0000000000..3c9ea0650e --- /dev/null +++ b/Selenium/Activities/Activity1.py @@ -0,0 +1,17 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the "About Us" button on the page using ID and click it + driver.find_element(By.LINK_TEXT, "About Us").click() + + # Print the title of the new page + print("New page title is: ", driver.title) \ No newline at end of file diff --git a/Selenium/Activities/Activity10.java b/Selenium/Activities/Activity10.java new file mode 100644 index 0000000000..6702d766e6 --- /dev/null +++ b/Selenium/Activities/Activity10.java @@ -0,0 +1,46 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; + +public class Activity10 { + + public static void main(String[] args) { + // Initialize the Firefox driver + WebDriver driver = new FirefoxDriver(); + // Create the Actions object + Actions builder = new Actions(driver); + + // Open the page + driver.get("https://training-support.net/webelements/drag-drop"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the football + WebElement football = driver.findElement(By.id("ball")); + // Find the dropzone1 + WebElement dropzone1 = driver.findElement(By.id("dropzone1")); + // Find the dropzone2 + WebElement dropzone2 = driver.findElement(By.id("dropzone2")); + + // Perform drag and drop to dropzone 1 + builder.clickAndHold(football).moveToElement(dropzone1).pause(5000).release().build().perform(); + if(dropzone1.findElement(By.className("dropzone-text")).getText().equals("Dropped!")) { + System.out.println("Ball was dropped in Dropzone 1"); + } + + // Perform drag and drop to dropzone 2 + builder.dragAndDrop(football, dropzone2).pause(5000).build().perform(); + if(dropzone2.findElement(By.className("dropzone-text")).getText().equals("Dropped!")) { + System.out.println("Ball was dropped in Dropzone 2"); + } + + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity10.py b/Selenium/Activities/Activity10.py new file mode 100644 index 0000000000..944d8039d9 --- /dev/null +++ b/Selenium/Activities/Activity10.py @@ -0,0 +1,30 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver import ActionChains +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the actions variable + actions = ActionChains(driver) + # Navigate to the URL + driver.get("https://training-support.net/webelements/drag-drop") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the football + football = driver.find_element(By.ID, "ball") + # Find the dropzone1 + dropzone1 = driver.find_element(By.ID, "dropzone1") + # Find the dropzone2 + dropzone2 = driver.find_element(By.ID, "dropzone2") + + # Perform drag and drop to dropzone 1 + actions.click_and_hold(football).move_to_element(dropzone1).pause(5).release().perform() + if(dropzone1.find_element(By.CLASS_NAME, "dropzone-text").text == "Dropped!"): + print("Ball was dropped in Dropzone 1") + + # Perform drag and drop to dropzone 2 + actions.drag_and_drop(football, dropzone2).pause(5).perform() + if(dropzone2.find_element(By.CLASS_NAME, "dropzone-text").text == "Dropped!"): + print("Ball was dropped in Dropzone 2") \ No newline at end of file diff --git a/Selenium/Activities/Activity11.java b/Selenium/Activities/Activity11.java new file mode 100644 index 0000000000..5355778a4f --- /dev/null +++ b/Selenium/Activities/Activity11.java @@ -0,0 +1,47 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity11 { + + public static void main(String[] args) { + // Driver object reference + WebDriver driver = new FirefoxDriver(); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open the browser + driver.get("https://www.training-support.net/webelements/dynamic-controls"); + + // Verify page title + System.out.println("Page title is: " + driver.getTitle()); + + // Find the checkbox and make sure it is visible + WebElement checkbox = driver.findElement(By.id("checkbox")); + System.out.println("Checkbox is visible? " + checkbox.isDisplayed()); + + // Find the button to toggle it and click it + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + // Wait for it to disappear + wait.until(ExpectedConditions.invisibilityOf(checkbox)); + // Check if it is visible + System.out.println("Checkbox is visible? " + checkbox.isDisplayed()); + + // Toggle the checkbox and click it + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + wait.until(ExpectedConditions.elementToBeClickable(checkbox)).click(); + // Check if it is selected + System.out.println("Checkbox is selected? " + checkbox.isSelected()); + + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity11.py b/Selenium/Activities/Activity11.py new file mode 100644 index 0000000000..470468fa9c --- /dev/null +++ b/Selenium/Activities/Activity11.py @@ -0,0 +1,31 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-controls") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the checkbox and make sure it is visible + checkbox = driver.find_element(By.ID, "checkbox") + print("Checkbox is visible? ", checkbox.is_displayed()) + + # Find the button to toggle it and click it + driver.find_element(By.XPATH, "//button[text()='Toggle Checkbox']").click() + # Wait for it to disappear + wait.until(EC.invisibility_of_element(checkbox)) + # Check if it is visible + print("Checkbox is visible? ", checkbox.is_displayed()) + + # Toggle the checkbox and click it + driver.find_element(By.XPATH, "//button[text()='Toggle Checkbox']").click() + wait.until(EC.element_to_be_clickable(checkbox)).click() + # Check if it is selected + print("Checkbox is selected? ", checkbox.is_selected()) \ No newline at end of file diff --git a/Selenium/Activities/Activity12.java b/Selenium/Activities/Activity12.java new file mode 100644 index 0000000000..3c08da16fe --- /dev/null +++ b/Selenium/Activities/Activity12.java @@ -0,0 +1,37 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity12 { + + public static void main(String[] args) { + // Driver object reference + WebDriver driver = new FirefoxDriver(); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open the browser + driver.get("https://training-support.net/webelements/dynamic-content"); + + // Verify page title + System.out.println("Page title is: " + driver.getTitle()); + + driver.findElement(By.id("genButton")).click(); + + // Wait for the word to appear + if (wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("word"), "release"))) { + // Print the text to console + System.out.println("Word found: " + driver.findElement(By.id("word")).getText()); + } + + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity12.py b/Selenium/Activities/Activity12.py new file mode 100644 index 0000000000..50a46f9ed2 --- /dev/null +++ b/Selenium/Activities/Activity12.py @@ -0,0 +1,21 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-content") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the button and click it + driver.find_element(By.ID, "genButton").click() + # Wait for the word to appear + if wait.until(EC.text_to_be_present_in_element((By.ID, "word"), "release")): + # Print the text to console + print("Word found: ", driver.find_element(By.ID, "word").text) \ No newline at end of file diff --git a/Selenium/Activities/Activity13.java b/Selenium/Activities/Activity13.java new file mode 100644 index 0000000000..2686643885 --- /dev/null +++ b/Selenium/Activities/Activity13.java @@ -0,0 +1,40 @@ +package Activities; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity13 { + + public static void main(String[] args) { + // initialize WebDriver + WebDriver driver = new FirefoxDriver(); + + // open the web page + driver.get("https://training-support.net/webelements/tables"); + + //verify the title to check if we are in right page or not + System.out.println("Page Title is: "+ driver.getTitle()); + + // Print the number of columns + List cols = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/thead/tr/th")); + System.out.println("Number of columns: " + cols.size()); + + // Print the number of Rows + List rows = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr")); + System.out.println("Number of Rows: " + rows.size()); + + // Print the cells values of the third row + System.out.println(driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr[3]")).getText()); + + // Print the cell value of the second row and second column + System.out.println(driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr[2]/td[2]")).getText()); + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity13.py b/Selenium/Activities/Activity13.py new file mode 100644 index 0000000000..0d0ee41999 --- /dev/null +++ b/Selenium/Activities/Activity13.py @@ -0,0 +1,27 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/tables") + # Print the title of the page + print("Page title is: ", driver.title) + + # Print the number of columns + cols = driver.find_elements(By.XPATH, "//table[contains(@class, 'table-auto')]/thead/tr/th") + print("Number of columns: ", len(cols)) + # Print the number of rows + rows = driver.find_elements(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr") + print("Number of rows: ", len(rows)) + + # Print the cells values of the third row + thirdRow = driver.find_elements(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr[3]/td") + print("Third row cell values: ") + for cell in thirdRow: + print(cell.text) + + # Print the cell value of the second row and second column + cellValue = driver.find_element(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr[2]/td[2]") + print("Second row, second cell value: ", cellValue.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity14.java b/Selenium/Activities/Activity14.java new file mode 100644 index 0000000000..9dd0609337 --- /dev/null +++ b/Selenium/Activities/Activity14.java @@ -0,0 +1,44 @@ +package Activities; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity14 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/tables"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Print the number of columns + List cols = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/thead/tr/th")); + System.out.println("Number of columns: " + cols.size()); + // Print the number of rows + List rows = driver.findElements(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr")); + System.out.println("Number of rows: " + rows.size()); + + // Print the Book Name in the 5th row + WebElement cellValue = driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr[5]/td[2]")); + System.out.println("Book name before sorting: " + cellValue.getText()); + + // Sort the table + driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/thead/tr/th[5]")).click(); + + // Print the cell value of the second row and second column again + cellValue = driver.findElement(By.xpath("//table[contains(@class, 'table-auto')]/tbody/tr[5]/td[2]")); + System.out.println("Book Name after sorting: " + cellValue.getText()); + + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity14.py b/Selenium/Activities/Activity14.py new file mode 100644 index 0000000000..afdd9bd1ae --- /dev/null +++ b/Selenium/Activities/Activity14.py @@ -0,0 +1,32 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/tables") + # Print the title of the page + print("Page title is: ", driver.title) + + # Print the number of columns + cols = driver.find_elements(By.XPATH, "//table[contains(@class, 'table-auto')]/thead/tr/th") + print("Number of columns: ", len(cols)) + # Print the number of rows + rows = driver.find_elements(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr") + print("Number of rows: ", len(rows)) + + # Print the Book Name in the 5th row + cellValue = driver.find_element(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr[5]/td[2]") + print("Book name before sorting: ", cellValue.text) + + # Sort the table + driver.find_element(By.XPATH, "//table[contains(@class, 'table-auto')]/thead/tr/th[5]").click() + + # Print the cell value of the second row and second column again + cellValue = driver.find_element(By.XPATH, "//table[contains(@class, 'table-auto')]/tbody/tr[5]/td[2]") + print("Book Name after sorting: ", cellValue.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity15.java b/Selenium/Activities/Activity15.java new file mode 100644 index 0000000000..fa5b85a4d6 --- /dev/null +++ b/Selenium/Activities/Activity15.java @@ -0,0 +1,48 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity15 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + // Create the Wait object + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open the page + driver.get("https://training-support.net/webelements/dynamic-attributes"); + // Print the title of the page + System.out.println("Page title is: " + driver.getTitle()); + + // Find the input fields + WebElement fullName = driver.findElement(By.xpath("//input[starts-with(@id, 'full-name')]")); + WebElement email = driver.findElement(By.xpath("//input[contains(@id, '-email')]")); + WebElement eventDate = driver.findElement(By.xpath("//input[contains(@name, '-event-date-')]")); + WebElement details = driver.findElement(By.xpath("//textarea[contains(@id, '-additional-details-')]")); + // Enter the details + fullName.sendKeys("Raiden Shogun"); + email.sendKeys("raiden@electromail.com"); + eventDate.sendKeys("2025-06-26"); + details.sendKeys("It will be electric!"); + // Find and click the submit button + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Wait for the success message and print it + String message = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("action-confirmation"))) + .getText(); + System.out.println("Success message: " + message); + + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity15.py b/Selenium/Activities/Activity15.py new file mode 100644 index 0000000000..1e8ac729d5 --- /dev/null +++ b/Selenium/Activities/Activity15.py @@ -0,0 +1,31 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-attributes") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the input fields + fullName = driver.find_element(By.XPATH, "//input[starts-with(@id, 'full-name')]") + email = driver.find_element(By.XPATH, "//input[contains(@id, '-email')]") + eventDate = driver.find_element(By.XPATH, "//input[contains(@name, '-event-date-')]") + details = driver.find_element(By.XPATH, "//textarea[contains(@id, '-additional-details-')]") + # Enter the details + fullName.send_keys("Raiden Shogun") + email.send_keys("raiden@electromail.com") + eventDate.send_keys("2025-06-26") + details.send_keys("It will be electric!") + # Find and click the submit button + driver.find_element(By.XPATH, "//button[text()='Submit']").click() + + # Wait for the success message and print it + message = wait.until(EC.visibility_of_element_located((By.ID, "action-confirmation"))).text + print("Success message: ", message) \ No newline at end of file diff --git a/Selenium/Activities/Activity16.java b/Selenium/Activities/Activity16.java new file mode 100644 index 0000000000..35746f2f93 --- /dev/null +++ b/Selenium/Activities/Activity16.java @@ -0,0 +1,51 @@ +package Activities; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.Select; + +public class Activity16 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/selects"); + // Print the title of the page + System.out.println("Page title is: " + driver.getTitle()); + + // get the options + WebElement dropdown = driver.findElement(By.cssSelector("select.h-10")); + Select singleSelect = new Select(dropdown); + + // Select the second option using the visible text. + singleSelect.selectByContainsVisibleText("One"); + System.out.println(singleSelect.getFirstSelectedOption().getText()); + + // Select the third option using the index. + + singleSelect.selectByIndex(3); + System.out.println(singleSelect.getFirstSelectedOption().getText()); + + // Select the fourth option using the value. + singleSelect.selectByValue("five"); + System.out.println(singleSelect.getFirstSelectedOption().getText()); + + // Get all the options and print them to the console. + List allOptions = singleSelect.getOptions(); + System.out.println("Options in the dropdown: "); + for(WebElement option : allOptions) + { + System.out.println(option.getText()); + } + // close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity16.py b/Selenium/Activities/Activity16.py new file mode 100644 index 0000000000..8203dd373d --- /dev/null +++ b/Selenium/Activities/Activity16.py @@ -0,0 +1,37 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.select import Select + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/selects") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the dropdown + dropdown = driver.find_element(By.CSS_SELECTOR, "select.h-10") + # Pass the WebElement to the Select object + singleSelect = Select(dropdown) + + # Select the second option using visible text + singleSelect.select_by_visible_text("Two") + # Print the selected option + print("Second option: " + singleSelect.first_selected_option.text) + + # Select the third option using index + singleSelect.select_by_index(3) + # Print the selected option + print("Third option: " + singleSelect.first_selected_option.text) + + # Select the fourth option using value attribute + singleSelect.select_by_value("four") + # Print the selected option + print("Fourth option: " + singleSelect.first_selected_option.text) + + # Print all the options + allOptions = singleSelect.options + print("Options in the dropdown: ") + for option in allOptions: + print(option.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity17.java b/Selenium/Activities/Activity17.java new file mode 100644 index 0000000000..09f5de82da --- /dev/null +++ b/Selenium/Activities/Activity17.java @@ -0,0 +1,60 @@ +package Activities; + +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.Select; + +public class Activity17 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/selects"); + // Print the title of the page + System.out.println("Page title is: " + driver.getTitle()); + + // get the options + WebElement dropdown = driver.findElement(By.cssSelector("select.h-80")); + Select multiSelect = new Select(dropdown); + + //Select the "HTML" option using the visible text. + multiSelect.selectByVisibleText("HTML"); + + //Select the 4th, 5th and 6th options using the index. + multiSelect.selectByIndex(4); + multiSelect.selectByIndex(5); + multiSelect.selectByIndex(6); + + //Select the "Node" option using the value. + multiSelect.selectByValue("nodejs"); + + List allOptions = multiSelect.getAllSelectedOptions(); + System.out.println("All Selected OPtions"); + for(WebElement option : allOptions) + { + System.out.println(option.getText()); + } + //Deselect the 5th option using index. + multiSelect.deselectByIndex(5); + + // Again printing all the selected options + List selectedOptions = multiSelect.getAllSelectedOptions(); + System.out.println("All Selected OPtions"); + for(WebElement option1 : selectedOptions) + { + System.out.println(option1.getText()); + } + + // close the browser + driver.quit(); + + + } + +} diff --git a/Selenium/Activities/Activity17.py b/Selenium/Activities/Activity17.py new file mode 100644 index 0000000000..223c783aa1 --- /dev/null +++ b/Selenium/Activities/Activity17.py @@ -0,0 +1,37 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.select import Select + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/selects") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the dropdown + selectElement = driver.find_element(By.CSS_SELECTOR, "select.h-80") + # Pass the WebElement to the Select object + multiSelect = Select(selectElement) + + # Select "HTML" using visible text + multiSelect.select_by_visible_text("HTML") + # Select 4th, 5th, and 6th index options + for i in range(3, 5): + multiSelect.select_by_index(i) + # Select "Node" using value attribute + multiSelect.select_by_value("nodejs") + # Print the selected options + selectedOptions = multiSelect.all_selected_options + print("Selected options are: ") + for option in selectedOptions: + print(option.text) + + # Deselect the 5th index option + multiSelect.deselect_by_index(4) + # Print the selected options + selectedOptions = multiSelect.all_selected_options + print("Selected options are: ") + for option in selectedOptions: + print(option.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity18.java b/Selenium/Activities/Activity18.java new file mode 100644 index 0000000000..0600f9c3ab --- /dev/null +++ b/Selenium/Activities/Activity18.java @@ -0,0 +1,36 @@ +package Activities; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity18 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/alerts"); + // Print the title of the page + System.out.println("Page title is: " + driver.getTitle()); + + //Find the button to open a SIMPLE alert and click it. + driver.findElement(By.id("simple")).click(); + + //Switch the focus from the main window to the Alert box and get the text in it and print it. + Alert simpleAlert = driver.switchTo().alert(); + System.out.println("Alert message on page is: "+ simpleAlert.getText()); + + //Close the alert once with OK. + simpleAlert.accept(); + + //Display the message + System.out.println("Result message is : "+ driver.findElement(By.id("result")).getText()); + + //Close the page + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity18.py b/Selenium/Activities/Activity18.py new file mode 100644 index 0000000000..ae2e8a0e2b --- /dev/null +++ b/Selenium/Activities/Activity18.py @@ -0,0 +1,30 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/alerts") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find and click the button to open the alert + driver.find_element(By.ID, "simple").click() + + # Switch focus to the alert + simpleAlert = wait.until(EC.alert_is_present()) + + # Print the text in the alert + alertText = simpleAlert.text + print("Text in alert: " + alertText) + + # Close the alert by clicking OK + simpleAlert.accept() + + # Print the message + print(driver.find_element(By.ID, "result").text) \ No newline at end of file diff --git a/Selenium/Activities/Activity19.java b/Selenium/Activities/Activity19.java new file mode 100644 index 0000000000..da898b8683 --- /dev/null +++ b/Selenium/Activities/Activity19.java @@ -0,0 +1,52 @@ +package Activities; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity19 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/alerts"); + // Print the title of the page + System.out.println("Page title is: " + driver.getTitle()); + + //Find the button to open a CONFIRM alert and click it. + driver.findElement(By.id("confirmation")).click(); + + //Switch the focus from the main window to the Alert box and get the text in it and print it. + Alert simpleAlert = driver.switchTo().alert(); + System.out.println("Alert message on page is: "+ simpleAlert.getText()); + + //Close the alert once with Ok. + simpleAlert.accept(); + + //Display the result message + System.out.println("Result message is : "+ driver.findElement(By.id("result")).getText()); + + // again clicking the alert but with we are cancelling + + //Find the button to open a CONFIRM alert and click it. + driver.findElement(By.id("confirmation")).click(); + + //Switch the focus from the main window to the Alert box and get the text in it and print it. + Alert confirmAlert = driver.switchTo().alert(); + System.out.println("Alert message on page is: "+ simpleAlert.getText()); + + //Close the alert once with Cancel. + confirmAlert.dismiss(); + + //Display the result message + System.out.println("Result message is : "+ driver.findElement(By.id("result")).getText()); + + //Close the browser. + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity19.py b/Selenium/Activities/Activity19.py new file mode 100644 index 0000000000..7044b9debb --- /dev/null +++ b/Selenium/Activities/Activity19.py @@ -0,0 +1,30 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/alerts") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find and click the button to open the alert + driver.find_element(By.ID, "confirmation").click() + + # Switch focus to the alert + confirmAlert = wait.until(EC.alert_is_present()) + + # Print the text in the alert + alertText = confirmAlert.text + print("Text in alert: " + alertText) + + # Close the alert by clicking OK + confirmAlert.dismiss() + + # Print the message + print(driver.find_element(By.ID, "result").text) \ No newline at end of file diff --git a/Selenium/Activities/Activity2.java b/Selenium/Activities/Activity2.java new file mode 100644 index 0000000000..e91bc733fa --- /dev/null +++ b/Selenium/Activities/Activity2.java @@ -0,0 +1,35 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity2 { + + public static void main(String[] args) { + // initialize WebDriver + WebDriver driver = new FirefoxDriver(); //ChromeDriver() , EdgeDriver() + + // open the web page + driver.get("https://training-support.net/webelements/login-form"); + + //verify the title to check if we are in right page or not + System.out.println("Page Title is: "+ driver.getTitle()); + + //interact with elements in page + driver.findElement(By.id("username")).sendKeys("admin"); + driver.findElement(By.id("password")).sendKeys("password"); + driver.findElement(By.cssSelector("button.svelte-1pdjkmx")).click(); + + String message = driver.findElement(By.tagName("h1")).getText(); + System.out.println(message); + + String message1 = driver.findElement(By.tagName("h2")).getText(); + System.out.println(message1); + + //Close + //driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity2.py b/Selenium/Activities/Activity2.py new file mode 100644 index 0000000000..af67b5fbd8 --- /dev/null +++ b/Selenium/Activities/Activity2.py @@ -0,0 +1,29 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/login-form") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the username field + username = driver.find_element(By.ID, "username") + # Find the password field + password = driver.find_element(By.ID, "password") + + # Enter the given credentials + # Enter username + username.send_keys("admin") + # Enter password + password.send_keys("password") + + # Find the login button + login = driver.find_element(By.XPATH, "//button[text()='Submit']") + login.click() + + # Print the login message + message = driver.find_element(By.CSS_SELECTOR, "h1.text-center") + print("Login message: ", message.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity20.java b/Selenium/Activities/Activity20.java new file mode 100644 index 0000000000..4aecccca9a --- /dev/null +++ b/Selenium/Activities/Activity20.java @@ -0,0 +1,39 @@ +package Activities; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity20 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/alerts"); + // Print the title of the page + System.out.println("Page title is: " + driver.getTitle()); + + //Find the button to open a CONFIRM alert and click it. + driver.findElement(By.id("prompt")).click(); + + //Switch the focus from the main window to the Alert box and get the text in it and print it. + Alert promptAlert = driver.switchTo().alert(); + System.out.println("Alert message on page is: "+ promptAlert.getText()); + + // Type text into the alert + promptAlert.sendKeys("Awesome!"); + // Thread.sleep(5000); + + //Close the alert once with Ok. + promptAlert.accept(); + + //Display the result message + System.out.println("Result message is : "+ driver.findElement(By.id("result")).getText()); + + + } + +} diff --git a/Selenium/Activities/Activity20.py b/Selenium/Activities/Activity20.py new file mode 100644 index 0000000000..72f60b9fc1 --- /dev/null +++ b/Selenium/Activities/Activity20.py @@ -0,0 +1,33 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/alerts") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find and click the button to open the alert + driver.find_element(By.ID, "prompt").click() + + # Switch focus to the alert + promptAlert = wait.until(EC.alert_is_present()) + + # Print the text in the alert + alertText = promptAlert.text + print("Text in alert: " + alertText) + + # Type text in the prompt alert + promptAlert.send_keys("Awesome!") + + # Close the alert by clicking OK + promptAlert.accept() + + # Print the message + print(driver.find_element(By.ID, "result").text) \ No newline at end of file diff --git a/Selenium/Activities/Activity21.java b/Selenium/Activities/Activity21.java new file mode 100644 index 0000000000..59afdf2ce6 --- /dev/null +++ b/Selenium/Activities/Activity21.java @@ -0,0 +1,63 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity21 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + // Create the Wait object + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open the page + driver.get("https://training-support.net/webelements/tabs"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + // Print the handle of the parent window + System.out.println("Current tab: " + driver.getWindowHandle()); + + // Find button to open new tab + wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='Open A New Tab']"))).click(); + // Wait for the second tab to open + wait.until(ExpectedConditions.numberOfWindowsToBe(2)); + // Print all window handles + System.out.println("Currently open windows: " + driver.getWindowHandles()); + + // Switch focus to the latest tab + for (String handle : driver.getWindowHandles()) { + driver.switchTo().window(handle); + } + + // Wait for the new page to load + wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(), 'Another One')]"))); + // Print the handle of the current tab + System.out.println("Current tab: " + driver.getWindowHandle()); + // Print the title and heading of the new page + System.out.println("New Page title: " + driver.getTitle()); + System.out.println("New Page message: " + driver.findElement(By.cssSelector("h2.mt-5")).getText()); + // Find and click the button on page to open another tab + driver.findElement(By.xpath("//button[contains(text(), 'Another One')]")).click(); + + // Wait for new tab to open + wait.until(ExpectedConditions.numberOfWindowsToBe(3)); + // Switch focus + for (String handle : driver.getWindowHandles()) { + driver.switchTo().window(handle); + } + // Print the title and heading of the new page + System.out.println("New Page title: " + driver.getTitle()); + System.out.println("New Page message: " + driver.findElement(By.cssSelector("h2.mt-5")).getText()); + + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity21.py b/Selenium/Activities/Activity21.py new file mode 100644 index 0000000000..c80b0a3fe6 --- /dev/null +++ b/Selenium/Activities/Activity21.py @@ -0,0 +1,40 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/tabs") + # Print the title of the page + print("Page title is: ", driver.title) + # Print the handle of the parent window + print("Current tab: ", driver.current_window_handle) + + # Find button to open new tab + wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Open A New Tab']"))).click() + # Wait for the second tab to open + wait.until(EC.number_of_windows_to_be(2)) + # Print all window handles + print("Currently open windows: ", driver.window_handles) + driver.switch_to.window(driver.window_handles[1]) + + # Wait for the new page to load + wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'Another One')]"))) + # Print the handle of the current tab + print("Current tab: ", driver.current_window_handle) + # Print the title and heading of the new page + print("New Page title: ", driver.title) + print("New Page message: ", driver.find_element(By.CSS_SELECTOR, "h2.mt-5").text) + # Find and click the button on page to open another tab + driver.find_element(By.XPATH, "//button[contains(text(), 'Another One')]").click() + + # Wait for new tab to open + wait.until(EC.number_of_windows_to_be(3)) + # Switch focus + for handle in driver.window_handles: + driver.switch_to.window(driver.window_handles[2]) \ No newline at end of file diff --git a/Selenium/Activities/Activity22.java b/Selenium/Activities/Activity22.java new file mode 100644 index 0000000000..c3adf4cb43 --- /dev/null +++ b/Selenium/Activities/Activity22.java @@ -0,0 +1,48 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity22 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + // Create the Wait object + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + // Open the page + driver.get("https://training-support.net/webelements/popups"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the launcher button and click it + driver.findElement(By.id("launcher")).click(); + + // Wait for the modal to appear + wait.until(ExpectedConditions.elementToBeClickable(By.id("username"))); + + // Find the input fields + WebElement username = driver.findElement(By.id("username")); + WebElement password = driver.findElement(By.id("password")); + // Enter the credentials + username.sendKeys("admin"); + password.sendKeys("password"); + // Click the submit button + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Print the success message + String message = driver.findElement(By.cssSelector("h2.text-center")).getText(); + System.out.println("Login message: " + message); + + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity22.py b/Selenium/Activities/Activity22.py new file mode 100644 index 0000000000..ab5c77298f --- /dev/null +++ b/Selenium/Activities/Activity22.py @@ -0,0 +1,32 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.wait import WebDriverWait + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the wait variable + wait = WebDriverWait(driver, timeout=10) + # Navigate to the URL + driver.get("https://training-support.net/webelements/popups") + # Print the title of the page + print("Page title is: ", driver.title) + # Find the launcher button and click it + driver.find_element(By.ID, "launcher").click() + + # Wait for the modal to appear + wait.until(EC.element_to_be_clickable((By.ID, "username"))) + + # Find the input fields + username = driver.find_element(By.ID, "username") + password = driver.find_element(By.ID, "password") + # Enter the credentials + username.send_keys("admin") + password.send_keys("password") + # Click the submit button + driver.find_element(By.XPATH, "//button[text()='Submit']").click() + + # Print the success message + message = driver.find_element(By.CSS_SELECTOR, "h2.text-center").text + print("Login message: " + message) \ No newline at end of file diff --git a/Selenium/Activities/Activity3.java b/Selenium/Activities/Activity3.java new file mode 100644 index 0000000000..fa029969ee --- /dev/null +++ b/Selenium/Activities/Activity3.java @@ -0,0 +1,45 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class Activity3 { + + public static void main(String[] args) { + // initialize WebDriver + WebDriver driver = new FirefoxDriver(); //ChromeDriver() , EdgeDriver() + //driver.manage().implicitlyWait(Duration.ofSeconds(10); + WebDriverWait wait = new WebDriverWait(driver,Duration.ofSeconds(10)); + // open the web page + driver.get("https://training-support.net/webelements/login-form"); + + //verify the title to check if we are in right page or not + System.out.println("Page Title is: "+ driver.getTitle()); + + //interact with elements in page + driver.findElement(By.xpath("//input[@id='username']")).sendKeys("admin"); + + + driver.findElement(By.xpath("//input[@id='password']")).sendKeys("password"); + + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h1[contains(text(), ' Success!')]"))); + // Print the confirmation message + String message = driver.findElement(By.xpath("//h1[contains(text(), ' Success!')]")).getText(); + System.out.println("Login Page title is: "+ message); + + String message1 = driver.findElement(By.xpath("//h2[contains(@class,'text-gray')]")).getText(); + System.out.println("Login Page title is: "+ message1); + + //Close + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity3.py b/Selenium/Activities/Activity3.py new file mode 100644 index 0000000000..6bf6a98b8e --- /dev/null +++ b/Selenium/Activities/Activity3.py @@ -0,0 +1,29 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/login-form") + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the username field + username = driver.find_element(By.XPATH, "//input[@id='username']") + # Find the password field + password = driver.find_element(By.XPATH, "//input[@id='password']") + + # Enter the given credentials + # Enter username + username.send_keys("admin") + # Enter password + password.send_keys("password") + + # Find the login button + login = driver.find_element(By.XPATH, "//button[text()='Submit']") + login.click() + + # Print the login message + message = driver.find_element(By.XPATH, "//h1[contains(@class, 'text-center')]") + print("Login message: ", message.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity4.java b/Selenium/Activities/Activity4.java new file mode 100644 index 0000000000..8fa2ac63a2 --- /dev/null +++ b/Selenium/Activities/Activity4.java @@ -0,0 +1,41 @@ +package Activities; + + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.Color; + +public class Activity4 { + + public static void main(String[] args) { + // initialize WebDriver + WebDriver driver = new FirefoxDriver(); + + // open the web page + driver.get("https://training-support.net/webelements/target-practice"); + + //verify the title to check if we are in right page or not + System.out.println("Page Title is: "+ driver.getTitle()); + + //String header3 = driver.findElement(By.xpath("//h3[contains(@class,'text-3xl font-bold text-orange-600')]")).getText(); + String header3 = driver.findElement(By.xpath("//h3[@class = 'text-3xl font-bold text-orange-600']")).getText(); + System.out.println(header3); + // Find the 5th header and print its color + Color fifthHeaderColor = Color.fromString(driver.findElement(By.xpath("//h5[contains(text(), '#5')]")).getCssValue("color")); + System.out.println("Color as RGB: " + fifthHeaderColor.asRgb()); + System.out.println("Color as hexcode: " + fifthHeaderColor.asHex()); + + // Find the violet button and print its classes + String purpleButtonClass = driver.findElement(By.xpath("//button[text()='Purple']")).getDomAttribute("class"); + System.out.println(purpleButtonClass); + + // Find the grey button and print its text + String slateButtonText = driver.findElement(By.xpath("//button[contains(@class, 'slate')]")).getText(); + System.out.println(slateButtonText); + + // Close the browser + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity4.py b/Selenium/Activities/Activity4.py new file mode 100644 index 0000000000..e20070e9c8 --- /dev/null +++ b/Selenium/Activities/Activity4.py @@ -0,0 +1,29 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By +from selenium.webdriver.support.color import Color + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/target-practice") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the 3rd header element on the page using XPath + third_heading = driver.find_element(By.XPATH, "//h3[contains(text(), '#3')]") + print("Third heading text is: ", third_heading.text) + + # Find the 5th header element on the page using XPath + fifth_heading_color = Color.from_string(driver.find_element(By.XPATH, "//h5[contains(text(), '#5')]").value_of_css_property("color")) + print("Fifth heading colour as Hexcode: ", fifth_heading_color.hex) + print("Fifth heading colour as RGB: ", fifth_heading_color.rgb) + + # Find the Purple button element on the page + purple_button = driver.find_element(By.XPATH, "//button[text()='Purple']") + print("Purple button's classes are: ", purple_button.get_attribute("class")) + + # Find the Slate button element on the page + slate_button = driver.find_element(By.XPATH, "//button[contains(@class, 'slate')]") + print("Text in slate button is: ", slate_button.text) \ No newline at end of file diff --git a/Selenium/Activities/Activity5.java b/Selenium/Activities/Activity5.java new file mode 100644 index 0000000000..7e34c2b756 --- /dev/null +++ b/Selenium/Activities/Activity5.java @@ -0,0 +1,41 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity5 { + + public static void main(String[] args) { + // initialize WebDriver + WebDriver driver = new FirefoxDriver(); //ChromeDriver() , EdgeDriver() + + // open the web page + driver.get("https://training-support.net/webelements/dynamic-controls"); + + //verify the title to check if we are in right page or not + System.out.println("Page Title is: "+ driver.getTitle()); + + // Find the checkbox and make sure it is visible + WebElement checkbox = driver.findElement(By.id("checkbox")); + System.out.println("Checkbox is visible? " + checkbox.isDisplayed()); + + // Find the button to toggle it and click it + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + + // Check if it is visible + System.out.println("Checkbox is visible? " + checkbox.isDisplayed()); + + // Toggle the checkbox and click it + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + + // Check if it is selected + System.out.println("Checkbox is visible? " + checkbox.isDisplayed()); + + //Close + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity5.py b/Selenium/Activities/Activity5.py new file mode 100644 index 0000000000..7ad28edf31 --- /dev/null +++ b/Selenium/Activities/Activity5.py @@ -0,0 +1,23 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-controls") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the checkbox + checkbox = driver.find_element(By.ID, "checkbox") + # Find the checkbox toggle button + checkbox_toggle = driver.find_element(By.XPATH, "//button[text()='Toggle Checkbox']") + # Verify if the checkbox is displayed or not + print("Checkbox is visible: ", checkbox.is_displayed()) + + # Click the checkbox_toggle button to hide checkbox + checkbox_toggle.click() + # Verify again if the checkbox is displayed or not + print("Checkbox is visible: ", checkbox.is_displayed()) \ No newline at end of file diff --git a/Selenium/Activities/Activity6.java b/Selenium/Activities/Activity6.java new file mode 100644 index 0000000000..4a1c71d73d --- /dev/null +++ b/Selenium/Activities/Activity6.java @@ -0,0 +1,39 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; + + +public class Activity6 { + + public static void main(String[] args) { + // initialize WebDriver + WebDriver driver = new FirefoxDriver(); //ChromeDriver() , EdgeDriver() + + // open the web page + driver.get("https://training-support.net/webelements/dynamic-controls"); + + //verify the title to check if we are in right page or not + System.out.println("Page Title is: "+ driver.getTitle()); + + // Find the checkbox + WebElement checkbox = driver.findElement(By.id("checkbox")); + // Click it + checkbox.click(); + // Check if it is selected + System.out.println("Checkbox is selected: " + checkbox.isSelected()); + // Click the checkbox again + checkbox.click(); + // Check if it is selected + System.out.println("Checkbox is selected: " + checkbox.isSelected()); + + + //Close + driver.quit(); + + + } + +} diff --git a/Selenium/Activities/Activity6.py b/Selenium/Activities/Activity6.py new file mode 100644 index 0000000000..dd49b16fbb --- /dev/null +++ b/Selenium/Activities/Activity6.py @@ -0,0 +1,22 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-controls") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the checkbox + checkbox = driver.find_element(By.ID, "checkbox") + # Click it + checkbox.click() + # Verify if the checkbox is selected or not + print("Checkbox is visible: ", checkbox.is_selected()) + # Click it again + checkbox.click() + # Verify again if the checkbox is selected or not + print("Checkbox is visible: ", checkbox.is_selected()) \ No newline at end of file diff --git a/Selenium/Activities/Activity7.java b/Selenium/Activities/Activity7.java new file mode 100644 index 0000000000..86aecbd201 --- /dev/null +++ b/Selenium/Activities/Activity7.java @@ -0,0 +1,39 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity7 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + // Open the page + driver.get("https://training-support.net/webelements/dynamic-controls"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the text field + WebElement textbox = driver.findElement(By.id("textInput")); + // Check if it is enabled + System.out.println("Input field is enabled: " + textbox.isEnabled()); + + // Click the toggle button to enable it + driver.findElement(By.id("textInputButton")).click(); + + // Check if the text field is enabled + System.out.println("Input field is enabled: " + textbox.isEnabled()); + + // Type something in to it + textbox.sendKeys("Hello"); + + System.out.println(textbox.getDomProperty("value")); + + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity7.py b/Selenium/Activities/Activity7.py new file mode 100644 index 0000000000..21ba58fec6 --- /dev/null +++ b/Selenium/Activities/Activity7.py @@ -0,0 +1,20 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Navigate to the URL + driver.get("https://training-support.net/webelements/dynamic-controls") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the checkbox + textbox = driver.find_element(By.ID, "textInput") + # Verify if the checkbox is enabled or not + print("Textbox is enabled: ", textbox.is_enabled()) + # Click it again + driver.find_element(By.ID, "textInputButton").click() + # Verify again if the textbox is enabled or not + print("Textbox is enabled: ", textbox.is_enabled()) \ No newline at end of file diff --git a/Selenium/Activities/Activity8.java b/Selenium/Activities/Activity8.java new file mode 100644 index 0000000000..1f76c18fcf --- /dev/null +++ b/Selenium/Activities/Activity8.java @@ -0,0 +1,53 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; + +public class Activity8 { + + public static void main(String[] args) { + // initialize WebDriver + WebDriver driver = new FirefoxDriver(); //ChromeDriver() , EdgeDriver() + Actions builder = new Actions(driver); + // open the web page + driver.get("https://training-support.net/webelements/mouse-events"); + + //verify the title to check if we are in right page or not + System.out.println("Page Title is: "+ driver.getTitle()); + + // Find the elements that can be clicked + WebElement cargoLock = driver.findElement(By.xpath("//h1[text()='Cargo.lock']")); + WebElement cargoToml = driver.findElement(By.xpath("//h1[text()='Cargo.toml']")); + WebElement srcButton = driver.findElement(By.xpath("//h1[text()='src']")); + WebElement targetButton = driver.findElement(By.xpath("//h1[text()='target']")); + + // Perform left click on Cargo.lock and then on Cargo.toml + builder.click(cargoLock).pause(Duration.ofSeconds(2)).click(cargoToml).pause(2000).build().perform(); + + String result = driver.findElement(By.id("result")).getText(); + + System.out.println(result); + + //Double click on the src button. + builder.doubleClick(srcButton).pause(Duration.ofSeconds(2)).pause(Duration.ofSeconds(2)).contextClick(targetButton).pause(Duration.ofSeconds(2)).perform(); + + builder.click(driver.findElement(By.xpath("//span[text()='Open']"))).pause(Duration.ofSeconds(1)).build().perform(); + + + result = driver.findElement(By.id("result")).getText(); + + System.out.println(result); + //Then right click on the target button and select open. + //Print the confirmation text at the end of the sequence. + + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity8.py b/Selenium/Activities/Activity8.py new file mode 100644 index 0000000000..89d1f6a4c5 --- /dev/null +++ b/Selenium/Activities/Activity8.py @@ -0,0 +1,34 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver import ActionChains +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the actions variable + actions = ActionChains(driver) + # Navigate to the URL + driver.get("https://training-support.net/webelements/mouse-events") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Find the elements that can be clicked + cargoLock = driver.find_element(By.XPATH, "//h1[text()='Cargo.lock']") + cargoToml = driver.find_element(By.XPATH, "//h1[text()='Cargo.toml']") + srcButton = driver.find_element(By.XPATH, "//h1[text()='src']") + targetButton = driver.find_element(By.XPATH, "//h1[text()='target']") + + # Perform left click on Cargo.lock and then on Cargo.toml + actions.click(cargoLock).pause(1).move_to_element(cargoToml).pause(5).click(cargoToml).perform() + # Print the front side text + actionMessage = driver.find_element(By.ID, "result").text + print(actionMessage) + + # Perform double click on src then right click on target + actions.double_click(srcButton).pause(3).pause(5).context_click(targetButton).pause(3).perform() + # and then open it + actions.click(driver.find_element(By.XPATH, ("//div[@id='menu']/div/ul/li[1]"))).pause(5).perform() + # Print the front side text + actionMessage = driver.find_element(By.ID, "result").text + print(actionMessage) \ No newline at end of file diff --git a/Selenium/Activities/Activity9.java b/Selenium/Activities/Activity9.java new file mode 100644 index 0000000000..fbebb0be55 --- /dev/null +++ b/Selenium/Activities/Activity9.java @@ -0,0 +1,34 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.Keys; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.interactions.Actions; + +public class Activity9 { + + public static void main(String[] args) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + // Create the Actions object + Actions builder = new Actions(driver); + + // Open the page + driver.get("https://training-support.net/webelements/keyboard-events"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Press the key + builder.sendKeys("This is coming from Selenium").sendKeys(Keys.RETURN).build().perform(); + + // Print the message from the page + String pageText = driver.findElement(By.cssSelector("h1.mt-3")).getText(); + System.out.println(pageText); + + // Close the browser + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity9.py b/Selenium/Activities/Activity9.py new file mode 100644 index 0000000000..d275077e8b --- /dev/null +++ b/Selenium/Activities/Activity9.py @@ -0,0 +1,21 @@ +# Import webdriver from selenium +from selenium import webdriver +from selenium.webdriver import Keys, ActionChains +from selenium.webdriver.common.by import By + +# Start the Driver +with webdriver.Firefox() as driver: + # Declare the actions variable + actions = ActionChains(driver) + # Navigate to the URL + driver.get("https://training-support.net/webelements/keyboard-events") + + # Print the title of the page + print("Page title is: ", driver.title) + + # Press the key + actions.send_keys("This is coming from Selenium").send_keys(Keys.RETURN).perform() + + # Print the message from the page + pageText = driver.find_element(By.CSS_SELECTOR, "h1.mt-3").text + print(pageText) \ No newline at end of file diff --git a/Selenium/Project/TestActivity1.java b/Selenium/Project/TestActivity1.java new file mode 100644 index 0000000000..46b3ca75b8 --- /dev/null +++ b/Selenium/Project/TestActivity1.java @@ -0,0 +1,38 @@ +package Activities; + +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity1 { + // declare class objects + WebDriver driver; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // open the page + driver.get("https://alchemy.hguy.co/lms"); + + } + + @Test + public void testCase1() { + // Assert page title + Assert.assertEquals(driver.getTitle(), "Alchemy LMS – An LMS Application"); + } + + // create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + } + +} diff --git a/Selenium/Project/TestActivity2.java b/Selenium/Project/TestActivity2.java new file mode 100644 index 0000000000..c531e9fb41 --- /dev/null +++ b/Selenium/Project/TestActivity2.java @@ -0,0 +1,40 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity2 { + // declare class objects + WebDriver driver; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // open the page + driver.get("https://alchemy.hguy.co/lms"); + + } + // Read the heading of the website and verify the text + @Test + public void testCase1() { + String message = driver.findElement(By.tagName("h1")).getText(); + System.out.println(message); + + Assert.assertEquals(message, "Learn from Industry Experts"); + } + + // create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + } +} diff --git a/Selenium/Project/TestActivity3.java b/Selenium/Project/TestActivity3.java new file mode 100644 index 0000000000..4eb920955b --- /dev/null +++ b/Selenium/Project/TestActivity3.java @@ -0,0 +1,40 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity3 { + // declare class objects + WebDriver driver; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // open the page + driver.get("https://alchemy.hguy.co/lms"); + + } + //Read the title of the first info box on the website and verify the text + @Test + public void testCase1() { + String message = driver.findElement(By.xpath("//h3[text()=' Actionable Training ']")).getText(); + System.out.println(message); + + Assert.assertEquals(message, "Actionable Training"); + } + + // create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + } +} diff --git a/Selenium/Project/TestActivity4.java b/Selenium/Project/TestActivity4.java new file mode 100644 index 0000000000..cdb358b3b0 --- /dev/null +++ b/Selenium/Project/TestActivity4.java @@ -0,0 +1,43 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity4 { +// declare class objects + WebDriver driver; + +// create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // open the page + driver.get("https://alchemy.hguy.co/lms"); + + } + +// Read the title of the second most popular course on the website and verify the text + + @Test + public void testCase1() { + String message = driver.findElement(By.xpath("//h3[text()='Email Marketing Strategies']")).getText(); + System.out.println(message); + + Assert.assertEquals(message, "Email Marketing Strategies"); + } + +// create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + } + +} diff --git a/Selenium/Project/TestActivity5.java b/Selenium/Project/TestActivity5.java new file mode 100644 index 0000000000..1c0f6df3dd --- /dev/null +++ b/Selenium/Project/TestActivity5.java @@ -0,0 +1,51 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity5 { + // declare class objects + WebDriver driver; + WebDriverWait wait; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // Wait Initialization + wait = new WebDriverWait(driver,Duration.ofSeconds(10)); + // open the page + driver.get("https://alchemy.hguy.co/lms"); + + } + + // Navigate to the “My Account” page on the site. + + @Test + public void testCase1() { + WebElement linkElement = driver.findElement(By.linkText("My Account")); + linkElement.click(); + System.out.println(driver.getTitle()); + + Assert.assertEquals(driver.getTitle(),"My Account – Alchemy LMS"); + } + + // create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + } + +} diff --git a/Selenium/Project/TestActivity6.java b/Selenium/Project/TestActivity6.java new file mode 100644 index 0000000000..e73c29c876 --- /dev/null +++ b/Selenium/Project/TestActivity6.java @@ -0,0 +1,72 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity6 { + // declare class objects + WebDriver driver; + WebDriverWait wait; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // Wait Initialization + wait = new WebDriverWait(driver,Duration.ofSeconds(10)); + // open the page + driver.get("https://alchemy.hguy.co/lms"); + + } + +// Navigate to the “My Account” page on the site. + + @Test + public void testCase1() { + WebElement linkElement = driver.findElement(By.linkText("My Account")); + linkElement.click(); + System.out.println(driver.getTitle()); + + Assert.assertEquals(driver.getTitle(),"My Account – Alchemy LMS"); + } + +// Login to the account + @Test + public void testCase2() { + + driver.findElement(By.cssSelector("a.ld-login")).click(); + + WebElement userId = driver.findElement(By.id("user_login")); + WebElement password = driver.findElement(By.id("user_pass")); + + userId.sendKeys("root"); + password.sendKeys("pa$$w0rd"); + + driver.findElement(By.id("wp-submit")).click(); + + //Wait + System.out.println(driver.getTitle()); + + Assert.assertEquals(driver.getTitle(),"My Account – Alchemy LMS"); + + } + +// create a tear down function + @AfterClass + public void teardown() { +// close the driver + driver.quit(); + } + +} diff --git a/Selenium/Project/TestActivity7.java b/Selenium/Project/TestActivity7.java new file mode 100644 index 0000000000..532611af75 --- /dev/null +++ b/Selenium/Project/TestActivity7.java @@ -0,0 +1,60 @@ +package Activities; + +import java.time.Duration; +import java.util.List; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity7 { + // declare class objects + WebDriver driver; + WebDriverWait wait; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // Wait Initialization + wait = new WebDriverWait(driver,Duration.ofSeconds(10)); + // open the page + driver.get("https://alchemy.hguy.co/lms"); + + } + + // Navigate to the “My Account” page on the site. + + @Test + public void testCase1() { + WebElement linkElement = driver.findElement(By.linkText("All Courses")); + linkElement.click(); + System.out.println(driver.getTitle()); + + + // Find all the courses on the page + List courses = driver.findElements(By.cssSelector("p.ld_course_grid_button")); + + // Print the number of courses + System.out.println("Number of courses: " + courses.size()); + + Assert.assertEquals(driver.getTitle(),"All Courses – Alchemy LMS"); + + } + + // create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + } + +} diff --git a/Selenium/Project/TestActivity8.java b/Selenium/Project/TestActivity8.java new file mode 100644 index 0000000000..e1d3993d7f --- /dev/null +++ b/Selenium/Project/TestActivity8.java @@ -0,0 +1,74 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity8 { + // declare class objects + WebDriver driver; + WebDriverWait wait; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // Wait Initialization + wait = new WebDriverWait(driver,Duration.ofSeconds(10)); + // open the page + driver.get("https://alchemy.hguy.co/lms"); + + } + + // Navigate to the “My Account” page on the site. + + @Test + public void testCase1() { + WebElement linkElement = driver.findElement(By.linkText("Contact")); + linkElement.click(); + System.out.println(driver.getTitle()); + + Assert.assertEquals(driver.getTitle(),"Contact – Alchemy LMS"); + } + + // Login to the account + @Test + public void testCase2() { + + + WebElement fullName = driver.findElement(By.id("wpforms-8-field_0")); + WebElement mailId = driver.findElement(By.id("wpforms-8-field_1")); + WebElement subject = driver.findElement(By.id("wpforms-8-field_3")); + WebElement comments = driver.findElement(By.id("wpforms-8-field_2")); + + fullName.sendKeys("test"); + mailId.sendKeys("test@gmail.com"); + subject.sendKeys("test"); + comments.sendKeys("test"); + + driver.findElement(By.id("wpforms-submit-8")).click(); + + String message = driver.findElement(By.id("wpforms-confirmation-8")).getText(); + System.out.println(message); + + Assert.assertEquals(message,"Thanks for contacting us! We will be in touch with you shortly."); + + } + + // create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + } +} diff --git a/Selenium/Project/TestActivity9.java b/Selenium/Project/TestActivity9.java new file mode 100644 index 0000000000..f382543da5 --- /dev/null +++ b/Selenium/Project/TestActivity9.java @@ -0,0 +1,127 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity9 { + // declare class objects + WebDriver driver; + WebDriverWait wait; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // Wait Initialization + wait = new WebDriverWait(driver,Duration.ofSeconds(10)); + // open the page + driver.get("https://alchemy.hguy.co/lms"); + + } + @Test + // Home page + public void testCase1() { + WebElement linkElement = driver.findElement(By.linkText("My Account")); + linkElement.click(); + System.out.println(driver.getTitle()); + + Assert.assertEquals(driver.getTitle(),"My Account – Alchemy LMS"); + } + @Test + // Navigate to the “My Account” page on the site and Login to the account + public void testCase2() { + + driver.findElement(By.cssSelector("a.ld-login")).click(); + + WebElement userId = driver.findElement(By.id("user_login")); + WebElement password = driver.findElement(By.id("user_pass")); + + userId.sendKeys("root"); + password.sendKeys("pa$$w0rd"); + + driver.findElement(By.id("wp-submit")).click(); + + //Wait + System.out.println(driver.getTitle()); + + Assert.assertEquals(driver.getTitle(),"My Account – Alchemy LMS"); + + } + @Test + // Navigating to all courses + public void testCase3() { + WebElement linkElement = driver.findElement(By.linkText("All Courses")); + linkElement.click(); + System.out.println(driver.getTitle()); + + Assert.assertEquals(driver.getTitle(),"All Courses – Alchemy LMS"); + } + + // Navigating to Social Media Marketing course + @Test + public void testCase4() { + + driver.findElement(By.xpath("/html/body/div/div/div/div/main/article/div/section[2]/div[2]/div/div/div/div[1]/article/div[2]/p[2]/a")).click(); + + System.out.println(driver.getTitle()); + Assert.assertEquals(driver.getTitle(),"Social Media Marketing – Alchemy LMS"); + + } + + @Test + // Navigating to course content + public void testCase5() { + + WebElement course = driver.findElements(By.cssSelector("div.ld-item-title")).get(0); + course.click(); + + System.out.println(driver.getTitle()); + Assert.assertEquals(driver.getTitle(),"Developing Strategy – Alchemy LMS"); + + } + + @Test + // Navigating to lesson in the course content + public void testCase6() { + + WebElement lesson = driver.findElements(By.cssSelector("div.ld-lesson-title")).get(1); + lesson.click(); + + System.out.println(driver.getTitle()); + Assert.assertEquals(driver.getTitle(),"Monitoring & Digital Advertising – Alchemy LMS"); + + } + @Test + // finding the next lesson button since course complete option is not available not this lesson + public void testCase7() { + +// WebElement subLession = driver.findElements(By.cssSelector("div.ld-topic-title")).get(0); +// subLession.click(); +// WebElement markComplete = driver.findElements(By.cssSelector("learndash_mark_complete_button")).get(2); +// markComplete.click(); + WebElement nextLession = driver.findElement(By.xpath("/html/body/div[1]/div/div[2]/div[2]/div/div/div[4]/div[2]/a")); + nextLession.click(); + + System.out.println(driver.getTitle()); + Assert.assertEquals(driver.getTitle(),"Investment & Marketing Final Strategies – Alchemy LMS"); + + } + + // create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + } +} diff --git a/Selenium/Project/TestNG.XML b/Selenium/Project/TestNG.XML new file mode 100644 index 0000000000..046c97d9d6 --- /dev/null +++ b/Selenium/Project/TestNG.XML @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TestNG/Activities/Activity4_DemoOne.java b/TestNG/Activities/Activity4_DemoOne.java new file mode 100644 index 0000000000..4c5e8c1871 --- /dev/null +++ b/TestNG/Activities/Activity4_DemoOne.java @@ -0,0 +1,16 @@ +package Activities; + +import org.testng.annotations.Test; + +public class Activity4_DemoOne { + @Test + public void firstTestCase() { + System.out.println("I'm in first test case from demoOne Class"); + } + + @Test + public void secondTestCase() { + System.out.println("I'm in second test case from demoOne Class"); + } + +} diff --git a/TestNG/Activities/Activity4_DemoTwo.java b/TestNG/Activities/Activity4_DemoTwo.java new file mode 100644 index 0000000000..c0cdacd1c9 --- /dev/null +++ b/TestNG/Activities/Activity4_DemoTwo.java @@ -0,0 +1,11 @@ +package Activities; + +import org.testng.annotations.Test; + +public class Activity4_DemoTwo { + @Test + public void TestCase() { + System.out.println("I'm in the test case from DemoTwo Class"); + } + +} diff --git a/TestNG/Activities/TestActivity1.java b/TestNG/Activities/TestActivity1.java new file mode 100644 index 0000000000..7ba812d61a --- /dev/null +++ b/TestNG/Activities/TestActivity1.java @@ -0,0 +1,47 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity1 { + + // declare class objects + WebDriver driver; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // open the page + driver.get("https://training-support.net"); + + } + + // Create test function + @Test(priority = 1) + public void homePageTest() { + // Assert page title + Assert.assertEquals(driver.getTitle(), "Training Support"); + } + + @Test(priority = 2) + public void AboutUsPageTest() { + driver.findElement(By.linkText("About Us")).click(); + Assert.assertEquals(driver.getTitle(), "About Training Support"); + } + + // create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + } + +} diff --git a/TestNG/Activities/TestActivity10.java b/TestNG/Activities/TestActivity10.java new file mode 100644 index 0000000000..c44e3c1591 --- /dev/null +++ b/TestNG/Activities/TestActivity10.java @@ -0,0 +1,108 @@ +package Activities; + +import static org.testng.Assert.assertEquals; +import java.io.FileInputStream; +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class TestActivity10 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void beforeClass() { + driver = new FirefoxDriver(); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open browser + driver.get("https://training-support.net/webelements/simple-form"); + } + + public static List> readExcel(String filePath) { + List> data = new ArrayList>(); + try { + FileInputStream file = new FileInputStream(filePath); + + // Create Workbook instance holding reference to Excel file + XSSFWorkbook workbook = new XSSFWorkbook(file); + + // Get first sheet from the workbook + XSSFSheet sheet = workbook.getSheetAt(0); + + // Iterate through each rows one by one + for (Row cells : sheet) { + // Temp variable + List rowData = new ArrayList(); + for (Cell cell : cells) { + // Store row data + rowData.add(cell.getStringCellValue()); + } + // Store row data in List + data.add(rowData); + } + file.close(); + workbook.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return data; + } + + @DataProvider(name = "Events") + public static Object[][] signUpInfo() { + String filePath = "src/test/resources/details.xlsx"; + List> data = readExcel(filePath); + return new Object[][] { + { data.get(1) }, + { data.get(2) }, + { data.get(3) } + }; + } + + @Test(dataProvider = "Events") + public void registerTest(List rows) throws InterruptedException { + // Find the input fields and enter text + WebElement fullName = driver.findElement(By.id("full-name")); + fullName.sendKeys(rows.get(0)); + + // Enter the email + driver.findElement(By.id("email")).sendKeys(rows.get(1)); + + // Enter the Date of the event + driver.findElement(By.name("event-date")).sendKeys(rows.get(2).replaceAll("\"", "")); + + // Enter additional details + driver.findElement(By.id("additional-details")).sendKeys(rows.get(3)); + + // Click Submit + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Confirm booking + String message = driver.findElement(By.id("action-confirmation")).getText(); + assertEquals(message, "Your event has been scheduled!"); + + // Refresh the page + driver.navigate().refresh(); + } + + @AfterClass + public void tearDown() { + // Close the browser + driver.quit(); + } +} + diff --git a/TestNG/Activities/TestActivity2.java b/TestNG/Activities/TestActivity2.java new file mode 100644 index 0000000000..74d6918c2f --- /dev/null +++ b/TestNG/Activities/TestActivity2.java @@ -0,0 +1,60 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.Assert; +import org.testng.SkipException; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity2 { + // declare class objects + WebDriver driver; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // open the page + driver.get("https://training-support.net/webelements/target-practice"); + + } + + @Test + public void testCase1() { + // Assert page title + Assert.assertEquals(driver.getTitle(), "Selenium: Target Practice"); + } + @Test + public void testCase2() { + // This test case will Fail + WebElement blackButton = driver.findElement(By.cssSelector("button.black")); + Assert.assertTrue(blackButton.isDisplayed()); + Assert.assertEquals(blackButton.getText(), "black"); + } + + @Test(enabled = false) + public void testCase3() { + // This test will be skipped and not counted + String subHeading = driver.findElement(By.className("sub")).getText(); + Assert.assertTrue(subHeading.contains("Practice")); + } + + @Test + public void testCase4() { + // This test will be skipped and will be be shown as skipped + throw new SkipException("Skipping test case"); + } + + // create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + } +} diff --git a/TestNG/Activities/TestActivity3.java b/TestNG/Activities/TestActivity3.java new file mode 100644 index 0000000000..71c448a762 --- /dev/null +++ b/TestNG/Activities/TestActivity3.java @@ -0,0 +1,66 @@ +package Activities; + +import java.time.Duration; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity3 { + // declare class objects + WebDriver driver; + WebDriverWait wait; + + // create a setup function + @BeforeClass + public void setUp() + { + // Driver initialization + driver = new FirefoxDriver(); + // Wait Initialization + wait = new WebDriverWait(driver,Duration.ofSeconds(10)); + // open the page + driver.get("https://training-support.net/webelements/login-form"); + + + } + + @Test + public void testCase1() { + // Assert page title + Assert.assertEquals(driver.getTitle(), "Selenium: Login Form"); + } + @Test + public void testCase2() { + // Find the username and password fields + WebElement username = driver.findElement(By.id("username")); + WebElement password = driver.findElement(By.id("password")); + + // Enter credentials + username.sendKeys("admin"); + password.sendKeys("password"); + + // Click login + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Read login message + String loginMessage = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("h2.text-center"))).getText(); + // String loginMessage = driver.findElement(By.cssSelector("h2.text-center")).getText(); + Assert.assertEquals(loginMessage,"Welcome Back, Admin!"); + } + + // create a tear down function + @AfterClass + public void teardown() { + // close the driver + driver.quit(); + + } +} diff --git a/TestNG/Activities/TestActivity5.java b/TestNG/Activities/TestActivity5.java new file mode 100644 index 0000000000..959786d289 --- /dev/null +++ b/TestNG/Activities/TestActivity5.java @@ -0,0 +1,64 @@ +package Activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.Color; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class TestActivity5 { + WebDriver driver; + + // Include alwaysRun property on the @BeforeClass to make sure the page always opens + @BeforeClass(alwaysRun = true) + public void setUp() { + // Create a new instance of the Firefox driver + driver = new FirefoxDriver(); + + // Open the browser + driver.get("https://training-support.net/webelements/target-practice"); + } + + @Test(groups = { "HeaderTests", "ButtonTests" }) + public void pageTitleTest() { + String title = driver.getTitle(); + System.out.println("Title is: " + title); + Assert.assertEquals(title, "Selenium: Target Practice"); + } + + @Test(dependsOnMethods = { "pageTitleTest" }, groups = { "HeaderTests" }) + public void HeaderTest1() { + WebElement header3 = driver.findElement(By.xpath("//h3[contains(@class, 'orange')]")); + Assert.assertEquals(header3.getText(), "Heading #3"); + } + + @Test(dependsOnMethods = { "pageTitleTest" }, groups = { "HeaderTests" }) + public void HeaderTest2() { + Color header5Color = Color.fromString(driver.findElement(By.cssSelector("h5.text-purple-600")).getCssValue("color")); + Assert.assertEquals(header5Color.asHex(), "#9333ea"); + } + + @Test(dependsOnMethods = { "pageTitleTest" }, groups = { "ButtonTests" }) + public void ButtonTest1() { + WebElement button1 = driver.findElement(By.xpath("//button[contains(@class, 'emerald')]")); + Assert.assertEquals(button1.getText(), "Emerald"); + } + + @Test(dependsOnMethods = { "pageTitleTest" }, groups = { "ButtonTests" }) + public void ButtonTest2() { + Color button2Color = Color.fromString(driver.findElement(By.xpath("//button[contains(text(), 'Purple')]")).getCssValue("color")); + Assert.assertEquals(button2Color.asHex(), "#581c87"); + } + + // Include alwaysRun property on the @AfterClass to make sure the page always + // closes + @AfterClass(alwaysRun = true) + public void tearDown() { + // Close the browser + driver.close(); + } +} \ No newline at end of file diff --git a/TestNG/Activities/TestActivity6.java b/TestNG/Activities/TestActivity6.java new file mode 100644 index 0000000000..a488fe1032 --- /dev/null +++ b/TestNG/Activities/TestActivity6.java @@ -0,0 +1,59 @@ +package Activities; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +public class TestActivity6 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void beforeClass() { + // Initialize the Firefox driver + driver = new FirefoxDriver(); + // Initialize the wait object + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open browser + driver.get("https://training-support.net/webelements/login-form"); + } + + @Test + @Parameters({ "username", "password", "message" }) + public void loginTestCase(String username, String password, @Optional("Login Success!") String message) { + // Find username and password fields + WebElement usernameField = driver.findElement(By.id("username")); + WebElement passwordField = driver.findElement(By.id("password")); + + // Enter credentials + usernameField.sendKeys(username); + passwordField.sendKeys(password); + + // Click the submit button + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + // Wait for the success page to load + wait.until(ExpectedConditions.titleContains("Success")); + + // Assert login message + String loginMessage = driver.findElement(By.cssSelector("h2.text-center")).getText(); + Assert.assertEquals("Welcome Back, Admin!", loginMessage); + } + + @AfterClass + public void afterClass() { + // Close browser + driver.close(); + } +} diff --git a/TestNG/Activities/TestActivity7.java b/TestNG/Activities/TestActivity7.java new file mode 100644 index 0000000000..0262bac2b6 --- /dev/null +++ b/TestNG/Activities/TestActivity7.java @@ -0,0 +1,62 @@ +package Activities; + +import java.time.Duration; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class TestActivity7 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() { + // Initialize driver + driver = new FirefoxDriver(); + // Initialize wait + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + // Open the page + driver.get("https://training-support.net/webelements/login-form"); + } + + @DataProvider(name = "Credentials") + public static Object[][] creds() { + return new Object[][] { + { "admin1", "password1", "Invalid Credentials" }, + { "wrongAdmin", "wrongPassword", "Invalid Credentials" } + }; + } + + @Test(dataProvider = "Credentials") + public void loginTest(String username, String password, String expectedMessage) { + // Find the input fields and the login button + WebElement usernameField = driver.findElement(By.id("username")); + WebElement passwordField = driver.findElement(By.id("password")); + WebElement loginButton = driver.findElement(By.xpath("//button[text()='Submit']")); + + // Clear the input fields + usernameField.clear(); + passwordField.clear(); + // Enter the credentials and click Log in + usernameField.sendKeys(username); + passwordField.sendKeys(password); + loginButton.click(); + + // Assert login message + String loginMessage = driver.findElement(By.id("subheading")).getText(); + Assert.assertEquals(loginMessage, expectedMessage); + } + + @AfterClass + public void tearDown() { + // Close the browser + driver.quit(); + } +} diff --git a/TestNG/Activities/TestActivity9.java b/TestNG/Activities/TestActivity9.java new file mode 100644 index 0000000000..f817d0f516 --- /dev/null +++ b/TestNG/Activities/TestActivity9.java @@ -0,0 +1,118 @@ +package Activities; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.Assert; +import org.testng.Reporter; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class TestActivity9 { + WebDriver driver; + + @BeforeClass + public void setUp() { + // Create a new instance of the Firefox driver + driver = new FirefoxDriver(); + + Reporter.log("Starting Test |"); + // Open browser + driver.get("https://training-support.net/webelements/alerts"); + Reporter.log("Opened Browser |"); + + // Print title of page + Reporter.log("Page title is " + driver.getTitle() + " |"); + } + + @BeforeMethod + public void beforeMethod() { + Reporter.log("Test Case Setup started |"); + driver.switchTo().defaultContent(); + } + + @Test(priority = 1) + public void simpleAlertTestCase() { + Reporter.log("simpleAlertTestCase() started |"); + // Click the button to open a simple alert + driver.findElement(By.id("simple")).click(); + Reporter.log("Simple Alert opened |"); + + // Switch to alert window + Alert simpleAlert = driver.switchTo().alert(); + Reporter.log("Switched foucs to alert |"); + + // Get text in the alert box and print it + String alertText = simpleAlert.getText(); + Reporter.log("Alert text is: " + alertText + " |"); + + // Assertion + Assert.assertEquals("You've just triggered a simple alert!", alertText); + + simpleAlert.accept(); + Reporter.log("Alert closed"); + + Reporter.log("Test case ended |"); + } + + @Test(priority = 2) + public void confirmAlertTestCase() { + Reporter.log("confirmAlertTestCase() started |"); + // Click the button to open a simple alert + driver.findElement(By.id("confirmation")).click(); + Reporter.log("Confirm Alert opened |"); + + // Switch to alert window + Alert confirmAlert = driver.switchTo().alert(); + Reporter.log("Switched foucs to alert |"); + + // Get text in the alert box and print it + String alertText = confirmAlert.getText(); + Reporter.log("Alert text is: " + alertText + " |"); + + // Assertion + Assert.assertEquals("You've just triggered a confirmation alert!", alertText); + + confirmAlert.accept(); + Reporter.log("Alert closed |"); + + Reporter.log("Test case ended |"); + } + + @Test(priority = 3) + public void promptAlertTestCase() { + Reporter.log("promptAlertTestCase() started |"); + // Click the button to open a simple alert + driver.findElement(By.id("prompt")).click(); + Reporter.log("Prompt Alert opened |"); + + // Switch to alert window + Alert promptAlert = driver.switchTo().alert(); + Reporter.log("Switched foucs to alert |"); + + // Get text in the alert box and print it + String alertText = promptAlert.getText(); + Reporter.log("Alert text is: " + alertText + " |"); + + // Assertion + Assert.assertEquals("I'm a Prompt! Type something into me!", alertText); + // Type some text into the prompt + promptAlert.sendKeys("Awesome!"); + Reporter.log("Text entered in prompt alert |"); + // Close the prompt + promptAlert.accept(); + Reporter.log("Alert closed |"); + + Reporter.log("Test case ended |"); + } + + @AfterClass + public void tearDown() { + Reporter.log("Ending Test |"); + // Close the driver + driver.close(); + } +} \ No newline at end of file diff --git a/TestNG/Activities/TestNG.XML b/TestNG/Activities/TestNG.XML new file mode 100644 index 0000000000..1ce6f07301 --- /dev/null +++ b/TestNG/Activities/TestNG.XML @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + diff --git a/TestNG/Activities/TestNG4.XML b/TestNG/Activities/TestNG4.XML new file mode 100644 index 0000000000..4cf0087bdf --- /dev/null +++ b/TestNG/Activities/TestNG4.XML @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file