diff --git a/API/Activities/CalcultaorSOAP.xml b/API/Activities/CalcultaorSOAP.xml new file mode 100644 index 0000000000..f26c5aad72 --- /dev/null +++ b/API/Activities/CalcultaorSOAP.xml @@ -0,0 +1,291 @@ + +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.asmxUTF-8http://www.dneonline.com/calculator.asmx\r + \r + \r + \r + ?\r + ?\r + \r + \r +]]>No AuthorizationNo AuthorizationUTF-8http://www.dneonline.com/calculator.asmx\r + \r + \r + \r + ?\r + ?\r + \r + \r +]]>No AuthorizationNo AuthorizationUTF-8http://www.dneonline.com/calculator.asmx\r + \r + \r + \r + ?\r + ?\r + \r + \r +]]>No AuthorizationNo AuthorizationUTF-8http://www.dneonline.com/calculator.asmx\r + \r + \r + \r + ?\r + ?\r + \r + \r +]]>No AuthorizationNo AuthorizationSEQUENTIALCalculatorSoap12Add<xml-fragment/>UTF-8http://www.dneonline.com/calculator.asmx\r + \r + \r + \r + 25\r + 5\r + \r + \r +]]>200declare namespace ns1='http://tempuri.org/'; + +//ns1:AddResult30falsefalsefalseNo AuthorizationNo AuthorizationCalculatorSoap12Divide<xml-fragment/>UTF-8http://www.dneonline.com/calculator.asmx\r + \r + \r + \r + 20\r + 2\r + \r + \r +]]>200declare namespace ns1='http://tempuri.org/'; + +//ns1:DivideResult10falsefalsefalseNo AuthorizationNo AuthorizationCalculatorSoap12Multiply<xml-fragment/>UTF-8http://www.dneonline.com/calculator.asmx + + + + 10 + 2 + + +]]>200declare namespace ns1='http://tempuri.org/'; + +//ns1:MultiplyResult20falsefalsefalseNo AuthorizationNo AuthorizationCalculatorSoap12Subtract<xml-fragment/>UTF-8http://www.dneonline.com/calculator.asmx + + + + 10 + 2 + + +]]>200declare namespace ns1='http://tempuri.org/'; + +//ns1:SubtractResult8falsefalsefalseNo AuthorizationNo Authorization0aee0df6-d8ef-4dea-8904-a9abb0007bedNONE52e98521-e8ce-4191-b0ec-f59cf9d969b3NONE30970bb8-502b-4b91-9542-18b3ce30f22aNONE25003ab1-7200-4c65-abfe-6f82e6c9102aNONE// 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/DataDriven-using-JDBC.xml b/API/Activities/DataDriven-using-JDBC.xml new file mode 100644 index 0000000000..6fca36565f --- /dev/null +++ b/API/Activities/DataDriven-using-JDBC.xml @@ -0,0 +1,26 @@ + +http://ipwhois.appIPIPTEMPLATEIPapplication/json; charset=utf-8200json:Responsehttp://ipwhois.appIPSEQUENTIALtruetruefalsetruetrue<xml-fragment/>com.mysql.jdbc.Driverjdbc:mysql://db4free.net:3306/fstm1db?user=fstm1db&password=PASS_VALUE6Y6NowPybqFST ConnectionSelect * FROM petData;falsetruetruepetIDpetNamepetStatustruefalse101-1COMPIP0falseIPv4falsefalseIPtruefalse<xml-fragment/>http://ipwhois.apphttp://ipwhois.app/json/200No AuthorizationNo AuthorizationIPcityTransferResponse$['city']city_nameData SinkJSONPATHtruelatitudeResponseGet Request$['latitude']latitudeData SinkJSONPATHtruelongitudeResponseGet Request$['longitude']longitudeData SinkJSONPATHtruecom.mysql.jdbc.Driverjdbc:mysql://db4free.net:3306/fstm1db?user=fstm1db&password=PASS_VALUE6Y6NowPybqFST Connection( Default environment )insert into coordinates(city_name,latitude,longitude) +values (?,?,?);falsecity_nameQuitolatitude-0.1806532longitude-78.4678382Data SourceGet RequesttrueFST Connectioncom.mysql.jdbc.Driverjdbc:mysql://db4free.net:3306/fstm1db?user=fstm1db&password=PASS_VALUE6Y6NowPybq// 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/DataDrivenTest-External-source.xml b/API/Activities/DataDrivenTest-External-source.xml new file mode 100644 index 0000000000..94c997451d --- /dev/null +++ b/API/Activities/DataDrivenTest-External-source.xml @@ -0,0 +1,25 @@ + +http://ipwhois.appIPIPTEMPLATEIPapplication/json; charset=utf-8200json:Responsehttp://ipwhois.appNo AuthorizationNo AuthorizationIPSEQUENTIALC:/Users/0019TE744/Downloads/FST_API/TextFile.txt,trueCp1252falsetruetrueIPaddresstruefalse<xml-fragment/>http://ipwhois.apphttp://ipwhois.app/json/200$['country']"India"falsefalsefalseNo AuthorizationNo AuthorizationIPDataSourceRequest 1trueC:/Users/0019TE744/Downloads/FST_API/Ips_Excel.xlsxA2falsefalsetruetrueIP Addresstruefalse<xml-fragment/>http://ipwhois.apphttp://ipwhois.app/json/200$['country']"India"falsefalsefalseNo AuthorizationNo AuthorizationIPData SourceRequest 1trueFST_Connectioncom.mysql.jdbc.Driverjdbc:mysql://db4free.net:3306/fstm1db?user=fstm1db&password=PASS_VALUE6Y6NowPybq// 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/Git-Hub-Project-readyapi-project_REST.xml b/API/Activities/Git-Hub-Project-readyapi-project_REST.xml new file mode 100644 index 0000000000..fabe982f2c --- /dev/null +++ b/API/Activities/Git-Hub-Project-readyapi-project_REST.xml @@ -0,0 +1,305 @@ + + + + + + + + https://api.github.com + + + + + + + + + application/json; charset=utf-8 + 404 + + keys:Fault + + + application/json + + + + application/json; charset=utf-8 + 201 + + keys:Response + + + + https://api.github.com + + + + + + + + + + + + keyId + keyId + TEMPLATE + keyId + + + + + + application/json; charset=utf-8 + 200 + + ns:Response + + + + https://api.github.com + + + + + keyId + + + + + + + + keyId + keyId + TEMPLATE + keyId + + + + + + application/json + + + + + 204 + + data + + + + https://api.github.com + + + + + keyId + + + + + + + + SEQUENTIAL + + + true + true + false + true + true + + + + + + + <xml-fragment/> + + https://api.github.com + { + "title": "TestKey", + "key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCePm79U4yDVOTfqRX/kjciBddWX4vOOTBb0TOwP+d1nUmzjrRBd2SpN/sOtjg+8AMUU/Lase+uCSg5q1eEUGStoMquIVrFXTXbL41BJiJhRc64l8ZzG0Ip61/72PLGmxMPqLgmLo2gBBBY5O6huPpDGn3Sy/WFluwK6HUSL6R39Q==" + } + https://api.github.com/user/keys + + + + 201 + + + + GitHubProject + No Authorization + + + + + + + + + + + transfer_id + Response + Post Request + $['id'] + keyId + Get Request + + JSONPATH + true + + + del_id + Response + Post Request + $['id'] + keyId + Delete Request + JSONPATH + true + + + + + + + + + <xml-fragment/> + + https://api.github.com + + https://api.github.com/user/keys/118866679 + + + + 200 + + + + GitHubProject + No Authorization + + + + + + + keyId + + + + + + + + + + <xml-fragment/> + + https://api.github.com + + https://api.github.com/user/keys/118866679 + + + + 204 + + + + GitHubProject + No Authorization + + + + + + + keyId + + + + + + + + + + + + + + + + + + GitHubProject + OAuth 2.0 + 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 + HEADER + ENTERED_MANUALLY + ENTERED_MANUALLY + AUTHORIZATION_CODE_GRANT + AUTOMATIC + + id_token + + + + + + + + + // 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() + + + + GitHubProject + OAuth 2.0 + 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 + HEADER + ENTERED_MANUALLY + ENTERED_MANUALLY + AUTHORIZATION_CODE_GRANT + AUTOMATIC + + id_token + + + + diff --git a/API/Activities/PetStoreREST.xml b/API/Activities/PetStoreREST.xml new file mode 100644 index 0000000000..3c472c5568 --- /dev/null +++ b/API/Activities/PetStoreREST.xml @@ -0,0 +1,482 @@ + + + + + + + + https://petstore.swagger.io + + + + + + + + + application/json + + + + application/json + 200 + + pet:Response + + + application/json + 400 + + pet:Fault + + + + 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 + 200 + + ns:Response + + + application/json + + + + application/json + 404 + + ns:Fault + + + + 404 + + data + + + + https://petstore.swagger.io + + No Authorization + No Authorization + + + + + + petId + + + + + + + + SEQUENTIAL + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + { + "id": 22935, + "name": "John", + "status": "alive" +} + https://petstore.swagger.io/v2/pet + + + + 200 + + + + + $['status'] + alive + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + petStatus + Response + Post Request + $['status'] + status + Get Request + JSONPATH + true + + + petID + Response + Post Request + $['id'] + + petId + Delete Request + + JSONPATH + true + + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + + https://petstore.swagger.io/v2/pet/findByStatus + + + + 200 + + + + No Authorization + No Authorization + + + + + + + status + + + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + + https://petstore.swagger.io/v2/pet/22935 + + + + 200 + + + + No Authorization + No Authorization + + + + + + + petId + + + + + + + + + + + + <xml-fragment/> + + + + + com.mysql.jdbc.Driver + jdbc:mysql://db4free.net:3306/fstm1db?user=fstm1db&password=PASS_VALUE + 6Y6NowPybq + FST_DBConnection( Default environment ) + SELECT * FROM petData; + + false + + + 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 + + + + + $['status'] + alive + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + Status transfer + Response + Post Request + $['status'] + status + Get Request + + JSONPATH + true + + + transferID + Response + Post Request + $['id'] + petId + Delete Request + JSONPATH + true + + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + + https://petstore.swagger.io/v2/pet/findByStatus + + + + 200 + + + + No Authorization + No Authorization + + + + + + + status + + + + + + + + + + <xml-fragment/> + + https://petstore.swagger.io + + https://petstore.swagger.io/v2/pet/22935 + + + + 200 + + + + No Authorization + No Authorization + + + + + + + petId + + + + + + + + Data Source + Post Request + true + + + + + + + + + + + + + + FST_DBConnection + com.mysql.jdbc.Driver + jdbc:mysql://db4free.net:3306/fstm1db?user=fstm1db&password=PASS_VALUE + 6Y6NowPybq + + + + + + + + + + + + // 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/Project-1-readyapi-project.xml b/API/Activities/Project-1-readyapi-project.xml new file mode 100644 index 0000000000..c8e0d38013 --- /dev/null +++ b/API/Activities/Project-1-readyapi-project.xml @@ -0,0 +1,321 @@ + + + + + + + + http://www.dneonline.com/calculator.asmx + + + + + + 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 + + + + + + CalculatorSoap + Add + + + <xml-fragment/> + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + 20\r + 30\r + \r + \r +]]> + + + + + 200 + + + + + + + + + declare namespace ns1='http://tempuri.org/'; +//ns1:AddResult + 50 + false + false + false + + + + No Authorization + No Authorization + + + + + + + + + + + CalculatorSoap + Divide + + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + + + + 200 + + + + + + + + No Authorization + No Authorization + + + + + + + + + CalculatorSoap + Multiply + + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + + + + 200 + + + + + + + + No Authorization + No Authorization + + + + + + + + + CalculatorSoap + Subtract + + + UTF-8 + http://www.dneonline.com/calculator.asmx + \r + \r + \r + \r + ?\r + ?\r + \r + \r +]]> + + + + + 200 + + + + + + + + No Authorization + No Authorization + + + + + + + + + + + + + + + + FST_DBConnection + com.mysql.jdbc.Driver + jdbc:mysql://db4free.net:3306/fstm1db?user=fstm1db&password=PASS_VALUE + 6Y6NowPybq + + + + + + + + + + + + // 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/Project-2-readyapi-project.xml b/API/Activities/Project-2-readyapi-project.xml new file mode 100644 index 0000000000..2791984e0b --- /dev/null +++ b/API/Activities/Project-2-readyapi-project.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + // 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-Project-2-readyapi-project.xml b/API/Activities/REST-Project-2-readyapi-project.xml new file mode 100644 index 0000000000..3c3cbdf234 --- /dev/null +++ b/API/Activities/REST-Project-2-readyapi-project.xml @@ -0,0 +1,231 @@ + + + + + + + + http://ipwhois.app + + + + + + + + + IP + IP + TEMPLATE + IP + + + + + + application/json; charset=utf-8 + 200 + + ns:Response + + + + http://ipwhois.app + + + + + IP + + + + + + + + SEQUENTIAL + + + + + + + + 10 + 1 + 0 + COMP + IP + 0 + false + IPv4 + + + + false + false + IP + true + false + + + + + + + + <xml-fragment/> + + http://ipwhois.app + + http://ipwhois.app/json/135.72.100.243 + + + + 200 + + + + No Authorization + No Authorization + + + + + + + IP + + + + + + + + + city Transfer + Response + Get Request + $['city'] + city_name + Data Sink + + JSONPATH + true + + + lat Transfer + Response + Get Request + $['latitude'] + latitude + Data Sink + JSONPATH + true + + + long Transfer + Response + Get Request + $['longitude'] + longitude + Data Sink + JSONPATH + true + + + + + + + + + com.mysql.jdbc.Driver + jdbc:mysql://db4free.net:3306/fstm1db?user=fstm1db&password=PASS_VALUE + 6Y6NowPybq + FST_DataConnection + INSERT INTO coordinates VALUES (? , ? , ?) + false + + + + + city_name + Carbondale + + + latitude + 37.7272727 + + + longitude + -89.2167501 + + + + + + + + Data Source + Get Request + true + + + + + + + + + + + + + + FST_DataConnection + com.mysql.jdbc.Driver + jdbc:mysql://db4free.net:3306/fstm1db?user=fstm1db&password=PASS_VALUE + 6Y6NowPybq + + + + + + + + + + + + // 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/Appium/Activities/ActionsBase.java b/Appium/Activities/ActionsBase.java new file mode 100644 index 0000000000..5b60eb2947 --- /dev/null +++ b/Appium/Activities/ActionsBase.java @@ -0,0 +1,58 @@ +package activities; + +import io.appium.java_client.AppiumDriver; +import org.openqa.selenium.Point; +import org.openqa.selenium.interactions.Pause; +import org.openqa.selenium.interactions.PointerInput; +import org.openqa.selenium.interactions.PointerInput.Kind; +import org.openqa.selenium.interactions.Sequence; + +import java.time.Duration; +import java.util.Arrays; +import static java.time.Duration.ofMillis; +import static org.openqa.selenium.interactions.PointerInput.MouseButton.LEFT; +import static org.openqa.selenium.interactions.PointerInput.Origin.viewport; + +public class ActionsBase { + // Create the pointer + static final PointerInput pointer = new PointerInput(Kind.TOUCH, "finger"); + + // Create the swipe action function + public static void doSwipe(AppiumDriver driver, Point start, Point end, int duration) { + // Create sequence of actions + Sequence swipe = new Sequence(pointer, 1) + .addAction(pointer.createPointerMove(ofMillis(0), viewport(), start.getX(), start.getY())) + .addAction(pointer.createPointerDown(LEFT.asArg())) + .addAction(pointer.createPointerMove(ofMillis(duration), viewport(), end.getX(), end.getY())) + .addAction(pointer.createPointerUp(LEFT.asArg())); + + // Perform the actions + driver.perform(Arrays.asList(swipe)); + } + + // Create the long press action function + public static void longPress(AppiumDriver driver, Point start) { + // Create sequence of actions + Sequence longPress = new Sequence(pointer, 1) + .addAction(pointer.createPointerMove(ofMillis(0), viewport(), start.getX(), start.getY())) + .addAction(pointer.createPointerDown(LEFT.asArg())) + .addAction(new Pause(pointer, Duration.ofMillis(500))) + .addAction(pointer.createPointerUp(LEFT.asArg())); + + // Perform the actions + driver.perform(Arrays.asList(longPress)); + } + + // Create the long press action function + public static void tap(AppiumDriver driver, Point start) { + // Create sequence of actions + Sequence tap = new Sequence(pointer, 1) + .addAction(pointer.createPointerMove(ofMillis(0), viewport(), start.getX(), start.getY())) + .addAction(pointer.createPointerDown(LEFT.asArg())) + .addAction(new Pause(pointer, Duration.ofMillis(100))) + .addAction(pointer.createPointerUp(LEFT.asArg())); + + // Perform the actions + driver.perform(Arrays.asList(tap)); + } +} \ No newline at end of file diff --git a/Appium/Activities/Activity1.java b/Appium/Activities/Activity1.java new file mode 100644 index 0000000000..87e377601d --- /dev/null +++ b/Appium/Activities/Activity1.java @@ -0,0 +1,75 @@ +package activities; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; +import io.appium.java_client.ios.options.XCUITestOptions; + +public class Activity1 { + AppiumDriver driver; + + //setup appium setup + @BeforeClass + public void androidSetUp() throws MalformedURLException, URISyntaxException + { + UiAutomator2Options options = new UiAutomator2Options(). + setPlatformName("android"). + setAutomationName("UiAutomator2"). + //setApp("path/to/file.apk"). + setAppPackage("com.google.android.calculator"). + setAppActivity("com.android.calculator2.Calculator"). + noReset(); + + URL serverURL = new URI("http://127.0.0.1:4723").toURL(); + + driver = new AndroidDriver(serverURL , options); + + } + + @Test + public void multiplyTest() { + // Perform the calculation + driver.findElement(AppiumBy.id("digit_6")).click(); + driver.findElement(AppiumBy.accessibilityId("multiply")).click(); + driver.findElement(AppiumBy.id("digit_7")).click(); + driver.findElement(AppiumBy.accessibilityId("equals")).click(); + + // Find the result + String result = driver.findElement(AppiumBy.id("result")).getText(); + + // Assertion + Assert.assertEquals(result, "42"); + } + + + @AfterClass + public void tearDown() + { + driver.quit(); + } + + /*@BeforeClass + public void IOSSetUp() + { + XCUITestOptions options = new XCUITestOptions(). + setPlatformName("ios"). + setAutomationName("XCUITest"). + setApp("path/to/file.ipa"). + noReset(); + }*/ + + + //Set Appium server URL + +} diff --git a/Appium/Activities/Activity2.java b/Appium/Activities/Activity2.java new file mode 100644 index 0000000000..7acd273037 --- /dev/null +++ b/Appium/Activities/Activity2.java @@ -0,0 +1,75 @@ +package activities; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; +import io.appium.java_client.ios.options.XCUITestOptions; + +public class Activity2 { + AppiumDriver driver; + + //setup appium setup + @BeforeClass + public void androidSetUp() throws MalformedURLException, URISyntaxException + { + UiAutomator2Options options = new UiAutomator2Options(). + setPlatformName("android"). + setAutomationName("UiAutomator2"). + //setApp("path/to/file.apk"). + setAppPackage("com.android.chrome"). + setAppActivity("com.google.android.apps.chrome.Main"). + noReset(); + + URL serverURL = new URI("http://127.0.0.1:4723").toURL(); + + driver = new AndroidDriver(serverURL , options); + driver.get("https://training-support.net"); + + driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); + + } + + @Test + public void chromeTest() { + // Find heading on the page + String pageHeading = driver.findElement(AppiumBy.xpath( + "//android.widget.TextView[@text='Training Support']" + )).getText(); + + // Print to console + System.out.println("Heading: " + pageHeading); + + + + // Find and click the About Us link + driver.findElement(AppiumBy.accessibilityId("About Us")).click(); + + // Find heading of new page and print to console + String aboutPageHeading = driver.findElement(AppiumBy.xpath( + "//android.widget.TextView[@text='About Us']" + )).getText(); + System.out.println(aboutPageHeading); + } + + + @AfterClass + public void tearDown() + { + driver.quit(); + } + + + +} diff --git a/Appium/Activities/Activity3.java b/Appium/Activities/Activity3.java new file mode 100644 index 0000000000..08de8bbafa --- /dev/null +++ b/Appium/Activities/Activity3.java @@ -0,0 +1,112 @@ +package activities; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity3 { + // Driver Declaration + AndroidDriver driver; + + // Set up method + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.calculator2"); + options.setAppActivity(".Calculator"); + options.noReset(); + + // Server Address + URL serverURL = new URI("http://127.0.0.1:4723").toURL(); + + // Driver Initialization + driver = new AndroidDriver(serverURL, options); + } + + // Test method + @Test + public void additionTest() { + // Perform the calculation + driver.findElement(AppiumBy.id("digit_5")).click(); + driver.findElement(AppiumBy.accessibilityId("plus")).click(); + driver.findElement(AppiumBy.id("digit_9")).click(); + driver.findElement(AppiumBy.accessibilityId("equals")).click(); + + // Find the result + String result = driver.findElement(AppiumBy.id("result")).getText(); + + // Assertion + Assert.assertEquals(result, "14"); + } + + // Test method + @Test + public void subtractTest() { + // Perform the calculation + driver.findElement(AppiumBy.id("digit_1")).click(); + driver.findElement(AppiumBy.id("digit_0")).click(); + driver.findElement(AppiumBy.accessibilityId("minus")).click(); + driver.findElement(AppiumBy.id("digit_5")).click(); + driver.findElement(AppiumBy.accessibilityId("equals")).click(); + + // Find the result + String result = driver.findElement(AppiumBy.id("result")).getText(); + + // Assertion + Assert.assertEquals(result, "5"); + } + + // Test method + @Test + public void multiplyTest() { + // Perform the calculation + driver.findElement(AppiumBy.id("digit_5")).click(); + driver.findElement(AppiumBy.accessibilityId("multiply")).click(); + driver.findElement(AppiumBy.id("digit_1")).click(); + driver.findElement(AppiumBy.id("digit_0")).click(); + driver.findElement(AppiumBy.id("digit_0")).click(); + driver.findElement(AppiumBy.accessibilityId("equals")).click(); + + // Find the result + String result = driver.findElement(AppiumBy.id("result")).getText(); + + // Assertion + Assert.assertEquals(result, "500"); + } + + // Test method + @Test + public void divideTest() { + // Perform the calculation + driver.findElement(AppiumBy.id("digit_5")).click(); + driver.findElement(AppiumBy.id("digit_0")).click(); + driver.findElement(AppiumBy.accessibilityId("divide")).click(); + driver.findElement(AppiumBy.id("digit_2")).click(); + driver.findElement(AppiumBy.accessibilityId("equals")).click(); + + // Find the result + String result = driver.findElement(AppiumBy.id("result")).getText(); + + // Assertion + Assert.assertEquals(result, "25"); + } + + // Tear down method + @AfterClass + public void tearDown() { + // Close the app + driver.quit(); + } +} \ No newline at end of file diff --git a/Appium/Activities/Activity4.java b/Appium/Activities/Activity4.java new file mode 100644 index 0000000000..4a901aac38 --- /dev/null +++ b/Appium/Activities/Activity4.java @@ -0,0 +1,128 @@ +package activities; + +import static org.testng.Assert.assertEquals; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity3 { + + AppiumDriver driver; + WebDriverWait wait; + + @BeforeClass() + public void setUp() throws MalformedURLException, URISyntaxException { + + UiAutomator2Options options = new UiAutomator2Options() + .setAutomationName("UiAutomator2") + .setPlatformName("android") + .setAppPackage("com.vivo.calculator")//to set a package, its always goes with setAppActivity() + .setAppActivity(".Calculator") + .noReset(); + + URL serverURL = new URI("http://127.0.0.1:4723").toURL(); + + //Initialize driver + driver = new AndroidDriver(serverURL, options); + + } + + @BeforeMethod + public void clearInput() { + //clears by clicking on AC on app + driver.findElement(AppiumBy.accessibilityId("Clear")).click(); + } + + @Test(priority = 1) + public void additionTest() { + + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_5")).click(); + + driver.findElement(AppiumBy.accessibilityId("Plus")).click(); + + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_9")).click(); + + driver.findElement(AppiumBy.accessibilityId("=")).click(); + + String res = driver.findElement(AppiumBy.id("com.vivo.calculator:id/formula")).getText(); + System.out.println("The result of addition is "+ res); + assertEquals(res, "14"); + + } + + @Test(priority = 2) + public void subTractionTest() { + + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_1")).click(); + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_0")).click(); + + driver.findElement(AppiumBy.accessibilityId("Minus")).click(); + + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_5")).click(); + + driver.findElement(AppiumBy.accessibilityId("=")).click(); + + String res = driver.findElement(AppiumBy.id("com.vivo.calculator:id/formula")).getText(); + System.out.println("The result of Subtraction is "+ res); + assertEquals(res, "5"); + + } + + @Test(priority = 3) + public void MultiplyTest() { + + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_5")).click(); + + + driver.findElement(AppiumBy.accessibilityId("Multiply")).click(); + + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_1")).click(); + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_0")).click(); + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_0")).click(); + + driver.findElement(AppiumBy.accessibilityId("=")).click(); + + String res = driver.findElement(AppiumBy.id("com.vivo.calculator:id/formula")).getText(); + System.out.println("The result of Multiplication is "+ res); + assertEquals(res, "500"); + + } + + @Test(priority = 4) + public void DivideTest() { + + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_5")).click(); + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_0")).click(); + + driver.findElement(AppiumBy.accessibilityId("Divide")).click(); + + driver.findElement(AppiumBy.id("com.vivo.calculator:id/digit_2")).click(); + + driver.findElement(AppiumBy.accessibilityId("=")).click(); + + String res = driver.findElement(AppiumBy.id("com.vivo.calculator:id/formula")).getText(); + System.out.println("The result of Division is "+ res); + assertEquals(res, "25"); + + } + + @AfterClass + public void closure() { + driver.quit(); + } + +} + diff --git a/Appium/Activities/Activity5.java b/Appium/Activities/Activity5.java new file mode 100644 index 0000000000..4793efbc93 --- /dev/null +++ b/Appium/Activities/Activity5.java @@ -0,0 +1,75 @@ +package activities; + +import static org.testng.Assert.assertEquals; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity4 { + + AppiumDriver driver; + WebDriverWait wait; + + @BeforeClass() + public void setUp() throws MalformedURLException, URISyntaxException { + + UiAutomator2Options options = new UiAutomator2Options() + .setAutomationName("UiAutomator2") + .setPlatformName("android") + .setAppPackage("com.google.android.contacts")//to set a package, its always goes with setAppActivity() + .setAppActivity("com.android.contacts.activities.PeopleActivity") + .noReset(); + + URL serverURL = new URI("http://127.0.0.1:4723").toURL(); + + //Initialize driver + driver = new AndroidDriver(serverURL, options); + + wait = new WebDriverWait(driver,Duration.ofSeconds(10)); + + } + + @Test + public void createContact() { + + driver.findElement(AppiumBy.accessibilityId("Create contact")).click(); + + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.EditText[@text=\"First name\"]"))); + //firstname + WebElement firstName = driver.findElement(AppiumBy.xpath("//android.widget.EditText[@text=\"First name\"]")); + WebElement lastName = driver.findElement(AppiumBy.xpath("//android.widget.EditText[@text=\"Last name\"]")); + WebElement PhoneNum = driver.findElement(AppiumBy.xpath("//android.widget.EditText[@text=\"+91\"]")); + + firstName.sendKeys("Test"); + lastName.sendKeys("Appium"); + PhoneNum.sendKeys("9999900000"); + + driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text=\"Save\"]")).click(); + + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.id("com.google.android.contacts:id/large_title"))); + String name = driver.findElement(AppiumBy.id("com.google.android.contacts:id/large_title")).getText(); + assertEquals(name, "Test Appium"); + } + + @AfterClass + public void closure() { + + driver.quit(); + + } +} diff --git a/Appium/Activities/Activity6.java b/Appium/Activities/Activity6.java new file mode 100644 index 0000000000..6eba086f79 --- /dev/null +++ b/Appium/Activities/Activity6.java @@ -0,0 +1,94 @@ +package activities; +import static org.testng.Assert.assertTrue; +import static activities.ActionsBase.doSwipe; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity6 { + AndroidDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("Android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); + options.noReset(); + + // Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(20)); + + // Open Selenium page + driver.get("https://training-support.net/webelements/sliders"); + } + + @Test + public void volume75Test() { + // Wait for page to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.SeekBar"))); + // Get the size of the screen + Dimension dims = driver.manage().window().getSize(); + // Set the start and end points + Point start = new Point((int) (dims.getWidth() * .50), (int) (dims.getHeight() * .72)); + Point end = new Point((int) (dims.getWidth() * .665), (int) (dims.getHeight() * .72)); + // Perform swipe + doSwipe(driver, start, end, 2000); + + // Get the volume level + String volumeText = driver + .findElement(AppiumBy.xpath("//android.view.View/android.widget.TextView[contains(@text, '%')]")) + .getText(); + + // Assertions + assertTrue(volumeText.contains("75%")); + } + + @Test + public void volume25Test() { + // Wait for page to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.SeekBar"))); + // Get the size of the screen + Dimension dims = driver.manage().window().getSize(); + // Set the start and end points + Point start = new Point((int) (dims.getWidth() * .50), (int) (dims.getHeight() * .72)); + Point end = new Point((int) (dims.getWidth() * .333), (int) (dims.getHeight() * .72)); + // Perform swipe + doSwipe(driver, start, end, 2000); + + // Get the volume level + String volumeText = driver + .findElement(AppiumBy.xpath("//android.view.View/android.widget.TextView[contains(@text, '%')]")) + .getText(); + + // Assertions + assertTrue(volumeText.contains("25%")); + } + + @AfterClass + public void tearDown() { + // Close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/Appium/Activities/Activity7.java b/Appium/Activities/Activity7.java new file mode 100644 index 0000000000..2eb9e1ec10 --- /dev/null +++ b/Appium/Activities/Activity7.java @@ -0,0 +1,83 @@ +package activities; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; +import java.util.List; + +import org.openqa.selenium.WebElement; +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; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity7 { + // Driver Declaration + AndroidDriver driver; + WebDriverWait wait; + + // Set up method + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); + options.noReset(); + + // Server Address + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver Initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + // Open the page in Chrome + driver.get("https://training-support.net/webelements/lazy-loading"); + } + + // Test method + @Test + public void uiScrollableTest() { + // Wait for page to load + wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.className("android.widget.Image"))); + // UiScrollable object string + String UiScrollable = "UiScrollable(UiSelector().scrollable(true))"; + + // Find all the image elements on the page + List imageElements = driver.findElements(AppiumBy.className("android.widget.Image")); + // Print the number of images + System.out.println("Before scroll: " + imageElements.size()); + + // Scroll to required element + String imageText = driver.findElement(AppiumBy + .androidUIAutomator(UiScrollable + ".scrollForward(25).getChildByText(className(\"android.widget.Image\"), \"Helen\")")) + .getText(); + System.out.println("Found " + imageText + "!"); + + // Get image elements after scroll + imageElements = driver.findElements(AppiumBy.className("android.widget.Image")); + // Print the number of images after scroll + System.out.println("After scroll: " + imageElements.size()); + + // Assertions + Assert.assertEquals(imageElements.size(), 3); + } + + // Tear down method + @AfterClass + public void tearDown() { + // Close the app + driver.quit(); + } +} diff --git a/Appium/Activities/Activity8.java b/Appium/Activities/Activity8.java new file mode 100644 index 0000000000..c90c21322c --- /dev/null +++ b/Appium/Activities/Activity8.java @@ -0,0 +1,137 @@ +package activities; + + +import static org.testng.Assert.assertTrue; +import static activities.ActionsBase.doSwipe; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.AppiumDriver; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity6{ + +AppiumDriver driver; +WebDriverWait wait; + + @BeforeClass + public void andriodSetup() throws MalformedURLException, URISyntaxException { + //set desired capabilities + UiAutomator2Options options = new UiAutomator2Options() + .setPlatformName("andriod")//Mandatory + .setAutomationName("UiAutomator2")//Mandatory + .setAppPackage("com.android.chrome")//to set a package, its always goes with setAppActivity() + .setAppActivity("com.google.android.apps.chrome.Main")//to set a class, its always goes with setAppPackage() + .noReset(); //it will not reset the appium + + //set appium url + URL serverURL = new URI("http://127.0.0.1:4723").toURL(); + + + //Initialize driver + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + //to open url + driver.get("https://training-support.net/webelements/sliders/"); + +} + + @Test(priority = 1) + public void volume75Test() { + + // Wait for page to load + + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.SeekBar"))); + + // Get the size of the screen + + Dimension dims = driver.manage().window().getSize(); + + // Set the start and end points + + Point start = new Point((int) (dims.getWidth() * .51), (int) (dims.getHeight() * .77)); + Point end = new Point((int) (dims.getWidth() * .67), (int) (dims.getHeight() * .77)); + + // Perform swipe + + doSwipe(driver, start, end, 2000); + + // Get the volume level + + String volumeText = driver + + .findElement(AppiumBy.xpath("//android.view.View/android.widget.TextView[contains(@text, '%')]")) + + .getText(); + + // Assertions + + assertTrue(volumeText.contains("75%")); + + } + @Test(priority = 2) + + public void volume25Test() { + + // Wait for page to load + + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.SeekBar"))); + + // Get the size of the screen + + Dimension dims = driver.manage().window().getSize(); + + // Set the start and end points + + Point start = new Point((int) (dims.getWidth() * .50), (int) (dims.getHeight() * .77)); + + Point end = new Point((int) (dims.getWidth() * .33), (int) (dims.getHeight() * .77)); + + // Perform swipe + + doSwipe(driver, start, end, 2000); + + + + // Get the volume level + + String volumeText = driver + + .findElement(AppiumBy.xpath("//android.view.View/android.widget.TextView[contains(@text, '%')]")) + + .getText(); + + + + // Assertions + + assertTrue(volumeText.contains("25%")); + + } + + + + @AfterClass + + public void tearDown() { + + // Close the browser + + driver.quit(); + + } + +} diff --git a/Appium/Project/Activity1.java b/Appium/Project/Activity1.java new file mode 100644 index 0000000000..fcf6efd1d1 --- /dev/null +++ b/Appium/Project/Activity1.java @@ -0,0 +1,84 @@ +package liveProject; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import java.net.MalformedURLException; +import java.net.URL; +import java.time.Duration; +import java.util.List; + +import static org.testng.Assert.assertEquals; + +public class Activity1 { + // Declare driver + AndroidDriver driver; + WebDriverWait wait; + + // Setup method + @BeforeClass + public void setUp() throws MalformedURLException { + // Desired Capabilities + UiAutomator2Options caps = new UiAutomator2Options(); + caps.setPlatformName("android"); + caps.setAutomationName("UiAutomator2"); + caps.setAppPackage("com.app.todolist"); + caps.setAppActivity(".view.MainActivity"); + caps.noReset(); + + // Appium Server URL + URL serverURL = new URL("http://localhost:4723"); + + // Initialization of driver + driver = new AndroidDriver(serverURL, caps); + // Initialization of wait + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + } + + @Test + public void tasksTest1() { + // Tasks to be added + String[][] tasksToAdd = { + {"Complete Activity 1", "High"}, + {"Complete Activity 2", "Medium"}, + {"Complete Activity 3", "Low"} + }; + + // Repeat actions for each task to add + for (String tasks[] : tasksToAdd) { + // Find the create new task button and click it + driver.findElement(AppiumBy.id("fab_new_task")).click(); + // Wait for input field to show and then enter the task name + wait.until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.id("et_new_task_name"))) + .sendKeys(tasks[0]); + // Set the priority + driver.findElement(AppiumBy.id("com.app.todolist:id/tv_new_task_priority")).click(); + wait.until(ExpectedConditions.elementToBeClickable( + AppiumBy.xpath("//android.widget.TextView[@resource-id='android:id/title' and @text='"+ tasks[1] +"']"))) + .click(); + // Click Save + driver.findElement(AppiumBy.id("bt_new_task_ok")).click(); + } + + // Assertions + // Find all the added tasks + List tasksAdded = wait.until(ExpectedConditions. + numberOfElementsToBe(AppiumBy.id("com.app.todolist:id/rl_exlv_task_group_root"), 3)); + // Verify number of tasks added + assertEquals(tasksAdded.size(), 3); + } + + @AfterClass + public void tearDown() { + // Close the app + driver.quit(); + } + +} \ No newline at end of file diff --git a/Appium/Project/Activity2.java b/Appium/Project/Activity2.java new file mode 100644 index 0000000000..c066030615 --- /dev/null +++ b/Appium/Project/Activity2.java @@ -0,0 +1,75 @@ +package liveProject; + +import static activities.ActionsBase.longPress; + +import java.net.MalformedURLException; +import java.net.URL; +import java.time.Duration; + +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +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; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity2 { + // Declare driver + AndroidDriver driver; + WebDriverWait wait; + + // Setup method + @BeforeClass + public void setUp() throws MalformedURLException { + // Desired Capabilities + UiAutomator2Options caps = new UiAutomator2Options(); + caps.setPlatformName("android"); + caps.setAutomationName("UiAutomator2"); + caps.setAppPackage("com.app.todolist"); + caps.setAppActivity(".view.MainActivity"); + caps.noReset(); + + // Appium Server URL + URL serverURL = new URL("http://localhost:4723"); + + // Initialization of driver + driver = new AndroidDriver(serverURL, caps); + // Initialization of wait + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + } + + @Test + public void tasksTest2() { + // Get the size of the screen + Dimension dims = driver.manage().window().getSize(); + // Set the point of long press + Point start = new Point((int) (dims.getWidth() * .50), (int) (dims.getHeight() * .15)); + + // Perform long press on the first list item + longPress(driver, start); + // Select edit task + driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text='Edit To-Do Task']")).click(); + + // Set a deadline for the coming weekend + driver.findElement(AppiumBy.id("tv_todo_list_deadline")).click(); + driver.findElement(AppiumBy.accessibilityId("15 February 2025")).click(); + // Save details + driver.findElement(AppiumBy.id("bt_deadline_ok")).click(); + driver.findElement(AppiumBy.id("bt_new_task_ok")).click(); + + // Assertions + String expectedDeadline = driver.findElement(AppiumBy.id("tv_exlv_task_deadline")).getText(); + Assert.assertEquals(expectedDeadline, "Deadline: 15.02.2025"); + } + + @AfterClass + public void tearDown() { + // Close the app + driver.quit(); + } +} diff --git a/Appium/Project/Activity3.java b/Appium/Project/Activity3.java new file mode 100644 index 0000000000..ce4fc284f0 --- /dev/null +++ b/Appium/Project/Activity3.java @@ -0,0 +1,97 @@ +package liveProject; + +import static activities.ActionsBase.doSwipe; +import static activities.ActionsBase.longPress; +import static org.testng.Assert.assertEquals; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; +import java.util.List; + +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity3 { + AndroidDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.app.todolist"); + options.setAppActivity(".view.MainActivity"); + options.noReset(); + + // Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(20)); + } + + @Test(priority = 1) + public void tasksTest3_1() { + // Get width and height of the screen + Dimension dims = driver.manage().window().getSize(); + // Set the point to long press + Point longPressPoint = new Point((int) (dims.getWidth() * 0.5), (int) (dims.getHeight() * 0.28)); + // Set the start and end points to move the slider + Point slideStart = new Point((int) (dims.getWidth() * 0.27), (int) (dims.getHeight() * 0.56)); + Point sliderEnd = new Point((int) (dims.getWidth() * 0.593), (int) (dims.getHeight() * 0.56)); + + // Mark the first 2 tasks as complete + List checkBoxes = driver.findElements(AppiumBy.id("com.app.todolist:id/cb_task_done")); + // Click first checkbox + checkBoxes.get(0).click(); + // Click second checkbox + checkBoxes.get(1).click(); + + // Long press the third task to edit + longPress(driver, longPressPoint); + // Click on Edit task + driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text='Edit To-Do Task']")).click(); + // Move the slider to 50% + doSwipe(driver, slideStart, sliderEnd, 2000); + // Click save + driver.findElement(AppiumBy.id("bt_new_task_ok")).click(); + + // Assertions + String progressValue = driver.findElements(AppiumBy.xpath("//android.widget.ProgressBar")).get(2).getText(); + assertEquals(progressValue, "50.0"); + } + + @Test(priority = 2) + public void tasksTest3_2() { + // Find and tap more options + driver.findElement(AppiumBy.accessibilityId("More options")).click(); + // Find and tap Completed tasks + driver.findElement(AppiumBy.xpath("//android.widget.TextView[@text='Completed tasks']")).click(); + + // Get all tasks + List completedTasks = driver + .findElements(AppiumBy.id("com.app.todolist:id/rl_exlv_task_group_root")); + // Assertions + assertEquals(completedTasks.size(), 2); + } + + @AfterClass + public void afterClass() { + driver.quit(); + } +} diff --git a/Appium/Project/Activity4.java b/Appium/Project/Activity4.java new file mode 100644 index 0000000000..7c2b179f7e --- /dev/null +++ b/Appium/Project/Activity4.java @@ -0,0 +1,99 @@ +package liveProject; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.WebElement; +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; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.List; +import java.time.Duration; + +import static activities.ActionsBase.doSwipe; + +public class Activity4 { + AndroidDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("Android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); + options.noReset(); + + // Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(20)); + + // Open Selenium page + driver.get("https://training-support.net/webelements"); + } + + @Test + public void webAppTest() throws InterruptedException { + // Get width and height of the screen + Dimension dims = driver.manage().window().getSize(); + System.out.println(dims); + Point start = new Point((int)(dims.getWidth() * 0.5), (int)(dims.getHeight() * 0.8)); + Point end = new Point((int)(dims.getWidth() * 0.5), (int)(dims.getHeight() * 0.6)); + + // Wait for page to load + wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(AppiumBy.xpath("//android.widget.TextView[@text='WebElements']"))); + + // Scroll(Fling) to the end of the page + doSwipe(driver, start, end, 50); + + // Wait for To-Do list link and click it + wait.until(ExpectedConditions.elementToBeClickable( + AppiumBy.xpath("//android.widget.TextView[contains(@text,'To-Do List')]")) + ).click(); + + // Wait for the page to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.EditText[@resource-id='todo-input']"))); + + // Find elements on the page + WebElement addTaskInput = driver.findElement(AppiumBy.xpath("//android.widget.EditText[@resource-id='todo-input']")); + WebElement addTaskButton = driver.findElement(AppiumBy.xpath("//android.widget.Button[@resource-id='todo-add']")); + // Enter tasks + addTaskInput.sendKeys("Add tasks to list"); + addTaskButton.click(); + addTaskInput.sendKeys("Get number of tasks"); + addTaskButton.click(); + addTaskInput.sendKeys("Clear the list"); + addTaskButton.click(); + + // Find all added tasks + List tasksAdded = driver.findElements(AppiumBy.xpath("//android.widget.ListView/android.view.View")); + // Check off tasks one by one + for(WebElement task : tasksAdded) { + task.findElement(AppiumBy.xpath("//android.view.View/android.widget.CheckBox")).click(); + } + + // Assertion to check if all tasks are added + tasksAdded = driver.findElements(AppiumBy.xpath("//android.widget.ListView/android.view.View")); + Assert.assertEquals(tasksAdded.size(), 5); + } + + @AfterClass + public void afterClass() { + driver.quit(); + } +} diff --git a/Appium/Project/Activity5.java b/Appium/Project/Activity5.java new file mode 100644 index 0000000000..dfead8d106 --- /dev/null +++ b/Appium/Project/Activity5.java @@ -0,0 +1,106 @@ +package liveProject; + +import static activities.ActionsBase.doSwipe; +import static org.testng.Assert.assertEquals; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity5 { + AndroidDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("Android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); + options.noReset(); + + // Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(20)); + + // Open Selenium page + driver.get("https://training-support.net/webelements"); + } + + @Test(priority = 1) + public void loginPageTest() { + // Get width and height of the screen + Dimension dims = driver.manage().window().getSize(); + System.out.println(dims); + Point start = new Point((int) (dims.getWidth() * 0.5), (int) (dims.getHeight() * 0.85)); + Point end = new Point((int) (dims.getWidth() * 0.5), (int) (dims.getHeight() * 0.5)); + + // Wait for page to load + wait.until(ExpectedConditions + .visibilityOfAllElementsLocatedBy(AppiumBy.xpath("//android.widget.TextView[@text='WebElements']"))); + + // Scroll(Fling) to the end of the page + doSwipe(driver, start, end, 145); + + // Wait for Login Form link and click it + wait.until(ExpectedConditions + .elementToBeClickable(AppiumBy.xpath("//android.widget.TextView[contains(@text,'Login Form')]"))) + .click(); + + // Wait for the page to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.Button[@text='Submit']"))); + + // Assertion + assertEquals(driver.findElement(AppiumBy.xpath("//android.widget.TextView")).getText(), "Login Form"); + } + + @Test(priority = 2) + public void invalidLoginTest() throws InterruptedException { + // Find the input fields and login + driver.findElement(AppiumBy.xpath("//android.widget.EditText[@resource-id='username']")) + .sendKeys("admin"); + driver.findElement(AppiumBy.xpath("//android.widget.EditText[@resource-id='password']")) + .sendKeys("WrongPassword"); + driver.findElement(AppiumBy.xpath("//android.widget.Button[@text='Submit']")).click(); + + // Wait for success message to load and get text + String message = wait.until(ExpectedConditions + .visibilityOfElementLocated(AppiumBy.xpath("//android.widget.TextView[@resource-id='subheading']"))) + .getText(); + assertEquals(message, "Invalid credentials"); + } + + @Test(priority = 3) + public void validLoginTest() throws InterruptedException { + // Find the input fields and login + driver.findElement(AppiumBy.xpath("//android.widget.EditText[@resource-id='username']")) + .sendKeys("admin"); + driver.findElement(AppiumBy.xpath("//android.widget.EditText[@resource-id='password']")) + .sendKeys("password"); + driver.findElement(AppiumBy.xpath("//android.widget.Button[@text='Submit']")).click(); + + // Wait for success message to load and get text + String message = wait + .until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.xpath("//android.widget.TextView[2]"))) + .getText(); + assertEquals(message, "Welcome Back, Admin!"); + } +} diff --git a/Appium/Project/Activity6.java b/Appium/Project/Activity6.java new file mode 100644 index 0000000000..13e0f19dc3 --- /dev/null +++ b/Appium/Project/Activity6.java @@ -0,0 +1,100 @@ +package liveProject; + +import static activities.ActionsBase.doSwipe; +import static activities.ActionsBase.tap; +import static org.testng.Assert.assertEquals; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.time.Duration; + +import org.openqa.selenium.Dimension; +import org.openqa.selenium.Point; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import io.appium.java_client.AppiumBy; +import io.appium.java_client.android.AndroidDriver; +import io.appium.java_client.android.options.UiAutomator2Options; + +public class Activity6 { + AndroidDriver driver; + WebDriverWait wait; + // Get width and height of the screen + Dimension dims; + + @BeforeClass + public void setUp() throws MalformedURLException, URISyntaxException { + // Desired Capabilities + UiAutomator2Options options = new UiAutomator2Options(); + options.setPlatformName("Android"); + options.setAutomationName("UiAutomator2"); + options.setAppPackage("com.android.chrome"); + options.setAppActivity("com.google.android.apps.chrome.Main"); + options.noReset(); + + // Server URL + URL serverURL = new URI("http://localhost:4723").toURL(); + + // Driver initialization + driver = new AndroidDriver(serverURL, options); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + dims = driver.manage().window().getSize(); + + // Open Selenium page + driver.get("https://training-support.net/webelements"); + } + + @Test(priority = 1) + public void popupPageTest() { + Point start = new Point((int) (dims.getWidth() * 0.5), (int) (dims.getHeight() * 0.85)); + Point end = new Point((int) (dims.getWidth() * 0.5), (int) (dims.getHeight() * 0.65)); + + // Wait for page to load + wait.until(ExpectedConditions + .visibilityOfAllElementsLocatedBy(AppiumBy.xpath("//android.widget.TextView[@text='WebElements']"))); + + // Scroll(Fling) to the end of the page + doSwipe(driver, start, end, 110); + + // Wait for Login Form link and click it + wait.until(ExpectedConditions + .elementToBeClickable(AppiumBy.xpath("//android.widget.TextView[contains(@text,'Popups')]"))) + .click(); + + // Wait for the page to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.Button[@resource-id='launcher']"))); + + // Assertion + assertEquals(driver.findElement(AppiumBy.xpath("//android.widget.TextView")).getText(), "Popups"); + } + + @Test(priority = 2) + public void validLoginTest() throws InterruptedException { + // Point to tap to focus the form + Point start = new Point((int) (dims.getWidth() * 0.5), (int) (dims.getHeight() * 0.27)); + // Find and click the button to launch the popup + driver.findElement(AppiumBy.xpath("//android.widget.Button[@resource-id='launcher']")).click(); + // Click the username field to focus on it + tap(driver, start); + // Wait for form elements to load + wait.until(ExpectedConditions.elementToBeClickable(AppiumBy.xpath("//android.widget.Button[@text='Submit']"))); + // Find the input fields and login + driver.findElement(AppiumBy.xpath("//android.widget.EditText[@resource-id='username']")) + .sendKeys("admin"); + driver.findElement(AppiumBy.xpath("//android.widget.EditText[@resource-id='password']")) + .sendKeys("password"); + driver.findElement(AppiumBy.xpath("//android.widget.Button[@text='Submit']")).click(); + + // Wait for success message to load and get text + String message = wait + .until(ExpectedConditions.visibilityOfElementLocated(AppiumBy.xpath("//android.widget.TextView[2]"))) + .getText(); + assertEquals(message, "Welcome Back, Admin!"); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/Activity6.java b/Cucumber/Activities/Activity6.java new file mode 100644 index 0000000000..245a57a712 --- /dev/null +++ b/Cucumber/Activities/Activity6.java @@ -0,0 +1,33 @@ +package stepdefinitions; +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 Activity6 extends BaseClass { + + @Given("User is on the To-Do list page") + public void completeRequirement() { + driver.get("https://training-support.net/webelements/todo-list"); + System.out.println("Given completed"); + } + + @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 are present"); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/Activity7.java b/Cucumber/Activities/Activity7.java new file mode 100644 index 0000000000..5747e1c2be --- /dev/null +++ b/Cucumber/Activities/Activity7.java @@ -0,0 +1,33 @@ +package stepdefinitions; +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 Activity7 extends BaseClass { + + @Given("User is on the To-Do list page") + public void completeRequirement() { + driver.get("https://training-support.net/webelements/todo-list"); + System.out.println("Given completed"); + } + + @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 are present"); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/Activity7_new.java b/Cucumber/Activities/Activity7_new.java new file mode 100644 index 0000000000..bb1d47657f --- /dev/null +++ b/Cucumber/Activities/Activity7_new.java @@ -0,0 +1,34 @@ +package stepdefinitions; + +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 Activity7 extends BaseClass { + + @Given("User is on the To-Do list page") + public void completeRequirement() { + driver.get("https://training-support.net/webelements/todo-list"); + System.out.println("Given completed"); + } + + @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 are present"); + } +} \ No newline at end of file diff --git a/Cucumber/Activities/BaseClass.java b/Cucumber/Activities/BaseClass.java new file mode 100644 index 0000000000..0e63ac6381 --- /dev/null +++ b/Cucumber/Activities/BaseClass.java @@ -0,0 +1,12 @@ +package stepdefinitions; + +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/Features b/Cucumber/Activities/Features new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/Cucumber/Activities/Features @@ -0,0 +1 @@ + diff --git a/Cucumber/Activities/FirstClass.java b/Cucumber/Activities/FirstClass.java new file mode 100644 index 0000000000..c08a39a6d6 --- /dev/null +++ b/Cucumber/Activities/FirstClass.java @@ -0,0 +1,27 @@ +package stepdefinitions; + +import org.openqa.selenium.By; +import static org.junit.jupiter.api.Assertions.assertEquals; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; + +public class FirstClass extends BaseClass { + + @Given("the user is on TS home page") + public void openPage() { + driver.get("https://training-support.net"); + assertEquals(driver.getTitle(), "Training Support"); + + } + + @When("the user clicks on the About us link") + public void clickLink() { + driver.findElement(By.linkText("About Us")).click(); + } + + @Then("the user is redirected to About us page") + public void redirectToAbout() { + assertEquals(driver.getTitle(), "About Training Support"); + } +} diff --git a/Cucumber/Activities/Fixtures.java b/Cucumber/Activities/Fixtures.java new file mode 100644 index 0000000000..401a88026c --- /dev/null +++ b/Cucumber/Activities/Fixtures.java @@ -0,0 +1,28 @@ +package stepdefinitions; + +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() + { + driver = new FirefoxDriver(); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + } + + @AfterAll + public static void tearDown() + { + driver.quit(); + } +} + + diff --git a/Cucumber/Activities/LoginSteps.java b/Cucumber/Activities/LoginSteps.java new file mode 100644 index 0000000000..ed1002f674 --- /dev/null +++ b/Cucumber/Activities/LoginSteps.java @@ -0,0 +1,73 @@ +package stepdefinitions; + +import org.junit.jupiter.api.Assertions; +import org.openqa.selenium.By; +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"); + String enteredUserName = driver.findElement(By.id("username")).getAttribute("value"); + System.out.println("User Name field has: " + enteredUserName); + } + + // calling parameter method. + @When("the user enters {string} and {string}") + public void enterCredsWithParam(String username, String password) { + // Find username field and enter username + driver.findElement(By.id("username")).sendKeys(username); + // Find password field and enter password + driver.findElement(By.id("password")).sendKeys(password); + String enteredUserName = driver.findElement(By.id("username")).getAttribute("value"); + Assertions.assertEquals(enteredUserName, "admin"); + } + + @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 message and verify message as {string}") + public void confirmMessageAsInput(String expectedMessage) { + // Find the confirmation 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.text-center"))) + .getText(); + } + + Assertions.assertEquals(expectedMessage, message); + + } +} diff --git a/Cucumber/Activities/TestRunnerClass.java b/Cucumber/Activities/TestRunnerClass.java new file mode 100644 index 0000000000..8cd9f7afd9 --- /dev/null +++ b/Cucumber/Activities/TestRunnerClass.java @@ -0,0 +1,14 @@ +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 = "stepdefinitions") +@ConfigurationParameter( + key = Constants.FILTER_TAGS_PROPERTY_NAME,value = "@activity6") +public class TestRunnerClass {} \ No newline at end of file diff --git a/Cucumber/Activities/activity2.feature b/Cucumber/Activities/activity2.feature new file mode 100644 index 0000000000..7ac4235ba7 --- /dev/null +++ b/Cucumber/Activities/activity2.feature @@ -0,0 +1,9 @@ +@activity2 +Feature: Activity to test the login feature + +@LoginTest +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/activity4.feature b/Cucumber/Activities/activity4.feature new file mode 100644 index 0000000000..5ebefeb74a --- /dev/null +++ b/Cucumber/Activities/activity4.feature @@ -0,0 +1,9 @@ +@activity4 +Feature: Data driven test without Examples + + @loginTest @loginsuccess + 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 message 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..4c9a26cd59 --- /dev/null +++ b/Cucumber/Activities/activity5.feature @@ -0,0 +1,13 @@ +@activity5 +Feature: Data driven test without Examples + + Scenario Outline: Testing with Data 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 message and verify message as "" + + Examples: + |Usernames | Passwords | Message | + |admin | password | Welcome Back, Admin!| + |admin | WrongPassword | Invalid credentials | \ No newline at end of file diff --git a/Cucumber/Activities/activity6.feature b/Cucumber/Activities/activity6.feature new file mode 100644 index 0000000000..5556791b73 --- /dev/null +++ b/Cucumber/Activities/activity6.feature @@ -0,0 +1,11 @@ +@activity6 +Feature: Data driven test with DataTable + +@TasksDataTable +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/firstTest.feature b/Cucumber/Activities/firstTest.feature new file mode 100644 index 0000000000..1bb4beb769 --- /dev/null +++ b/Cucumber/Activities/firstTest.feature @@ -0,0 +1,8 @@ +@activity1 +Feature: Basic syntax + + Scenario: TS home page test + Given the user is on TS home page + When the user clicks on the About us link + Then the user is redirected to About us page + \ No newline at end of file diff --git a/Git/Activities/Git evidence.docx b/Git/Activities/Git evidence.docx new file mode 100644 index 0000000000..66539b5b36 Binary files /dev/null and b/Git/Activities/Git evidence.docx differ diff --git a/Java/Activities/Activity1.java b/Java/Activities/Activity1.java new file mode 100644 index 0000000000..dddccaede9 --- /dev/null +++ b/Java/Activities/Activity1.java @@ -0,0 +1,18 @@ +package activities; + +public class Activity1 { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Car carObj = new Car("Red", "Auto", 2020); + carObj.displayCharacteristics(); + carObj.accelarate(); + carObj.brake(); + + Car carObj2 = new Car("Blue", "Manual", 2025); + carObj2.displayCharacteristics(); + carObj2.accelarate(); + carObj2.brake(); + } + +} diff --git a/Java/Activities/Activity10.java b/Java/Activities/Activity10.java new file mode 100644 index 0000000000..e83828f53b --- /dev/null +++ b/Java/Activities/Activity10.java @@ -0,0 +1,39 @@ +package activities; + +import java.util.HashSet; + +public class Activity10 { + public static void main(String[] args) { + HashSet hs = new HashSet(); + // Adding element to HashSet + hs.add("M"); + hs.add("B"); + hs.add("C"); + hs.add("A"); + hs.add("M"); + hs.add("X"); + + //Print HashSet + System.out.println("Original HashSet: " + hs); + //Print size of HashSet + System.out.println("Size of HashSet: " + hs.size()); + + //Remove element + System.out.println("Removing A from HashSet: " + hs.remove("A")); + //Remove element that is not present + if(hs.remove("Z")) { + System.out.println("Z removed from the Set"); + } else { + System.out.println("Z is not present in the Set"); + } + + //Search for element + System.out.println("Checking if M is present: " + hs.contains("M")); + //Print updated HashSet + System.out.println("Updated HashSet: " + hs); + + hs.removeAll(hs); + //Print size of HashSet + System.out.println("is HashSet empty: " + hs.isEmpty()); + } +} diff --git a/Java/Activities/Activity11.java b/Java/Activities/Activity11.java new file mode 100644 index 0000000000..211bfad16e --- /dev/null +++ b/Java/Activities/Activity11.java @@ -0,0 +1,31 @@ +package com.java.fst; +import java.util.HashMap; + +public class Activity11 { + public static void main(String[] args) { + HashMap hash_map = new HashMap(); + hash_map.put(1, "Red"); + hash_map.put(2, "Green"); + hash_map.put(3, "Blue"); + hash_map.put(4, "White"); + hash_map.put(5, "Black"); + + // Print the Map + System.out.println("The Original map: " + hash_map); + + // Remove one colour + hash_map.remove(4); + // Map after removing a colour + System.out.println("After removing White: " + hash_map); + + // Check if green exists + if(hash_map.containsValue("Green")) { + System.out.println("Green exists in the Map"); + } else { + System.out.println("Green does not exist in the Map"); + } + + // Print the size of the Map + System.out.println("Number of pairs in the Map is: " + hash_map.size()); + } +} \ No newline at end of file diff --git a/Java/Activities/Activity12.java b/Java/Activities/Activity12.java new file mode 100644 index 0000000000..37db33750b --- /dev/null +++ b/Java/Activities/Activity12.java @@ -0,0 +1,22 @@ +package com.java.fst; + + +interface Addable { + int add(int a , int b); +} +public class Activity12 { + public static void main(String[] args) { + Addable ad1 = (num1 , num2) -> num1 + num2; + + + Addable ad2 = (int num1 , int num2) -> {; + return num1+num2; + }; + + System.out.println(ad1.add(10, 50)); + System.out.println(ad1.add(20, 90)); + + + +} +} \ No newline at end of file diff --git a/Java/Activities/Activity13.java b/Java/Activities/Activity13.java new file mode 100644 index 0000000000..561f458f05 --- /dev/null +++ b/Java/Activities/Activity13.java @@ -0,0 +1,26 @@ +package com.java.fst; +import java.util.*; + +public class Activity13 { + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + ArrayList list = new ArrayList(); + Random indexGen = new Random(); + + System.out.print("Enter integers please "); + System.out.println("(EOF or non-integer to terminate): "); + + while(scan.hasNextInt()) { + list.add(scan.nextInt()); + } + + Integer nums[] = list.toArray(new Integer[0]); + int index = indexGen.nextInt(nums.length); + System.out.println("Index value generated: " + index); + System.out.println("Value in arary at generated index: " + nums[index]); + + scan.close(); + } + +} diff --git a/Java/Activities/Activity14.java b/Java/Activities/Activity14.java new file mode 100644 index 0000000000..62022d1559 --- /dev/null +++ b/Java/Activities/Activity14.java @@ -0,0 +1,38 @@ +package com.java.fst; +import java.io.File; +import java.io.IOException; +import org.apache.commons.io.FileUtils; + + public class Activity14 { + public static void main(String[] args) throws IOException { + try { + File file = new File("src/newfile.txt"); + boolean fStatus = file.createNewFile(); + if(fStatus) { + System.out.println("File created successfully!"); + } else { + System.out.println("File already exists at this path."); + } + + //get the file Object + File fileUtil = FileUtils.getFile("src/newfile.txt"); + //Read file + System.out.println("Data in file: " + FileUtils.readFileToString(fileUtil, "UTF8")); + + //Create directory + File destDir = new File("resources"); + //Copy file to directory + FileUtils.copyFileToDirectory(file, destDir); + + //Get file from new directory + File newFile = FileUtils.getFile(destDir, "src/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..688b9ec699 --- /dev/null +++ b/Java/Activities/Activity2.java @@ -0,0 +1,38 @@ +package com.java.fst; + +import javax.swing.tree.FixedHeightLayoutCache; + +public class Activity2 { + public static void main(String[] args) { + + Activity2 actobj = new Activity2(); + + int[] inputArr= {10,77,10,54,11,10}; + + int searchNum = 10; + int finalSum = 30; + + System.out.println("Does the sum equal to 30 ? " + actobj.result(inputArr , searchNum , finalSum)); + + } + + public boolean result (int [] nums , int searchNum , int fixedSum) + { + + int tempSum = 0; + + for(int num : nums) { + if (num == searchNum) + { + tempSum = tempSum+searchNum; + + } + if(tempSum > fixedSum) + break; + + } + return tempSum == fixedSum; + + } + +} diff --git a/Java/Activities/Activity3.java b/Java/Activities/Activity3.java new file mode 100644 index 0000000000..469ae56c91 --- /dev/null +++ b/Java/Activities/Activity3.java @@ -0,0 +1,24 @@ +package com.java.fst; + +public class Activity3 { + public static void main(String[] args) { + double seconds = 1000000000; + double EarthSeconds = 31557600; + double MercurySeconds= 0.2408467; + double VenusSeconds = 0.61519726; + double MarsSeconds = 1.8808158; + double JupiterSeconds = 11.862615; + double SaturnSeconds = 29.447498; + double UranuSeconds = 84.016846; + double NeptuneSeconds = 164.79132; + + System.out.println("Age on Mercury :" + seconds / EarthSeconds / MercurySeconds); + System.out.println("Age on Venus :" + seconds / EarthSeconds / VenusSeconds); + System.out.println("Age on Earth :" + seconds / EarthSeconds ); + System.out.println("Age on Mars :" + seconds / EarthSeconds / MarsSeconds); + System.out.println("Age on Jupiter :" + seconds / EarthSeconds / JupiterSeconds); + System.out.println("Age on Uranu :" + seconds / EarthSeconds / UranuSeconds); + System.out.println("Age on Neptune :" + seconds / EarthSeconds / NeptuneSeconds); + + } +} diff --git a/Java/Activities/Activity4.java b/Java/Activities/Activity4.java new file mode 100644 index 0000000000..ce40f063a3 --- /dev/null +++ b/Java/Activities/Activity4.java @@ -0,0 +1,27 @@ +package com.java.fst; + +public class Activity4 { + public static void main(String[] args) + { + + int[] arr = new int[] {78, 34, 1, 3, 90, 34, 6, 55, 20}; + System.out.println("Array elements after sorting:"); + + for (int i = 0; i < arr.length; i++) + { + for (int j = i + 1; j < arr.length; j++) + { + int tmp = 0; + if (arr[i] > arr[j]) + { + tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + } + } + //prints the sorted element of the array + System.out.println(arr[i]); + } + } + +} diff --git a/Java/Activities/Activity5.java b/Java/Activities/Activity5.java new file mode 100644 index 0000000000..ec9a50a4fd --- /dev/null +++ b/Java/Activities/Activity5.java @@ -0,0 +1,37 @@ +package com.java.fst; + + +abstract class Book { + String title; + abstract void setTitle(String s); + + String getTitle() + { + return title; + } + +} + +class MyBook extends Book{ + public void setTitle(String s) + { + title = s; + +} +} + +public class Activity5 { + + public static void main(String []args) { + //Initialize title of the book + String title = "Hover Car Racer"; + //Create object for MyBook + Book newNovel = new MyBook(); + //Set title + newNovel.setTitle(title); + + //Print result + System.out.println("The title is: " + newNovel.getTitle()); + } +} + diff --git a/Java/Activities/Activity6.java b/Java/Activities/Activity6.java new file mode 100644 index 0000000000..8e61a2a049 --- /dev/null +++ b/Java/Activities/Activity6.java @@ -0,0 +1,56 @@ +package com.java.fst; +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<>(); + } + + public void onboard(String passenger) { + this.passengers.add(passenger); + } + + public Date takeOff() { + this.lastTimeTookOf = new Date(); + return lastTimeTookOf; + } + + public void land() { + this.lastTimeLanded = new Date(); + this.passengers.clear(); + } + + public Date getLastTimeLanded() { + return lastTimeLanded; + } + + public List getPassengers() { + return passengers; + } +} + +public class Activity6 { + + public static void main(String[] args) throws InterruptedException { + Plane plane = new Plane(10); + + plane.onboard("John"); + plane.onboard("Steve"); + plane.onboard("Anna"); + + System.out.println("Plane took off at: " + plane.takeOff()); + System.out.println("People on the plane: " + plane.getPassengers()); + Thread.sleep(5000); + plane.land(); + 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..79852084e5 --- /dev/null +++ b/Java/Activities/Activity7.java @@ -0,0 +1,71 @@ +package com.java.fst; + + interface BicycleParts { + public int tyres = 2; + public int maxSpeed = 25; + } + + interface BicycleOperations { + public void applyBrake(int decrement); + public void speedUp(int increment); + } + + + class Bicycle implements BicycleParts, BicycleOperations { + + public int gears; + public int currentSpeed; + + + public Bicycle(int gears, int currentSpeed) { + this.gears = gears; + this.currentSpeed = currentSpeed; + } + + + 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); + } + + + public String bicycleDesc() { + return("No of gears are "+ gears + "\nSpeed of bicycle is " + maxSpeed); + } + } + + + class MountainBike extends Bicycle { + + + public int seatHeight; + + + public MountainBike(int gears, int currentSpeed, int startHeight) { + + super(gears, currentSpeed); + seatHeight = startHeight; + } + 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..45123c59bf --- /dev/null +++ b/Java/Activities/Activity8.java @@ -0,0 +1,5 @@ +package com.java.fst; + +public class Activity8 { + +} diff --git a/Java/Activities/Activity9.java b/Java/Activities/Activity9.java new file mode 100644 index 0000000000..280562c98d --- /dev/null +++ b/Java/Activities/Activity9.java @@ -0,0 +1,30 @@ +package com.java.fst; +import java.util.ArrayList; +import java.util.List; + +public class Activity9 { + public static void main(String[] args) { + + List myList = new ArrayList(); + + myList.add("Apple"); + myList.add("Watermelon"); + myList.add("Banana"); + + myList.add(3, "Pineapple"); + myList.add(1, "Kiwi"); + + System.out.println("Print All the Objects:"); + for(String fruits:myList){ + System.out.println(fruits); + } + + System.out.println("3rd element in the list is: " + myList.get(2)); + System.out.println("Is Pineapple is in list: " + myList.contains("Pineapple")); + System.out.println("Size of ArrayList: " + myList.size()); + + myList.remove("Kiwi"); + + System.out.println("New Size of ArrayList: " + myList.size()); + } +} \ No newline at end of file diff --git a/Java/Activities/Car.java b/Java/Activities/Car.java new file mode 100644 index 0000000000..30f8776bed --- /dev/null +++ b/Java/Activities/Car.java @@ -0,0 +1,38 @@ +package com.java.fst; + +public class Car { + + String color; + String transmission; + int make; + int tyres; + int doors; + + public Car(String color,String transmission , int make) + { + this.color=color; + this.transmission=transmission; + this.make=make; + + } + + public void characteristics() + { + System.out.println("color of the car is " + this.color); + System.out.println("Transmission of car " + this.transmission); + System.out.println("Make " + this.make); + System.out.println("Doors " + this.doors); + System.out.println("Tyres " + this.tyres); + + } + + public void accelerate() + { + System.out.println("Car moved forward"); + } + + public void brake() + { + System.out.println("Car stops"); + } +} diff --git a/Java/Activities/Example.java b/Java/Activities/Example.java new file mode 100644 index 0000000000..2471aed95d --- /dev/null +++ b/Java/Activities/Example.java @@ -0,0 +1,20 @@ +package com.java.fst; + +import java.util.ArrayList; +import java.util.List; + +public class Example { + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("Rick"); + list.add("Negan"); + list.add("Daryl"); + list.add("Glenn"); + list.add("Carl"); + + list.forEach( + (name) -> System.out.println(name) +); + +} +} diff --git a/Java/Activities/FirstClass.java b/Java/Activities/FirstClass.java new file mode 100644 index 0000000000..ead2b13b52 --- /dev/null +++ b/Java/Activities/FirstClass.java @@ -0,0 +1,9 @@ +package com.java.fst; + +public class FirstClass { + + public static void main(String[] args) { + System.out.println("Hello world"); + } + +} diff --git a/Python/Activities/Activity10.py b/Python/Activities/Activity10.py new file mode 100644 index 0000000000..01d7514d4e --- /dev/null +++ b/Python/Activities/Activity10.py @@ -0,0 +1,7 @@ + +num_tuple = (1, 5, 10, 81, 90) + +print("Elements that are divisible by 5:") +for num in num_tuple: + if (num % 5 == 0): + print(num) \ No newline at end of file diff --git a/Python/Activities/Activity11.py b/Python/Activities/Activity11.py new file mode 100644 index 0000000000..f6b3eabb0f --- /dev/null +++ b/Python/Activities/Activity11.py @@ -0,0 +1,14 @@ + +fruit_shop = { + "apple": 10, + "banana": 15, + "orange": 8, + "peaches": 15 +} + +key_to_check = input("What are you looking for? ").lower() + +if(key_to_check in fruit_shop): + print("Yes, this is available") +else: + print("No, this is not available") \ No newline at end of file diff --git a/Python/Activities/Activity12.py b/Python/Activities/Activity12.py new file mode 100644 index 0000000000..41777aa9e8 --- /dev/null +++ b/Python/Activities/Activity12.py @@ -0,0 +1,14 @@ + +# Define function to calculate sum +def calculateSum(num): + if num: + # Recursive function call + return num + calculateSum(num-1) + else: + return 0 + +# Call calculateSum() function +res = calculateSum(10) + +# 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..944a933858 --- /dev/null +++ b/Python/Activities/Activity13.py @@ -0,0 +1,15 @@ +# Custom function to calculate sum +def calculate_sum(numbers): + sum = 0 + for number in numbers: + sum += number + return sum + +# Define the list of numbers +numList = [10, 40, 60, 90] + +# Call the sum() function with numList as argument +result = calculate_sum(numList) + +# Print result with message +print("The sum of all the elements is: " + str(result)) diff --git a/Python/Activities/Activity14.py b/Python/Activities/Activity14.py new file mode 100644 index 0000000000..4a3d550f09 --- /dev/null +++ b/Python/Activities/Activity14.py @@ -0,0 +1,15 @@ + +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..248db5aa0d --- /dev/null +++ b/Python/Activities/Activity15.py @@ -0,0 +1,4 @@ +try: + print(x) +except NameError: + print("x hasn't been defined yet.") diff --git a/Python/Activities/Activity16.py b/Python/Activities/Activity16.py new file mode 100644 index 0000000000..a778661967 --- /dev/null +++ b/Python/Activities/Activity16.py @@ -0,0 +1,23 @@ + +class Car: + 'This class represents a 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() \ 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..f2270ebb12 --- /dev/null +++ b/Python/Activities/Activity17_18.py @@ -0,0 +1,36 @@ + +import pandas + +# create the data set +data = { + "Usernames": ["admin", "Charles", "Deku"], + "Passwords": ["password", "Charl13", "AllMight"] +} + +# convert data set into data frame +dataframe = pandas.DataFrame(data) + +# Print the DataFrame +print(dataframe) + +# writing the data frame into a csv file +dataframe.to_csv("sample.csv", index=False) + + +# read data from csv file +input_data = pandas.read_csv("sample.csv") + +# print the values in the user name + +username_col = input_data["Usernames"] +print(username_col) + +#print username and password of the second row + +# print username and password of second row +print(username_col[1]) +print(input_data["Passwords"]) + + +#sorting usernames +print(input_data.sort_values("Usernames",ascending=False)) \ No newline at end of file diff --git a/Python/Activities/Activity19_20.py b/Python/Activities/Activity19_20.py new file mode 100644 index 0000000000..6a2ff128ca --- /dev/null +++ b/Python/Activities/Activity19_20.py @@ -0,0 +1,42 @@ +# Import pandas +import pandas +from pandas import ExcelWriter + +# data set +data = { + 'FirstName':["Satvik", "Avinash", "Lahri"], + 'LastName':["Shah", "Kati", "Rath"], + 'Email':["satshah@example.com", "avinashK@example.com", "lahri.rath@example.com"], + 'PhoneNumber':["4537829158", "4892184058", "4528727830"] +} + +# convert into dataset +dataframe = pandas.DataFrame(data) + +# Print the dataframe +print(dataframe) + +# Writing the dataframe to a Excel file +writer = ExcelWriter('sample.xlsx') +dataframe.to_excel(writer, 'Sheet1', index = False) + +# closing the writer +writer.close() + +# Read the excel file +input_date = pandas.read_excel("sample.xlsx") + + +#print number of rows and columns +print(input_date.shape) + +print("Number of rows " , input_date.shape[0]) +print("Number of columns " , input_date.shape[1]) + +#print data in email columns only + +print(input_date["Email"]) + +#Sort the data + +print(input_date.sort_values("FirstName")) \ 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..30e8db4d5a --- /dev/null +++ b/Python/Activities/Activity3_4.py @@ -0,0 +1,46 @@ + +user1 = input("What is Player 1's name? ") +user2 = input("What is Player 2's name? ") + +# While looping endlessly +while True: + # Ask User1's choice + user1_answer = input(user1 + ", do you want to choose rock, paper or scissors? ").lower() + + # Ask User2's choice + user2_answer = input(user2 + ", do you want to choose rock, paper or scissors? ").lower() + + # Run the algorithm to see who wins + if user1_answer == user2_answer: + print("It's a tie!") + elif user1_answer == 'rock': + if user2_answer == 'scissors': + print("Rock wins!") + else: + print("Paper wins!") + elif user1_answer == 'scissors': + if user2_answer == 'paper': + print("Scissors win!") + else: + print("Rock wins!") + elif user1_answer == 'paper': + if user2_answer == 'rock': + print("Paper wins!") + else: + print("Scissors win!") + else: + print("Invalid input! You have not entered rock, paper or scissors, try again.") + + # Ask them if they want to play again + repeat = input("Do you want to play another round? Yes/No: ").lower() + + # If they say yes, don't do anything + if(repeat == "yes"): + pass + # If they say no, exit the game + elif(repeat == "no"): + raise SystemExit + # If they say anything else, exit with an error message. + else: + print("You entered an invalid option. Exiting now.") + raise SystemExit \ No newline at end of file diff --git a/Python/Activities/Activity5.py b/Python/Activities/Activity5.py new file mode 100644 index 0000000000..e038386eac --- /dev/null +++ b/Python/Activities/Activity5.py @@ -0,0 +1,5 @@ +number = int(input("Input a number: ")) + +# use for loop to iterate 10 times +for i in range(1,11): + print(number, ' x ', i, ' = ', number*i) diff --git a/Python/Activities/Activity6.py b/Python/Activities/Activity6.py new file mode 100644 index 0000000000..b08461fbdb --- /dev/null +++ b/Python/Activities/Activity6.py @@ -0,0 +1,2 @@ +for i in range(10): + print(str(i) * i) \ No newline at end of file diff --git a/Python/Activities/Activity7.py b/Python/Activities/Activity7.py new file mode 100644 index 0000000000..890908cf91 --- /dev/null +++ b/Python/Activities/Activity7.py @@ -0,0 +1,9 @@ +num_list = list(input("Enter List of numbers : ").split(",")) + +#num_list = [1,6,4,2,9] +sum = 0 + +for x in num_list: + sum=sum+int(x) + +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..bf40239f56 --- /dev/null +++ b/Python/Activities/Activity8.py @@ -0,0 +1,14 @@ +# Given list of numbers +numList = [10, 20, 30, 40, 10] +print("Given list is ", numList) + +# Get first element in list +firstElement = numList[0] +# Get last element in list +lastElement = numList[-1] + +# Check if first and last element are equal +if (firstElement == lastElement): + 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..500e677192 --- /dev/null +++ b/Python/Activities/Activity9.py @@ -0,0 +1,25 @@ + +# Given lists +listOne = [10, 20, 23, 11, 17] +listTwo = [13, 43, 24, 36, 12] + +# Print the lists +print("First List ", listOne) +print("Second List ", listTwo) + +# Declare a third list that will contain the result +thirdList = [] + +# Iterate through first list to get odd elements +for num in listOne: + if (num % 2 != 0): + thirdList.append(num) + +# Iterate through first list to get even elements +for num in listTwo: + if (num % 2 == 0): + thirdList.append(num) + +# Print result +print("result List is:") +print(thirdList) \ No newline at end of file diff --git a/Python/Activities/Activiy2.py b/Python/Activities/Activiy2.py new file mode 100644 index 0000000000..291eb81c73 --- /dev/null +++ b/Python/Activities/Activiy2.py @@ -0,0 +1,7 @@ +num = int(input("Enter a number : ")) + +if(num%2==0): + print("Number is even" ) +else: + print ("Number is odd") + \ No newline at end of file diff --git a/Python/Activities/Pandas.py b/Python/Activities/Pandas.py new file mode 100644 index 0000000000..184336b5ee --- /dev/null +++ b/Python/Activities/Pandas.py @@ -0,0 +1,18 @@ +# import pandas +import pandas as pd + +# Create a dictionary to hold our data +data = { + "X": [1, 2, 3, 4, 5], + "Y": [9, 8, 7, 6, 5], + "Z": [10, 12, 8, 4, 3] +} + +# Create a new DataFrame using our dictionary +table = pd.DataFrame(data) + +# Print the DataFrame +print(table) + +print(table["Z"][1]) +print(table["Z"]) \ No newline at end of file diff --git a/Python/Activities/PandasExample.py b/Python/Activities/PandasExample.py new file mode 100644 index 0000000000..2aceb3aaa9 --- /dev/null +++ b/Python/Activities/PandasExample.py @@ -0,0 +1,15 @@ +import pandas + +data = { + "Vehicle Type": ["Car", "Car", "Bike"], + "Manufacturer": ["Maruti", "Toyota", "Royal Enfield"], + "Model" : ["Swift", "Corolla", "Thunderbird"] +} + +dataframe = pandas.DataFrame(data) + +# Print the DataFrame +print(dataframe) + + +dataframe.to_csv("Vehicle.csv", index=False) \ No newline at end of file diff --git a/Python/Activities/activity1.py b/Python/Activities/activity1.py new file mode 100644 index 0000000000..68944126b5 --- /dev/null +++ b/Python/Activities/activity1.py @@ -0,0 +1,7 @@ +name = input("Enter your name : ") +age = int(input ("Enter your age : ")) + +year = (2025-age)+100 + + +print ("{} will turn 100 in the year {}".format(name,year)) \ No newline at end of file diff --git a/Rest_Assured/Activities/Activity1.java b/Rest_Assured/Activities/Activity1.java new file mode 100644 index 0000000000..157d22b361 --- /dev/null +++ b/Rest_Assured/Activities/Activity1.java @@ -0,0 +1,76 @@ +package activities; + +import java.util.HashMap; +import java.util.Map; + +import org.testng.annotations.Test; +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; + +public class Activity1 { + + + @Test(priority = 1) + public void addNewPet() + { + Map reqBody = new HashMap<>(); + reqBody.put("Id", 77232); + reqBody.put("name","Riley"); + reqBody.put("status", "alive"); + + given() + .baseUri("https://petstore.swagger.io/v2/pet") + .header("content-type","application/json") + .body(reqBody) + .log().all() + + .when() + .post() + + .then() + .log().all() + .statusCode(200) + .body("name", equalTo("Riley")) + .body("status", equalTo("alive")); + } + + @Test(priority = 2) + public void getPetInfo() + { + given() + .baseUri("https://petstore.swagger.io/v2/pet") + .header("content-type","application/json") + .pathParam("petId", 77232) + .log().all() + + .when() + .get("/{petId}") + + .then() + .log().all() + .statusCode(200) + .body("name", equalTo("Riley")) + .body("status", equalTo("alive")); + + } + @Test(priority = 3) + public void deletePet() + { + given() + .baseUri("https://petstore.swagger.io/v2/pet") + .header("content-type","application/json") + .pathParam("petId", 77232) + .log().all() + + .when() + .delete("/{petId}") + + .then() + .log().all() + .statusCode(200) + .body("message",equalTo(77232)); + + + } + +} diff --git a/Rest_Assured/Activities/Activity2.java b/Rest_Assured/Activities/Activity2.java new file mode 100644 index 0000000000..a84f6049c0 --- /dev/null +++ b/Rest_Assured/Activities/Activity2.java @@ -0,0 +1,95 @@ +package activities; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; + +import org.testng.annotations.Test; + +import io.restassured.response.Response; + +public class Activity2 { + + @Test(priority = 1) + + public void addNewUser() throws IOException + { + FileInputStream inputJson = new FileInputStream("src/test/java/activities/userinfo.json"); + given() + .baseUri("https://petstore.swagger.io/v2/user") + .header("Content-Type" , "application/json") + .body(inputJson) + + + .when() + .post() + + .then() + .body("code", equalTo(200)) + .body("message", equalTo("9901")); + inputJson.close(); + } + + @Test(priority = 2) + public void getUserInfo() + { + File outputJson = new File("src/test/java/activities/userGETResponse.json"); + + Response response = given() + .baseUri("https://petstore.swagger.io/v2/user") + .header("Content-Type" , "application/json") + .pathParam("username", "justinc") + + .when() + .get("/{username}"); + + String restBody = response.getBody().asPrettyString(); + + try { + outputJson.createNewFile(); + + + FileWriter writer = new FileWriter(outputJson.getPath()); + writer.write(restBody); + writer.close(); + + } + catch (IOException e) { + // TODO: handle exception + e.printStackTrace(); + } + + response.then().body("id",equalTo(2293)); + response.then().body("username",equalTo("justinc")); + response.then().body("firstName",equalTo("justinc")); + response.then().body("lastName",equalTo("justinc")); + response.then().body("email",equalTo("justinc")); + response.then().body("password",equalTo("justinc")); + response.then().body("phone",equalTo("justinc")); + + } + + + @Test(priority = 3) + public void deleteUser() + { + + given() + .baseUri("https://petstore.swagger.io/v2/user") + .header("Content-Type" , "application/json") + .pathParam("username","justinc") + + .when() + .delete("/{username}") + + .then() + .body("code", equalTo(200)) + .body("message",equalTo("justinc")); + } +} + diff --git a/Rest_Assured/Activities/Activity3.java b/Rest_Assured/Activities/Activity3.java new file mode 100644 index 0000000000..6ed2e27d07 --- /dev/null +++ b/Rest_Assured/Activities/Activity3.java @@ -0,0 +1,92 @@ +package activities; +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.equalTo; +import java.util.HashMap; +import java.util.Map; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import io.restassured.builder.RequestSpecBuilder; +import io.restassured.builder.ResponseSpecBuilder; +import io.restassured.specification.RequestSpecification; +import io.restassured.specification.ResponseSpecification; + +public class Activity3 { + // Declare request specification + RequestSpecification requestSpec; + // Declare response specification + ResponseSpecification responseSpec; + + @BeforeClass + public void setUp() { + // Create request specification + requestSpec = new RequestSpecBuilder() + // Set content type + .addHeader("Content-Type", "application/json") + // Set base URL + .setBaseUri("https://petstore.swagger.io/v2/pet") + // Build request specification + .build(); + + responseSpec = new ResponseSpecBuilder() + // Check status code in response + .expectStatusCode(200) + // Check response content type + .expectContentType("application/json") + // Check if response contains name property + .expectBody("status", equalTo("alive")) + // Build response specification + .build(); + } + + @DataProvider(name = "petInfo") + public Object[][] petInfoProvider() { + // Setting parameters to pass to test case + Object[][] testData = new Object[][] { + { 77232, "Riley", "alive" }, + { 77233, "Hansel", "alive" } + }; + return testData; + } + + @Test(priority=1, dataProvider = "petInfo") + // Test case using a DataProvider + public void addPets(int petId, String petName, String petStatus) { + Map reqBody = new HashMap<>(); + reqBody.put("id", petId); + reqBody.put("name", petName); + reqBody.put("status", petStatus); + + given().spec(requestSpec) // Use requestSpec + .body(reqBody) // Send request body + .when() + .post() // Send POST request + .then().spec(responseSpec) // Assertions using responseSpec + .body("name", equalTo(petName)); // Additional Assertion + } + + // Test case using a DataProvider + @Test( priority=2, dataProvider = "petInfo") + public void getPets(int petId, String petName, String petStatus) { + given().spec(requestSpec) // Use requestSpec + .pathParam("petId", petId) // Add path parameter + .log().all() // Log for request details + .when() + .get("/{petId}") // Send GET request + .then().spec(responseSpec) // Assertions using responseSpec + .body("name", equalTo(petName)) // Additional Assertion + .log().all(); + } + + // Test case using a DataProvider + @Test(priority=3, dataProvider = "petInfo") + public void deletePets(int petId, String petName, String petStatus) { + given().spec(requestSpec) // Use requestSpec + .pathParam("petId", petId) // Add path parameter + .when() + .delete("/{petId}") // Send GET request + .then() + .body("code", equalTo(200)) + .body("message", equalTo(""+petId)); // Assertions using responseSpec + } +} \ 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..7f313fb444 --- /dev/null +++ b/Rest_Assured/Activities/ConsumerTest.java @@ -0,0 +1,66 @@ +package liveProject; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +import au.com.dius.pact.consumer.dsl.DslPart; +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.RequestResponsePact; +import au.com.dius.pact.core.model.annotations.Pact; + +@ExtendWith(PactConsumerTestExt.class) +public class ConsumerTest { + // Set the headers + Map headers = new HashMap<>(); + + // Create the contract(Pact) + @Pact(consumer = "UserConsumer", provider = "UserProvider") + public RequestResponsePact createPact(PactDslWithProvider builder) { + // Set the headers + headers.put("Content-Type", "application/json"); + // The request and response body + DslPart reqResBody = new PactDslJsonBody(). + numberType("id", 123). + stringType("firstName", "Saahil"). + stringType("lastName", "Sharma"). + stringType("email", "saahil@example.com"); + + // Create the 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(); + } + + // Consumer test with mock provider + @Test + @PactTestFor(providerName = "UserProvider", port = "8282") + public void postRequestTest() { + // 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, add assertions + given().baseUri("http://localhost:8282/api/users").headers(headers).body(reqBody).log().all() + .when().post() + .then().statusCode(201).body("firstName", equalTo("Saahil")).log().all(); + } +} \ No newline at end of file diff --git a/Rest_Assured/Activities/GitHubProject.java b/Rest_Assured/Activities/GitHubProject.java new file mode 100644 index 0000000000..2fe46d8e68 --- /dev/null +++ b/Rest_Assured/Activities/GitHubProject.java @@ -0,0 +1,80 @@ +package activities; +import static io.restassured.RestAssured.given; +import static org.hamcrest.CoreMatchers.equalTo; +import java.util.HashMap; +import java.util.Map; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; +import io.restassured.builder.RequestSpecBuilder; +import io.restassured.builder.ResponseSpecBuilder; +import io.restassured.specification.RequestSpecification; +import io.restassured.specification.ResponseSpecification; + +public class GitHubProject { + // Declare request specification + RequestSpecification requestSpec; + // Declare response specification + ResponseSpecification responseSpec; + + @BeforeClass + public void setUp() { + // Create request specification + requestSpec = new RequestSpecBuilder() + // Set content type + .addHeader("Content-Type", "application/json") + // Set base URL + .setBaseUri("https://petstore.swagger.io/v2/pet") + // Build request specification + .build(); + + responseSpec = new ResponseSpecBuilder() + // Check status code in response + .expectStatusCode(200) + // Check response content type + .expectContentType("application/json") + // Check if response contains name property + .expectBody("status", equalTo("alive")) + // Build response specification + .build(); + } + + public void addPets(int petId, String petName, String petStatus) { + Map reqBody = new HashMap<>(); + reqBody.put("id", petId); + reqBody.put("name", petName); + reqBody.put("status", petStatus); + + given().spec(requestSpec) // Use requestSpec + .body(reqBody) // Send request body + .when() + .post() // Send POST request + .then().spec(responseSpec) // Assertions using responseSpec + .body("name", equalTo(petName)); // Additional Assertion + } + + // Test case using a DataProvider + @Test( priority=2, dataProvider = "petInfo") + public void getPets(int petId, String petName, String petStatus) { + given().spec(requestSpec) // Use requestSpec + .pathParam("petId", petId) // Add path parameter + .log().all() // Log for request details + .when() + .get("/{petId}") // Send GET request + .then().spec(responseSpec) // Assertions using responseSpec + .body("name", equalTo(petName)) // Additional Assertion + .log().all(); + } + + // Test case using a DataProvider + @Test(priority=3, dataProvider = "petInfo") + public void deletePets(int petId, String petName, String petStatus) { + given().spec(requestSpec) // Use requestSpec + .pathParam("petId", petId) // Add path parameter + .when() + .delete("/{petId}") // Send GET request + .then() + .body("code", equalTo(200)) + .body("message", equalTo(""+petId)); // Assertions using responseSpec + } +} \ No newline at end of file diff --git a/Rest_Assured/Activities/ProviderTest.java b/Rest_Assured/Activities/ProviderTest.java new file mode 100644 index 0000000000..ee5005982f --- /dev/null +++ b/Rest_Assured/Activities/ProviderTest.java @@ -0,0 +1,30 @@ +package liveProject; + +import au.com.dius.pact.provider.junit.Provider; +import au.com.dius.pact.provider.junit.State; +import au.com.dius.pact.provider.junit.loader.PactFolder; +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 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() {} +} \ No newline at end of file diff --git a/Rest_Assured/Activities/userInfo.json b/Rest_Assured/Activities/userInfo.json new file mode 100644 index 0000000000..446f0f55e7 --- /dev/null +++ b/Rest_Assured/Activities/userInfo.json @@ -0,0 +1,9 @@ +{ + "id": 2293, + "username": "justinc", + "firstName": "Justin", + "lastName": "Case", + "email": "justincase@mail.com", + "password": "password123", + "phone": "9812763450" +} \ No newline at end of file diff --git a/SQL/Activities/SQL_Activities_1-5.sql b/SQL/Activities/SQL_Activities_1-5.sql new file mode 100644 index 0000000000..402f31f942 --- /dev/null +++ b/SQL/Activities/SQL_Activities_1-5.sql @@ -0,0 +1,47 @@ +-- Activity 1 +CREATE TABLE salesman(salesman_id int , salesman_name varchar(32) , salesman_city varchar(32) , commission int) + +DESCRIBE salesman; +-- Activity 2 + +INSERT INTO salesman VALUES (5001 , 'James Hoog' , 'New York' , 15); +INSERT INTO salesman VALUES (5002 , 'Nail Knite' , 'Paris' , 13); +INSERT INTO salesman VALUES (5005 , 'Pit Alex' , 'London' , 11); +INSERT INTO salesman VALUES (5006 , 'Mc Lyon' , 'Paularis' , 14); +INSERT INTO salesman VALUES (5007 , 'Paul Adam' , 'Rome' , 13); +INSERT INTO salesman VALUES (5003 , 'Lauson hen' , 'San Jose' , 12); + +select * from salesman; + +-- Activity 3 +-- Show data from the salesman_id and salesman_city columns +SELECT salesman_id, salesman_city FROM salesman; + +-- show data of salesman from Paris +SELECT * from salesman where salesman_city = 'Paris'; + +-- Show salesman_id and commission of Paul Adam +SELECT salesman_id , commission from salesman where salesman_name = 'Paul Adam'; + +-- Activity 4 + +ALTER TABLE salesman ADD grade int; +UPDATE salesman set grade = 100; +select * from salesman; + + +-- Activity 5 + +-- Update the grade score of salesman from Rome to 200 +UPDATE salesman SET grade = 200 where SALESMAN_CITY='Rome'; + +-- Update the grade score of James Hoog to 300 +UPDATE salesman SET grade = 300 where SALESMAN_NAME='JamesHoog'; + +-- Update the name Mc Lyon to Pierre +UPDATE salesman set salesman_name='Pierre' where salesman_name='Mc Lyon'; + + +select * from salesman; + + diff --git a/SQL/Activities/SQL_Activities_6-8.sql b/SQL/Activities/SQL_Activities_6-8.sql new file mode 100644 index 0000000000..0ee9e83571 --- /dev/null +++ b/SQL/Activities/SQL_Activities_6-8.sql @@ -0,0 +1,74 @@ +-- Activity 6 + +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; + + select * from 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, order_date from orders order by order_date; + +-- Display the order number ordered by purchase amount in descending order +select order_no, purchase_amount 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) AS "Max Amount" FROM orders GROUP BY customer_id; + +-- Write an SQL statement to find the highest purchase amount on '2012-08-17' for each salesman with their ID. +SELECT salesman_id, order_date, MAX(purchase_amount) AS "Max Amount" FROM orders +WHERE order_date=To_DATE('2012/08/17', 'YYYY/MM/DD') GROUP BY salesman_id, order_date; + +-- 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, and 6000. +SELECT customer_id, order_date, MAX(purchase_amount) AS "Max Amount" FROM orders +GROUP BY customer_id, order_date +HAVING MAX(purchase_amount) IN(2030, 3450, 5760, 6000); + diff --git a/SQL/Activities/SQL_Activities_9-11.sql b/SQL/Activities/SQL_Activities_9-11.sql new file mode 100644 index 0000000000..0bfe985e8c --- /dev/null +++ b/SQL/Activities/SQL_Activities_9-11.sql @@ -0,0 +1,80 @@ + -- Activity 9 + + create table customers ( + customer_id int primary key, customer_name varchar(32), + city varchar(20), grade int, salesman_id int); + +-- Insert values into it +INSERT ALL + INTO customers VALUES (3002, 'Nick Rimando', 'New York', 100, 5001) + INTO customers VALUES (3007, 'Brad Davis', 'New York', 200, 5001) + INTO customers VALUES (3005, 'Graham Zusi', 'California', 200, 5002) + INTO customers VALUES (3008, 'Julian Green', 'London', 300, 5002) + INTO customers VALUES (3004, 'Fabian Johnson', 'Paris', 300, 5006) + INTO customers VALUES (3009, 'Geoff Cameron', 'Berlin', 100, 5003) + INTO customers VALUES (3003, 'Jozy Altidor', 'Moscow', 200, 5007) + INTO customers VALUES (3001, 'Brad Guzan', 'London', 300, 5005) +SELECT 1 FROM DUAL; + + +-- 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; \ No newline at end of file diff --git a/Selenium/Activities/Activity1.java b/Selenium/Activities/Activity1.java new file mode 100644 index 0000000000..f37483d12f --- /dev/null +++ b/Selenium/Activities/Activity1.java @@ -0,0 +1,22 @@ +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) { + //initialization of web browser + WebDriver driver = new FirefoxDriver(); + + driver.get("https://training-support.net/"); + + System.out.println("Browsre is open"); + + System.out.println("The Title of the page : "+ driver.getTitle()); + driver.findElement(By.linkText("About Us")).click(); + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity10.java b/Selenium/Activities/Activity10.java new file mode 100644 index 0000000000..9dcadb673a --- /dev/null +++ b/Selenium/Activities/Activity10.java @@ -0,0 +1,44 @@ +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) { + + WebDriver driver = new FirefoxDriver(); + + Actions builder = new Actions(driver); + driver.get("https://training-support.net/webelements/drag-drop"); + + System.out.println("Browsre is open"); + System.out.println("The Title of the page : "+ driver.getTitle()); + + + WebElement football = driver.findElement(By.id("ball")); + + WebElement dropzone1 = driver.findElement(By.id("dropzone1")); + + 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"); + } + + + + + } +} diff --git a/Selenium/Activities/Activity11.java b/Selenium/Activities/Activity11.java new file mode 100644 index 0000000000..75436f3b99 --- /dev/null +++ b/Selenium/Activities/Activity11.java @@ -0,0 +1,43 @@ +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_new.java b/Selenium/Activities/Activity11_new.java new file mode 100644 index 0000000000..a054a67f16 --- /dev/null +++ b/Selenium/Activities/Activity11_new.java @@ -0,0 +1,29 @@ +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) { + WebDriver driver = new FirefoxDriver(); + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + driver.get("https://www.training-support.net/webelements/dynamic-controls"); + System.out.println("Page title is: " + driver.getTitle()); + + WebElement checkbox = driver.findElement(By.id("checkbox")); + System.out.println("Checkbox is visible? " + checkbox.isDisplayed()); + + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + wait.until(ExpectedConditions.invisibilityOf(checkbox)); + System.out.println("Checkbox is visible? " + checkbox.isDisplayed()); + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + wait.until(ExpectedConditions.elementToBeClickable(checkbox)).click(); + System.out.println("Checkbox is selected? " + checkbox.isSelected()); + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity12.java b/Selenium/Activities/Activity12.java new file mode 100644 index 0000000000..4aa2d7dc05 --- /dev/null +++ b/Selenium/Activities/Activity12.java @@ -0,0 +1,31 @@ +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) { + //initialization of web browser + + WebDriver driver = new FirefoxDriver(); + + WebDriverWait wait = new WebDriverWait(driver , Duration.ofSeconds(10)); + driver.get("https://training-support.net/webelements/dynamic-content"); + + System.out.println("Page title :" + driver.getTitle()); + + driver.findElement(By.id("genButton")).click(); + wait.until(ExpectedConditions.textToBePresentInElementLocated(By.id("word"), "release")); + System.out.println("word found : "+ driver.findElement(By.id("word")).getText()); + + + + driver.quit(); + +} +} diff --git a/Selenium/Activities/Activity13.java b/Selenium/Activities/Activity13.java new file mode 100644 index 0000000000..4a05120407 --- /dev/null +++ b/Selenium/Activities/Activity13.java @@ -0,0 +1,43 @@ +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) { + + WebDriver driver = new FirefoxDriver(); + + driver.get("https://training-support.net/webelements/tables"); + + System.out.println("Browsre is open"); + + System.out.println("The Title of the page : "+ driver.getTitle()); + + // Number of columns + List cols = driver.findElements(By.xpath("//table/thead/tr/th")); + System.out.println("Number of columns : "+ cols.size()); + + // Number of Rows + List rows = driver.findElements(By.xpath("//table/tbody/tr")); + System.out.println("Number of rows : "+ rows.size()); + + + System.out.println(driver.findElement(By.xpath("//table/tbody/tr[3]")).getText()); + + List thirdrow = driver.findElements(By.xpath("//table/tbody/tr[3]")); + for(WebElement cell:thirdrow) + { + System.out.println(cell.getText()); + } + + System.out.println(driver.findElement(By.xpath("//table/tbody/tr[2]/td[2]")).getText()); + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity14.java b/Selenium/Activities/Activity14.java new file mode 100644 index 0000000000..24c6162c01 --- /dev/null +++ b/Selenium/Activities/Activity14.java @@ -0,0 +1,41 @@ +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) { + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/tables"); + + System.out.println("Browsre is open"); + + System.out.println("The Title of the page : "+ driver.getTitle()); + + // 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()); + + // Number of Rows + List rows = driver.findElements(By.xpath("//table[contains(@class,'table-auto')]/thead/tr")); + System.out.println("Number of rows : "+ rows.size()); + + // 5th row book name + WebElement cellValue = driver.findElement(By.xpath("//table[contains(@class,'table-auto')]/tbody/tr[5]/td[2]")); + System.out.println("Book name before starting: " + cellValue.getText()); + + + // sort the table + + driver.findElement(By.xpath("//table[contains(@class,'table-auto')]/thead/tr/th[5]")).click(); + + + System.out.println("Book name after soring : " + cellValue.getText()); + driver.quit(); + } + +} diff --git a/Selenium/Activities/Activity15.java b/Selenium/Activities/Activity15.java new file mode 100644 index 0000000000..984bfa9bdb --- /dev/null +++ b/Selenium/Activities/Activity15.java @@ -0,0 +1,33 @@ +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 Activity15 { + + public static void main(String[] args) { + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/dynamic-attributes"); + + System.out.println("Browsre is open"); + System.out.println("The Title of the page : "+ driver.getTitle()); + WebElement nameField = driver.findElement(By.xpath("//input[contains(@id,'full-name-')]")); + WebElement emailField = driver.findElement(By.xpath("//input[contains(@id,'-email')]")); + WebElement dataField = driver.findElement(By.xpath("//label[contains(text(),'event?')]/folowing-sibling::input[@type='date']")); + WebElement detailsField = driver.findElement(By.xpath("//textarea[contains(@id,'-additional-details-')]")); + + + nameField.sendKeys("malli"); + emailField.sendKeys("gownivarimalli@gmail.com"); + dataField.sendKeys("2025-03-15"); + detailsField.sendKeys("End of course party"); + + driver.findElement(By.xpath("//buttonn[text()='Submit']")).click(); + + String message = driver.findElement(By.id("action-confirmation")).getText(); + System.out.println("Success message : " + message); + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity16.java b/Selenium/Activities/Activity16.java new file mode 100644 index 0000000000..13e9003c00 --- /dev/null +++ b/Selenium/Activities/Activity16.java @@ -0,0 +1,36 @@ +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.ui.Select; + +public class Activity16 { + public static void main(String[] args) { + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/selects"); + + System.out.println("Browsre is open"); + System.out.println("The Title of the page : "+ driver.getTitle()); + + WebElement selectElement = driver.findElement(By.cssSelector("select.h-10")); + Select dropdown = new Select(selectElement); + + dropdown.selectByVisibleText("One"); + + System.out.println(dropdown.getFirstSelectedOption().getText()); + + dropdown.selectByIndex(2); + + System.out.println(dropdown.getFirstSelectedOption().getText()); + + dropdown.selectByValue("three"); + + + for(WebElement option : dropdown.getOptions()) + { + System.out.println(option.getText()); + } + } +} diff --git a/Selenium/Activities/Activity18.java b/Selenium/Activities/Activity18.java new file mode 100644 index 0000000000..965c4c63ac --- /dev/null +++ b/Selenium/Activities/Activity18.java @@ -0,0 +1,28 @@ +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) { + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/alerts"); + + System.out.println("Browsre is open"); + System.out.println("The Title of the page : "+ driver.getTitle()); + + driver.findElement(By.id("simple")).click(); + Alert simpleAlert = driver.switchTo().alert(); + + + System.out.println(simpleAlert.getText()); + + simpleAlert.accept(); + + System.out.println("message : "+ driver.findElement(By.id("result")).getText()); + +} +} diff --git a/Selenium/Activities/Activity19.java b/Selenium/Activities/Activity19.java new file mode 100644 index 0000000000..bff91934e9 --- /dev/null +++ b/Selenium/Activities/Activity19.java @@ -0,0 +1,28 @@ +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) { + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/alerts"); + + System.out.println("Browsre is open"); + System.out.println("The Title of the page : "+ driver.getTitle()); + + driver.findElement(By.id("confirmation")).click(); + Alert confirmAlert = driver.switchTo().alert(); + + + System.out.println(confirmAlert.getText()); + + confirmAlert.accept(); + + System.out.println("message : "+ driver.findElement(By.id("result")).getText()); + +} +} diff --git a/Selenium/Activities/Activity2.java b/Selenium/Activities/Activity2.java new file mode 100644 index 0000000000..4e2a29b1a8 --- /dev/null +++ b/Selenium/Activities/Activity2.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 Activity2 { + + public static void main(String[] args) { + //initialization of web browser + WebDriver driver = new FirefoxDriver(); + + driver.get("https://training-support.net/webelements/login-form/"); + + System.out.println("Browsre is open"); + + System.out.println("The Title of the page : "+ driver.getTitle()); + + + driver.findElement(By.id("username")).sendKeys("admin"); + + driver.findElement(By.id("password")).sendKeys("password"); + + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + + String message = driver.findElement(By.tagName("h1")).getText(); + System.out.println(message); + + driver.quit(); + + } + +} diff --git a/Selenium/Activities/Activity21.java b/Selenium/Activities/Activity21.java new file mode 100644 index 0000000000..40a3e8d2de --- /dev/null +++ b/Selenium/Activities/Activity21.java @@ -0,0 +1,51 @@ +package activities; + +import java.time.Duration; + +import org.openqa.selenium.Alert; +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) { + WebDriver driver = new FirefoxDriver(); + + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + driver.get("https://training-support.net/webelements/tabs"); + + System.out.println("Browsre is open"); + System.out.println("The Title of the page : "+ driver.getTitle()); + System.out.println("Current Tab :" + driver.getWindowHandle()); + + wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[text()='Open A New Tab']"))).click(); + + wait.until(ExpectedConditions.numberOfWindowsToBe(2)); + + System.out.println("Currently open windows : " + driver.getWindowHandles()); + + + + for(String handle : driver.getWindowHandles()) + { + driver.switchTo().window(handle); + + } + + wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[contains(text(),'Another One')]"))).click(); + + wait.until(ExpectedConditions.numberOfWindowsToBe(3)); + + for(String handle : driver.getWindowHandles()) + { + driver.switchTo().window(handle); + } + + driver.quit(); +} +} + diff --git a/Selenium/Activities/Activity3.java b/Selenium/Activities/Activity3.java new file mode 100644 index 0000000000..3bc2fc81ca --- /dev/null +++ b/Selenium/Activities/Activity3.java @@ -0,0 +1,28 @@ +package activities; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; + +public class Activity3 { + public static void main(String[] args) { +WebDriver driver = new FirefoxDriver(); + + driver.get("https://training-support.net/webelements/login-form/"); + + System.out.println("Browsre is open"); + System.out.println("The Title of the page : "+ driver.getTitle()); + + driver.findElement(By.xpath("//input[@placeholder='Username']")).sendKeys("admin"); + + driver.findElement(By.xpath("//input[@placeholder='Password']")).sendKeys("password"); + + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + String message = driver.findElement(By.tagName("h1")).getText(); + System.out.println("Login message : " + message); + + + + } +} diff --git a/Selenium/Activities/Activity4.java b/Selenium/Activities/Activity4.java new file mode 100644 index 0000000000..3deff51f38 --- /dev/null +++ b/Selenium/Activities/Activity4.java @@ -0,0 +1,36 @@ +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) { + // Create a new instance of the Firefox driver + WebDriver driver = new FirefoxDriver(); + + // Open the page + driver.get("https://training-support.net/webelements/target-practice"); + // Print the title of the page + System.out.println("Page title: " + driver.getTitle()); + + // Find the 3rd header and print its text + String thirdHeaderText = driver.findElement(By.xpath("//h3[contains(text(), '#3')]")).getText(); + System.out.println(thirdHeaderText); + // 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(); + } +} \ No newline at end of file diff --git a/Selenium/Activities/Activity4_new.java b/Selenium/Activities/Activity4_new.java new file mode 100644 index 0000000000..3ce9a90ea4 --- /dev/null +++ b/Selenium/Activities/Activity4_new.java @@ -0,0 +1,28 @@ +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) { + + WebDriver driver = new FirefoxDriver(); + + driver.get("https://training-support.net/webelements/target-practice"); + System.out.println("Page title: " + driver.getTitle()); + + + String thirdHeaderText = driver.findElement(By.xpath("//h3[contains(text(), '#3')]")).getText(); + System.out.println(thirdHeaderText); + 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()); + String purpleButtonClass = driver.findElement(By.xpath("//button[text()='Purple']")).getDomAttribute("class"); + System.out.println(purpleButtonClass); + String slateButtonText = driver.findElement(By.xpath("//button[contains(@class, 'slate')]")).getText(); + System.out.println(slateButtonText); + driver.quit(); + } +} \ No newline at end of file diff --git a/Selenium/Activities/Activity5.java b/Selenium/Activities/Activity5.java new file mode 100644 index 0000000000..4192283a2e --- /dev/null +++ b/Selenium/Activities/Activity5.java @@ -0,0 +1,32 @@ +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 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 checkbox + WebElement checkbox = driver.findElement(By.id("checkbox")); + // Find the toggle button and click it + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + // Check if it is displayed on the page + System.out.println("Checkbox is displayed: " + checkbox.isDisplayed()); + // Click the button again + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + // Check if it is displayed on the page + System.out.println("Checkbox is displayed: " + checkbox.isDisplayed()); + + // Close the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity5_new.java b/Selenium/Activities/Activity5_new.java new file mode 100644 index 0000000000..6421e2a66a --- /dev/null +++ b/Selenium/Activities/Activity5_new.java @@ -0,0 +1,26 @@ +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) { + WebDriver driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/dynamic-controls"); + System.out.println("Page title: " + driver.getTitle()); + + WebElement checkbox = driver.findElement(By.id("checkbox")); + + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + + System.out.println("Checkbox is displayed: " + checkbox.isDisplayed()); + + driver.findElement(By.xpath("//button[text()='Toggle Checkbox']")).click(); + System.out.println("Checkbox is displayed: " + checkbox.isDisplayed()); + + + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity6.java b/Selenium/Activities/Activity6.java new file mode 100644 index 0000000000..bc8e522d5a --- /dev/null +++ b/Selenium/Activities/Activity6.java @@ -0,0 +1,32 @@ +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 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 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 the browser + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity6_new.java b/Selenium/Activities/Activity6_new.java new file mode 100644 index 0000000000..35d09d99c3 --- /dev/null +++ b/Selenium/Activities/Activity6_new.java @@ -0,0 +1,23 @@ +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) { + WebDriver driver = new FirefoxDriver(); + + driver.get("https://training-support.net/webelements/dynamic-controls"); + + System.out.println("Page title: " + driver.getTitle()); + WebElement checkBox = driver.findElement(By.id("checkbox")); + checkBox.click(); + System.out.println("Checkbox is selected: " + checkbox.isSelected()); + checkBox.click(); + + System.out.println("Checkbox is selected: " + checkbox.isSelected()); + driver.quit(); + } +} diff --git a/Selenium/Activities/Activity8.java b/Selenium/Activities/Activity8.java new file mode 100644 index 0000000000..036eb17149 --- /dev/null +++ b/Selenium/Activities/Activity8.java @@ -0,0 +1,51 @@ +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 Activity8 { + + public static void main(String[] args) { + + WebDriver driver = new FirefoxDriver(); + + Actions builder = new Actions(driver); + driver.get("https://training-support.net/webelements/mouse-events"); + + System.out.println("Browsre is open"); + System.out.println("The Title of the page : "+ driver.getTitle()); + + WebElement cargoLock= driver.findElement(By.xpath("//h1[text()='Cargo.lock']")); + WebElement cargoTom1= 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']")); + + + builder.click(cargoLock).pause(2000).click(cargoTom1).pause(2000).build().perform(); + + + String actionMessage = driver.findElement(By.id("result")).getText(); + System.out.println(actionMessage); + + + builder.doubleClick(srcButton).pause(2000).contextClick(targetButton).pause(2000).perform(); + + WebElement openElement = driver.findElement(By.xpath("//span[text()='Open']")); + builder.click(openElement).build().perform(); + + + actionMessage= driver.findElement(By.id("result")).getText(); + System.out.println(actionMessage); + + + + + 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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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.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/Activity1.java b/Selenium/Project/Activity1.java new file mode 100644 index 0000000000..ea8383884c --- /dev/null +++ b/Selenium/Project/Activity1.java @@ -0,0 +1,38 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; + +import static org.testng.Assert.assertEquals; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.annotations.AfterClass; + +public class Activity1 { + + //declare the class objects + WebDriver driver; + + @BeforeClass + public void setUp() + { + driver = new FirefoxDriver(); + driver.get("http://alchemy.hguy.co/orangehrm"); + System.out.println(driver.getTitle()); + } + + @Test(priority = 1) + public void pageTitleTest() + { + assertEquals(driver.getTitle(),"OrangeHRM"); + } + + @AfterClass + public void tearDown() + { + driver.quit(); + } + +} diff --git a/Selenium/Project/Activity2.java b/Selenium/Project/Activity2.java new file mode 100644 index 0000000000..874ec7a8f5 --- /dev/null +++ b/Selenium/Project/Activity2.java @@ -0,0 +1,41 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; + +import static org.testng.Assert.assertEquals; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.annotations.AfterClass; + +public class Activity2 { + + //declare the class objects + WebDriver driver; + + + @BeforeClass + public void setUp() + { + driver = new FirefoxDriver(); + driver.get("http://alchemy.hguy.co/orangehrm"); + + } + + @Test(priority = 1) + public void urlHeaderImage() + { + WebElement headerImage = driver.findElement(By.xpath("//*[@id=\"divLogo\"]/img")); + System.out.println(headerImage.getAttribute("src")); + } + + @AfterClass + public void tearDown() + { + driver.quit(); + } + +} diff --git a/Selenium/Project/Activity3.java b/Selenium/Project/Activity3.java new file mode 100644 index 0000000000..47fb75d836 --- /dev/null +++ b/Selenium/Project/Activity3.java @@ -0,0 +1,66 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; + +import static org.testng.Assert.assertEquals; + +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.annotations.AfterClass; + +public class Activity3 { + + //declare the class objects + WebDriver driver; + + + @BeforeClass + public void setUp() + { + driver = new FirefoxDriver(); + driver.get("http://alchemy.hguy.co/orangehrm"); + + } + + @Test(priority = 1) + public void login() + { + WebElement userName = driver.findElement(By.id("txtUsername")); + WebElement password = driver.findElement(By.id("txtPassword")); + WebElement loginButton = driver.findElement(By.id("btnLogin")); + + userName.sendKeys("orange"); + password.sendKeys("orangepassword123"); + loginButton.click(); + + System.out.println(driver.getTitle()); + + } + + @Test(priority = 2) + public void verifyHomepage() + { + + WebElement welcome = driver.findElement(By.id("welcome")); + Boolean msg = welcome.isDisplayed(); + if(msg.equals("welcome")) + { + System.out.println("Home page is opened"); + } + else + { + System.out.println("Login is failed"); + } + } + + @AfterClass + public void tearDown() + { + driver.quit(); + } + +} diff --git a/Selenium/Project/Activity4.java b/Selenium/Project/Activity4.java new file mode 100644 index 0000000000..939faa2b86 --- /dev/null +++ b/Selenium/Project/Activity4.java @@ -0,0 +1,109 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; + +import static org.testng.Assert.assertEquals; + +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.annotations.AfterClass; + +public class Activity4 { + + //declare the class objects + WebDriver driver; + + + @BeforeClass + public void setUp() + { + driver = new FirefoxDriver(); + driver.get("http://alchemy.hguy.co/orangehrm"); + + } + + @Test(priority = 1) + public void login() + { + WebElement userName = driver.findElement(By.id("txtUsername")); + WebElement password = driver.findElement(By.id("txtPassword")); + WebElement loginButton = driver.findElement(By.id("btnLogin")); + + userName.sendKeys("orange"); + password.sendKeys("orangepassword123"); + loginButton.click(); + + System.out.println(driver.getTitle()); + + } + + @Test(priority = 2) + + public void addEmployee() + { + WebElement PIM = driver.findElement(By.xpath("//*[@id=\"menu_pim_viewPimModule\"]/b")); + PIM.click(); + + WebElement employeeList = driver.findElement(By.id("menu_pim_viewEmployeeList")); + employeeList.click(); + + WebElement addEmployee = driver.findElement(By.id("btnAdd")); + addEmployee.click(); + + WebElement firstName = driver.findElement(By.id("firstName")); + firstName.sendKeys("Malli"); + + WebElement lastName = driver.findElement(By.id("lastName")); + lastName.sendKeys("Gownivari"); + + driver.findElement(By.id("btnSave")).click(); + } + + + @Test (priority = 3) + public void verifyEmployeeDetails() throws InterruptedException { + + + WebElement PIM = driver.findElement(By.xpath("//*[@id=\"menu_pim_viewPimModule\"]/b")); + PIM.click(); + + WebElement employeeList = driver.findElement(By.id("menu_pim_viewEmployeeList")); + employeeList.click(); + + WebElement employeName = driver.findElement(By.id("empsearch_employee_name_empName")); + employeName.clear(); + + Thread.sleep(10000); + employeName.sendKeys("Malli Gownivari"); + + Thread.sleep(10000); + WebElement selectEmployee = driver.findElement(By.xpath("/html/body/div[4]/ul/li")); + selectEmployee.click(); + + + + WebElement employeeSelected = driver.findElement(By.xpath("empsearch_employee_name_empName")); + String emp = employeeSelected.getText(); + + if(emp.equals("Malli Gownivari")) + { + System.out.println("Employee details added successfully"); + } + else { + System.out.println("Employee details not added"); + } + + } + + + @AfterClass + public void tearDown() + { + driver.quit(); + } + +} diff --git a/Selenium/Project/Activity5.java b/Selenium/Project/Activity5.java new file mode 100644 index 0000000000..1bc95744fa --- /dev/null +++ b/Selenium/Project/Activity5.java @@ -0,0 +1,87 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; + +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; +import org.testng.annotations.AfterClass; + +public class Activity5 { + + //declare the class objects + WebDriver driver; + + + @BeforeClass + public void setUp() + { + driver = new FirefoxDriver(); + driver.get("http://alchemy.hguy.co/orangehrm"); + + } + + @Test(priority = 1) + public void login() + { + WebElement userName = driver.findElement(By.id("txtUsername")); + WebElement password = driver.findElement(By.id("txtPassword")); + WebElement loginButton = driver.findElement(By.id("btnLogin")); + + userName.sendKeys("orange"); + password.sendKeys("orangepassword123"); + loginButton.click(); + + System.out.println(driver.getTitle()); + + } + + @Test(priority = 2) + public void editMyInfo() throws InterruptedException + { + WebElement myInfo_Link = driver.findElement(By.id("menu_pim_viewMyDetails")); + + myInfo_Link.click(); + + //Edit button xpath is not workings + WebElement edit = driver.findElement(By.xpath("//*[@id=\"btnSave\"]")); + edit.click(); + + + WebElement firstName = driver.findElement(By.id("personal_txtEmpFirstName")); + firstName.clear(); + firstName.sendKeys("Malli"); + + + WebElement lastName = driver.findElement(By.id("personal_txtEmpFirstName")); + lastName.clear(); + lastName.sendKeys("Gownivari"); + + + WebElement gender = driver.findElement(By.id("personal_optGender_1")); + gender.click(); + + + WebElement nationality = driver.findElement(By.id("personal_cmbNation")); + Select countries = new Select(nationality); + countries.selectByVisibleText("American"); + + + WebElement saveButton = driver.findElement(By.id("btnSave")); + saveButton.click(); + + } + + @AfterClass + public void tearDown() + { + driver.quit(); + } + +} + + + diff --git a/Selenium/Project/Activity6.java b/Selenium/Project/Activity6.java new file mode 100644 index 0000000000..0daeecda4e --- /dev/null +++ b/Selenium/Project/Activity6.java @@ -0,0 +1,71 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; + +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; +import org.testng.Assert; +import org.testng.annotations.AfterClass; + +public class Activity6 { + + //declare the class objects + WebDriver driver; + + + @BeforeClass + public void setUp() + { + driver = new FirefoxDriver(); + driver.get("http://alchemy.hguy.co/orangehrm"); + + } + + @Test(priority = 1) + public void login() + { + WebElement userName = driver.findElement(By.id("txtUsername")); + WebElement password = driver.findElement(By.id("txtPassword")); + WebElement loginButton = driver.findElement(By.id("btnLogin")); + + userName.sendKeys("orange"); + password.sendKeys("orangepassword123"); + loginButton.click(); + + System.out.println(driver.getTitle()); + + } + + @Test + public void verifyDirectoryMenu() + { + + WebElement dashboard = driver.findElement(By.xpath("//*[@id=\"menu_dashboard_index\"]/b")); + System.out.println("Dashboard is displayed : " + dashboard.isDisplayed()); + + dashboard.click(); + + String title = driver.getTitle(); + + Assert.assertEquals(title, "Search Directory"); + System.out.println("Title is same as " + title); + + + + } + + + @AfterClass + public void tearDown() + { + driver.quit(); + } + +} + + + diff --git a/Selenium/Project/Activity7.java b/Selenium/Project/Activity7.java new file mode 100644 index 0000000000..1673fd097f --- /dev/null +++ b/Selenium/Project/Activity7.java @@ -0,0 +1,124 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; +import org.apache.poi.ss.formula.functions.Today; +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; +import org.testng.Assert; +import org.testng.annotations.AfterClass; + +public class Activity7 { + + //declare the class objects + WebDriver driver; + + + @BeforeClass + public void setUp() + { + driver = new FirefoxDriver(); + driver.get("http://alchemy.hguy.co/orangehrm"); + + } + + @Test(priority = 1) + public void login() + { + WebElement userName = driver.findElement(By.id("txtUsername")); + WebElement password = driver.findElement(By.id("txtPassword")); + WebElement loginButton = driver.findElement(By.id("btnLogin")); + + userName.sendKeys("orange"); + password.sendKeys("orangepassword123"); + loginButton.click(); + + System.out.println(driver.getTitle()); + + } + + + @Test(priority = 2) + public void myInfo() + { + WebElement myInfo = driver.findElement(By.id("menu_pim_viewMyDetails")); + myInfo.click(); + + } + + @Test(priority = 3) + public void addQualification() + { + + WebElement qualification = driver.findElement(By.xpath("//*[@id=\"sidenav\"]/li[9]/a")); + qualification.click(); + + WebElement addWorkExp = driver.findElement(By.id("addWorkExperience")); + addWorkExp.click(); + + + WebElement company = driver.findElement(By.id("experience_employer")); + company.sendKeys("IBM"); + + WebElement jobTitle = driver.findElement(By.id("experience_jobtitle")); + jobTitle.sendKeys("Tester"); + + + + + WebElement fromDate = driver.findElement(By.id("experience_from_date")); + fromDate.clear(); + fromDate.click(); + + WebElement from_month = driver.findElement(By.xpath("//*[@id=\"frmWorkExperience\"]/fieldset/ol/li[3]/img")); + Select from_monthCombo = new Select(from_month); + from_monthCombo.selectByVisibleText("Mar"); + + WebElement from_year = driver.findElement(By.xpath("//*[@id=\"ui-datepicker-div\"]/div/div/select[2]")); + Select from_yearCombo = new Select(from_year); + from_yearCombo.selectByVisibleText("2015"); + + driver.findElement(By.xpath("//*[@id=\"ui-datepicker-div\"]/table/tbody/tr[4]/td[3]/a")).click(); + + + + + WebElement toDate = driver.findElement(By.id("experience_from_date")); + toDate.clear(); + toDate.click(); + + WebElement to_month = driver.findElement(By.xpath("//*[@id=\"frmWorkExperience\"]/fieldset/ol/li[3]/img")); + Select to_monthCombo = new Select(to_month); + to_monthCombo.selectByVisibleText("Mar"); + + WebElement to_year = driver.findElement(By.xpath("//*[@id=\"ui-datepicker-div\"]/div/div/select[2]")); + Select to_yearCombo = new Select(to_year); + to_yearCombo.selectByVisibleText("2020"); + + driver.findElement(By.xpath("//*[@id=\"ui-datepicker-div\"]/table/tbody/tr[4]/td[3]/a")).click(); + + + + WebElement addComment = driver.findElement(By.id("experience_comments")); + addComment.sendKeys("added the experience"); + + + WebElement saveBtn = driver.findElement(By.id("btnWorkExpSave")); + saveBtn.click(); + +} + + + @AfterClass + public void tearDown() + { + driver.quit(); + } + +} + + + diff --git a/Selenium/Project/Activity8.java b/Selenium/Project/Activity8.java new file mode 100644 index 0000000000..f0c69fb90d --- /dev/null +++ b/Selenium/Project/Activity8.java @@ -0,0 +1,70 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; + +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; +import org.testng.Assert; +import org.testng.annotations.AfterClass; + +public class Activity8 { + + //declare the class objects + WebDriver driver; + + + @BeforeClass + public void setUp() + { + driver = new FirefoxDriver(); + driver.get("http://alchemy.hguy.co/orangehrm"); + + } + + @Test(priority = 1) + public void login() + { + WebElement userName = driver.findElement(By.id("txtUsername")); + WebElement password = driver.findElement(By.id("txtPassword")); + WebElement loginButton = driver.findElement(By.id("btnLogin")); + + userName.sendKeys("orange"); + password.sendKeys("orangepassword123"); + loginButton.click(); + + System.out.println(driver.getTitle()); + + } + + public void leaveApply() + { + WebElement dashboard = driver.findElement(By.id("menu_dashboard_index")); + dashboard.click(); + + WebElement LeaveLink = driver.findElement(By.xpath("//*[@id=\"dashboard-quick-launch-panel-menu_holder\"]/table/tbody/tr/td[4]/div/a/img")); + LeaveLink.click(); + + WebElement applyLeave = driver.findElement(By.xpath("menu_leave_applyLeave")); + applyLeave.click(); + + //I'm getting No leave Types with leave balances + + // So Unable to do apply for leave + + + } + + @AfterClass + public void tearDown() + { + driver.quit(); + } + +} + + + diff --git a/Selenium/Project/Activity9.java b/Selenium/Project/Activity9.java new file mode 100644 index 0000000000..6a5498036e --- /dev/null +++ b/Selenium/Project/Activity9.java @@ -0,0 +1,86 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; + +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; +import org.testng.Assert; +import org.testng.annotations.AfterClass; + +public class Activity9 { + + //declare the class objects + WebDriver driver; + + + @BeforeClass + public void setUp() + { + driver = new FirefoxDriver(); + driver.get("http://alchemy.hguy.co/orangehrm"); + + } + + @Test(priority = 1) + public void login() + { + WebElement userName = driver.findElement(By.id("txtUsername")); + WebElement password = driver.findElement(By.id("txtPassword")); + WebElement loginButton = driver.findElement(By.id("btnLogin")); + + userName.sendKeys("orange"); + password.sendKeys("orangepassword123"); + loginButton.click(); + + System.out.println(driver.getTitle()); + + } + + @Test(priority = 2) + public void myInfo() + { + WebElement myInfo = driver.findElement(By.id("menu_pim_viewMyDetails")); + myInfo.click(); + + } + + + @Test(priority = 3) + public void emergencyContact() + { + WebElement emergency_contact = driver.findElement(By.xpath("/html/body/div[1]/div[3]/div/div[1]/ul/li[3]/a")); + emergency_contact.click(); + + List allRows = driver.findElements(By.xpath("//table[@class='emgcontact_list']//tr")); + + + for (WebElement row : allRows) { + List cells = row.findElements(By.tagName("td")); + + + for (WebElement cell : cells) { + + System.out.println(cell.getText()); + + } + + } + + } + + @AfterClass + public void tearDown() + { + driver.quit(); + } + +} + + + diff --git a/Selenium/Project/pom.xml b/Selenium/Project/pom.xml new file mode 100644 index 0000000000..2f0b48d17c --- /dev/null +++ b/Selenium/Project/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + com.ibm + FST_TestNG + 0.0.1-SNAPSHOT + + + + + org.seleniumhq.selenium + selenium-java + 4.27.0 + + + + org.testng + testng + 7.10.2 + test + + + + org.apache.poi + poi + 5.3.0 + + + + org.apache.poi + poi-ooxml + 5.3.0 + + + + com.opencsv + opencsv + 5.9 + + + + \ No newline at end of file diff --git a/TestNG/Activities/Activity1.java b/TestNG/Activities/Activity1.java new file mode 100644 index 0000000000..765bb5219c --- /dev/null +++ b/TestNG/Activities/Activity1.java @@ -0,0 +1,43 @@ +package activities; + +import org.testng.annotations.Test; +import org.testng.annotations.BeforeClass; + +import static org.testng.Assert.assertEquals; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.annotations.AfterClass; + +public class Activity1 { + + //declare the class objects + WebDriver driver; + + @BeforeClass + public void setUp() + { + driver = new FirefoxDriver(); + driver.get("https://training-support.net/"); + } + + @Test(priority = 1) + public void pageTitleTest() + { + assertEquals(driver.getTitle(),"Training Support"); + } + + @Test(priority = 2) + public void aboutLinkTest() + { + driver.findElement(By.linkText("About Us")).click(); + assertEquals(driver.getTitle(),"About Training Support"); + } + @AfterClass + public void tearDown() + { + driver.quit(); + } + +} diff --git a/TestNG/Activities/Activity10.java b/TestNG/Activities/Activity10.java new file mode 100644 index 0000000000..be2949f8e9 --- /dev/null +++ b/TestNG/Activities/Activity10.java @@ -0,0 +1,106 @@ +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 Activity10 { + 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/sample.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/Activity2.java b/TestNG/Activities/Activity2.java new file mode 100644 index 0000000000..3c4f6efc57 --- /dev/null +++ b/TestNG/Activities/Activity2.java @@ -0,0 +1,64 @@ +package activities; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.SkipException; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +public class Activity2 { + WebDriver driver; + + @BeforeTest + public void beforeMethod() { + // Set up the Firefox driver + //WebDriverManager.firefox().setup(); + //Create a new instance of the Firefox driver + driver = new FirefoxDriver(); + + //Open the browser + driver.get("https://v1.training-support.net/selenium/target-practice"); + } + + @Test + public void testCase1() { + //This test case will pass + String title = driver.getTitle(); + System.out.println("Title is: " + title); + assertEquals(title, "Target Practice"); + } + + @Test + public void testCase2() { + //This test case will Fail + WebElement blackButton = driver.findElement(By.cssSelector("button.black")); + assertTrue(blackButton.isDisplayed()); + 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(); + 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"); + } + + @AfterTest + public void afterMethod() { + //Close the browser + driver.close(); + } + +} diff --git a/TestNG/Activities/Activity2_new.java b/TestNG/Activities/Activity2_new.java new file mode 100644 index 0000000000..70c9b30164 --- /dev/null +++ b/TestNG/Activities/Activity2_new.java @@ -0,0 +1,59 @@ +package activities; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.testng.SkipException; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +public class Activity2 { + WebDriver driver; + + @BeforeTest + public void beforeMethod() { + + driver = new FirefoxDriver(); + driver.get("https://v1.training-support.net/selenium/target-practice"); + } + + @Test + public void testCase1() { + + String title = driver.getTitle(); + System.out.println("Title is: " + title); + assertEquals(title, "Target Practice"); + } + + @Test + public void testCase2() { + + WebElement blackButton = driver.findElement(By.cssSelector("button.black")); + assertTrue(blackButton.isDisplayed()); + assertEquals(blackButton.getText(), "Black"); + } + + @Test(enabled = false) + public void testCase3() { + + String subHeading = driver.findElement(By.className("sub")).getText(); + assertTrue(subHeading.contains("Practice")); + } + + @Test + public void testCase4() { + throw new SkipException("Skipping test case"); + } + + @AfterTest + public void afterMethod() { + + driver.close(); + } + +} diff --git a/TestNG/Activities/Activity3.java b/TestNG/Activities/Activity3.java new file mode 100644 index 0000000000..b6816e6368 --- /dev/null +++ b/TestNG/Activities/Activity3.java @@ -0,0 +1,48 @@ +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.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class Activity3 { + WebDriver driver; + + @BeforeClass + public void beforeClass() { + // Set up the Firefox driver + //WebDriverManager.firefox().setup(); + driver = new FirefoxDriver(); + + //Open browser + driver.get("https://v1.training-support.net/selenium/login-form"); + } + + @Test + public void loginTest() { + //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()='Log in']")).click(); + + //Read login message + String loginMessage = driver.findElement(By.id("action-confirmation")).getText(); + Assert.assertEquals("Welcome Back, admin", loginMessage); + } + + @AfterClass + public void afterClass() { + //Close browser + driver.close(); + } +} diff --git a/TestNG/Activities/Activity3_new.java b/TestNG/Activities/Activity3_new.java new file mode 100644 index 0000000000..e7ae022619 --- /dev/null +++ b/TestNG/Activities/Activity3_new.java @@ -0,0 +1,35 @@ +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.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class Activity3 { + WebDriver driver; + + @BeforeClass + public void beforeClass() { + driver = new FirefoxDriver(); + driver.get("https://v1.training-support.net/selenium/login-form"); + } + + @Test + public void loginTest() { + WebElement username = driver.findElement(By.id("username")).sendKeys("admin"); + WebElement password = driver.findElement(By.id("password")).sendKeys("password"); + + driver.findElement(By.xpath("//button[text()='Log in']")).click(); + String loginMessage = driver.findElement(By.id("action-confirmation")).getText(); + Assert.assertEquals("Welcome Back, admin", loginMessage); + } + + @AfterClass + public void afterClass() { + driver.close(); + } +} diff --git a/TestNG/Activities/Activity4_DemoOne.java b/TestNG/Activities/Activity4_DemoOne.java new file mode 100644 index 0000000000..16fdfc4c53 --- /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..d3526932a6 --- /dev/null +++ b/TestNG/Activities/Activity4_DemoTwo.java @@ -0,0 +1,13 @@ +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/Activity5.java b/TestNG/Activities/Activity5.java new file mode 100644 index 0000000000..c26775cd95 --- /dev/null +++ b/TestNG/Activities/Activity5.java @@ -0,0 +1,62 @@ +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 Activity5 { + + WebDriver driver; + @BeforeClass(alwaysRun = true) + public void setUp() { + driver = new FirefoxDriver(); + + 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(@class, 'purple')]")).getCssValue("color")); + Assert.assertEquals(button2Color.asHex(), "#581c87"); + } + + + @AfterClass(alwaysRun = true) + public void tearDown() { + + driver.close(); + + } +} + + diff --git a/TestNG/Activities/Activity6.java b/TestNG/Activities/Activity6.java new file mode 100644 index 0000000000..e0f1f40c57 --- /dev/null +++ b/TestNG/Activities/Activity6.java @@ -0,0 +1,51 @@ +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.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; +public class Activity6 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void beforeClass() { + // Initialize the Firefox driver + driver = new FirefoxDriver(); + + //Open browser + driver.get("https://training-support.net/webelements/login-form"); + } + + @Test + @Parameters({"username", "password"}) + public void loginTestCase(String username, String password) { + //Find username and pasword fields + WebElement usernameField = driver.findElement(By.id("username")); + WebElement passwordField = driver.findElement(By.id("password")); + + //Enter values + usernameField.sendKeys(username); + passwordField.sendKeys(password); + + //Click Log in + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + + //Assert Message + String loginMessage = driver.findElement(By.xpath("//h2")).getText(); + Assert.assertEquals(loginMessage, "Welcome Back, Admin!"); + } + + @AfterClass + public void afterClass() { + //Close browser + driver.close(); + } + +} diff --git a/TestNG/Activities/Activity6_new.java b/TestNG/Activities/Activity6_new.java new file mode 100644 index 0000000000..fa8c8c557d --- /dev/null +++ b/TestNG/Activities/Activity6_new.java @@ -0,0 +1,40 @@ +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.ui.WebDriverWait; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; +public class Activity6 { + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void beforeClass() { + driver = new FirefoxDriver(); + driver.get("https://training-support.net/webelements/login-form"); + } + + @Test + @Parameters({"username", "password"}) + public void loginTestCase(String username, String password) { + //Find username and pasword fields + WebElement usernameField = driver.findElement(By.id("username")).sendKeys(username); + WebElement passwordField = driver.findElement(By.id("password")).sendKeys(password); + + driver.findElement(By.xpath("//button[text()='Submit']")).click(); + String loginMessage = driver.findElement(By.xpath("//h2")).getText(); + Assert.assertEquals(loginMessage, "Welcome Back, Admin!"); + } + + @AfterClass + public void afterClass() { + driver.close(); + } + +} diff --git a/TestNG/Activities/Activity7.java b/TestNG/Activities/Activity7.java new file mode 100644 index 0000000000..91832d8172 --- /dev/null +++ b/TestNG/Activities/Activity7.java @@ -0,0 +1,82 @@ +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.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class Activity7 { + WebDriver driver; + WebDriverWait wait; + + @BeforeMethod + public void setUp() { + + //opening the browser + driver = new FirefoxDriver(); + + // adding web driver wait + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + // Open the page + driver.get("https://training-support.net/webelements/login-form"); + } + + @Test(priority = 1) + public void pageTitle() + { + Assert.assertEquals(driver.getTitle(), "Selenium : Login Form"); + } + @DataProvider(name = "Credentials") + public static Object[][] credentials() { + return new Object[][] { + { "admin1", "password1", "Invalid Credentials" }, + { "wrongAdmin", "wrongPassword", "Invalid Credentials" }, + {"wrongUser" , "wrongPassword" , "Invalid Credentials"} + + }; + + + } + + @Test(dataProvider = "Credentials" , priority = 2) + public void loginTest(String username, String password, String expectedMessage) { + + WebElement usernameField = driver.findElement(By.id("username")); + WebElement passwordField = driver.findElement(By.id("password")); + WebElement loginButton = driver.findElement(By.xpath("//button[text()='Submit']")); + + + usernameField.clear(); + passwordField.clear(); + // Enter the credentials and click Log in + usernameField.sendKeys(username); + passwordField.sendKeys(password); + loginButton.click(); + + try { + Thread.sleep(5000); + }catch (InterruptedException e) { + // TODO: handle exception + e.printStackTrace(); + } + // Assert login message + String loginMessage = driver.findElement(By.id("subheading")).getText(); + Assert.assertEquals(loginMessage, expectedMessage); + } + + @AfterClass + public void tearDown() { + // Close the browser + driver.quit(); + } +} \ No newline at end of file diff --git a/TestNG/Activities/Activity8.xml b/TestNG/Activities/Activity8.xml new file mode 100644 index 0000000000..f924192786 --- /dev/null +++ b/TestNG/Activities/Activity8.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TestNG/Activities/Activity8_new.xml b/TestNG/Activities/Activity8_new.xml new file mode 100644 index 0000000000..5d0a8e5be5 --- /dev/null +++ b/TestNG/Activities/Activity8_new.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TestNG/Activities/Activity9.java b/TestNG/Activities/Activity9.java new file mode 100644 index 0000000000..1ac3842267 --- /dev/null +++ b/TestNG/Activities/Activity9.java @@ -0,0 +1,98 @@ +package activities; + +import java.time.Duration; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +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 activity9 { + + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() { + + driver = new FirefoxDriver(); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + driver.get("https://training-support.net/webelements/alerts"); + + + } + + @BeforeMethod() + public void defaultContent() { + + driver.switchTo().defaultContent(); + + } + + + @Test(priority = 1) + public void simpleAlertTestCase() { + + driver.findElement(By.id("simple")).click(); + Reporter.log("Simple Alert opened |"); + Alert smplAlert = driver.switchTo().alert(); + Reporter.log(smplAlert.getText()); + + smplAlert.accept(); + + String msg = driver.findElement(By.id("result")).getText(); + Assert.assertEquals(msg, "You just accepted a simple alert!"); + + } + @Test(priority = 2) + public void confirmAlertTestCase() { + + driver.findElement(By.id("confirmation")).click(); + Reporter.log("Confirm Alert opened |"); + Alert cnfrmAlert = driver.switchTo().alert(); + Reporter.log(cnfrmAlert.getText()); + + cnfrmAlert.accept(); + + String msg = driver.findElement(By.id("result")).getText(); + Assert.assertEquals(msg, "You just accepted a confirmation alert!"); + + + } + + @Test(priority = 3) + public void promptAlertTestCase() { + + driver.findElement(By.id("prompt")).click(); + Reporter.log("Prompt Alert opened |"); + Alert promptAlert = driver.switchTo().alert(); + Reporter.log(promptAlert.getText()); + + promptAlert.sendKeys("Madhu"); + promptAlert.accept(); + + String msg = driver.findElement(By.id("result")).getText(); + Assert.assertEquals(msg, "You typed \"Madhu\" into the prompt!"); + + + } + + + @AfterClass + public void tearDown() { + + driver.quit(); + + } + + + +} diff --git a/TestNG/Activities/Activity9_new.java b/TestNG/Activities/Activity9_new.java new file mode 100644 index 0000000000..1aee06ab3e --- /dev/null +++ b/TestNG/Activities/Activity9_new.java @@ -0,0 +1,98 @@ +package activities; + +import java.time.Duration; + +import org.openqa.selenium.Alert; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.support.ui.WebDriverWait; +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 activity9 { + + WebDriver driver; + WebDriverWait wait; + + @BeforeClass + public void setUp() { + + driver = new FirefoxDriver(); + wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + + driver.get("https://training-support.net/webelements/alerts"); + + + } + + @BeforeMethod() + public void defaultContent() { + + driver.switchTo().defaultContent(); + + } + + + @Test(priority = 1) + public void simpleAlert() { + + driver.findElement(By.id("simple")).click(); + Reporter.log("Simple Alert opened |"); + Alert smplAlert = driver.switchTo().alert(); + Reporter.log(smplAlert.getText()); + + smplAlert.accept(); + + String msg = driver.findElement(By.id("result")).getText(); + Assert.assertEquals(msg, "You just accepted a simple alert!"); + + } + @Test(priority = 2) + public void confirmAlert() { + + driver.findElement(By.id("confirmation")).click(); + Reporter.log("Confirm Alert opened |"); + Alert cnfrmAlert = driver.switchTo().alert(); + Reporter.log(cnfrmAlert.getText()); + + cnfrmAlert.accept(); + + String msg = driver.findElement(By.id("result")).getText(); + Assert.assertEquals(msg, "You just accepted a confirmation alert!"); + + + } + + @Test(priority = 3) + public void promptAlert() { + + driver.findElement(By.id("prompt")).click(); + Reporter.log("Prompt Alert opened |"); + Alert promptAlert = driver.switchTo().alert(); + Reporter.log(promptAlert.getText()); + + promptAlert.sendKeys("Malli"); + promptAlert.accept(); + + String msg = driver.findElement(By.id("result")).getText(); + Assert.assertEquals(msg, "You typed \"Malli\" into the prompt!"); + + + } + + + @AfterClass + public void tearDown() { + + driver.quit(); + + } + + + +}