Welcome to the Simplilearn Community

Want to join the rest of our members? Sign up right away!

Sign Up

Selenium Certification Training Mar Apr 2021

harishp1906

Well-Known Member
Hi Team,

Sharing the Java Assignment which you can practice out this week.

Waiting to meet you all upcoming week to start with Automation :)
 

Attachments

  • ClassObjectAssignments.txt
    1.1 KB · Views: 24

harishp1906

Well-Known Member
Team,

Please find the attachment on the definitions and example which we saw in our class. Once we get the Gdrive link I will update the slides deck as well.
 

Attachments

  • Definitions.pdf
    259.4 KB · Views: 21

harishp1906

Well-Known Member
Hi Team,

Sharing the assignment for the week below,

Step1: Create a testng project using eclipse
Step2: Register an account http://automationpractice.com/index.php on this website manually
Step 3: Automate the login flow with the registered credentials
Step 4: Print the page url, title before and after login and write a java if condition to check the url and page title are valid
Step 5: Generate testng html report using @Test

Please let me know for any clarifications.
 

_27971

Member
Hello I am not able to create an account in mentioned site can you please share another link for create account in another side ??

1616580056765.png
 
Harish please can we have some shared documentation on API please.

Please share the notepad used during class and the definition doco used last week on HTML etc....

Also has the power points used in class been shared yet? Please let me know where can I get access to it. Thanks.
 
Last edited:

rohini aher_2

Customer
Customer
Hi Team,

Sharing the assignment for the week below,

Step1: Create a testng project using eclipse
Step2: Register an account http://automationpractice.com/index.php on this website manually
Step 3: Automate the login flow with the registered credentials
Step 4: Print the page url, title before and after login and write a java if condition to check the url and page title are valid
Step 5: Generate testng html report using @Test

Please let me know for any clarifications.
Please review the assignment. For privacy reason I added the dummy credentials. Code run successfully if I add valid credentials.
 
Hi Team,

Sharing the assignment for the week below,

Step1: Create a testng project using eclipse
Step2: Register an account http://automationpractice.com/index.php on this website manually
Step 3: Automate the login flow with the registered credentials
Step 4: Print the page url, title before and after login and write a java if condition to check the url and page title are valid
Step 5: Generate testng html report using @Test

Please let me know for any clarifications.
package com.browser;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

public class TestNGassignment1 {

@Test
public void automationpractice() {


System.setProperty("webdriver.chrome.driver", "./BrowserUtils/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://automationpractice.com/index.php");

System.out.println(driver.getCurrentUrl());
System.out.println(driver.getTitle());
if(driver.getCurrentUrl().equals("http://automationpractice.com/index.php") &&
driver.getTitle().equals("My Store")) {
System.out.println("PASSED");
}
else {
System.out.println("FAIL");
}

driver.findElement(By.className("login")).click();
driver.findElement(By.id("email")).sendKeys("varssai@gmail.com");
driver.findElement(By.id("passwd")).sendKeys("Varshasai123");
driver.findElement(By.id("SubmitLogin")).click();
System.out.println(driver.getCurrentUrl());
System.out.println(driver.getTitle());
if(driver.getCurrentUrl().equals("http://automationpractice.com/index.php?controller=my-account") &&
driver.getTitle().equals("My account - My Store")) {
System.out.println("PASSED");
}
else {
System.out.println("FAIL");
}
driver.close();

}
}


Console:
My Store
PASSED
My account - My Store
PASSED
PASSED: automationpractice

===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
 

Taruna Arora

New Member
Hi Harish,

Can you please look into the below error,


Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /Users/Taruna.arora/eclipse-workspace/FirstSelenuimProject/./BrowserUtils/chromedriver.exe
at com.google.common.base.Preconditions.checkState(Preconditions.java:585)
at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:146)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:141)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at com.browser.seleniumclass.main(seleniumclass.java:15)

Below is the code for which I am getting above mentioned error:


package com.browser;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class seleniumclass {
public static void main (String args[])


{
System.setProperty("webdriver.chrome.driver", "./BrowserUtils/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.rediff.com/");
System.out.println(driver.getCurrentUrl());
System.out.println(driver.getTitle());

//driver.findElement(By.id("login")).click();

driver.close();

}
}

Please let know what mistake I am actually doing.
 

varunbhatia84

Member
Alumni
My Code and result Attached

Created 7 methods
LoginPage()-->launches login page
URLBefore()-->comparing page URL before login
TitleBefore()-->comparing page Title before login
loginCredentials()--> Login into the website
URLAfterLogin()-->comparing page URL after login
TitleAfterLogin()-->Comparing Title after logging in
closeBrowser()-->Closes the browser
 

Attachments

  • Assignment Week2_Varun Bhatia.pdf
    449.5 KB · Views: 10
Last edited:

rohini aher_2

Customer
Customer
Hi Harish @harishp1906

Please help me here.

I am not clear here with Rel xpath for the checkbox in website 'http://the-internet.herokuapp.com/checkboxes'

When I hover over the 1st checkbox - and search for xpath - I see '//input[1]" and not "//body//div//input[1]"

Please guide me. Attaching screenshot here as well.
Hi Caroline, reletive xpath is small which can search elements anywhere on the webpage. so //input[1] is just sufficient to identify the web element on the given web page. while absolute xpath is long as it always start from the html tag like /html/body till the web element path.
 

SEAH CHEN KHOON

New Member
Dear Sir,
I need some help. I have a problem with testing on a website. The code basically
1> Get webElements via xpath
2> Print a stub that contains a number of webElement count
3> Sleep for 2 secs
4> Refresh the page
5> Get webElements via xpath
6> Print a stub that contains a number of webElement count

Step 2 output count 10
Step 6 - If I refresh the page (Step 4), the count becomes 0. Without Step 4, the count is 10.

Please advise how can I refresh the page and get the webElement count number to be 10?

Thank you.

List<WebElement> webElements = driver.findElements(By.xpath("//div[@class='form-horizontal bgp-radio-group']/div/div/div/label/parent::div/parent::div//parent::div/div[2]/label[1]/span"));
System.out.println("hello " + webElements.size());

Thread.sleep(2000L);

// Refresh Page
driver.navigate().refresh();
webElements = driver.findElements(By.xpath("//div[@class='form-horizontal bgp-radio-group']/div/div/div/label/parent::div/parent::div//parent::div/div[2]/label[1]/span"));
System.out.println("hello " + webElements.size());
 

Niki Sweta Sahay

Customer
Customer
Hi Harish ,

While running the TestNG file and dont see the option TestNG Suite to run the program I tried running from the configurations also but it does not work.I get the below error.

org.testng.TestNGException:
TestNG by default disables loading DTD from unsecured Urls. If you need to explicitly load the DTD from a http url, please do so by using the JVM argument [-Dtestng.dtd.http=true]
at org.testng.xml.TestNGContentHandler.resolveEntity(TestNGContentHandler.java:115)
at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(Unknown Source)

Error attached below
 

Attachments

  • TestNG Error.txt
    2.1 KB · Views: 2

varunbhatia84

Member
Alumni
Hi Harish,

While executing the code for Safari browser, I am seeing "NosuchElementExecption" while doing send keys operation.

Can you please advice.

Code used :

public
void dloginCredentials() {


WebElement emailTextBox=driver.findElement(By.xpath("//input[@id='email']"));
WebElement Password= driver.findElement(By.xpath("//input[@id='passwd']"));
WebElement LoginButton=driver.findElement(By.xpath("//button[@id='SubmitLogin']"));

WebDriverWait wait1=new WebDriverWait(driver,10);


//Step 2 wait for an element to display or load in the webpage
wait1.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@id='email']")));
emailTextBox.sendKeys("varunbhatia84@gmail.com");

//Step 3 wait for an element to display or load in the webpage
wait1.until(ExpectedConditions.visibilityOf(Password));
Password.sendKeys("varun123");
//Step 2 wait for an element to display or load in the webpage
wait1.until(ExpectedConditions.visibilityOf(LoginButton));
LoginButton.click();
System.out.println("Login successful"+'\n');


}

Exception thrown :

FAILED: dloginCredentials


org.openqa.selenium.NoSuchElementException:


For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html


Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'


System info: host: 'Hridhaans-MacBook-Pro.local', ip: '2405:201:4008:850:f104:ae6:ea00:777f%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_281'


Driver info: org.openqa.selenium.safari.SafariDriver


Capabilities {acceptInsecureCerts: false, browserName: Safari, browserVersion: 14.0.3, javascriptEnabled: true, platform: MAC, platformName: MAC, safari:automaticInspection: false, safari:automaticProfiling: false, safari:diagnose: false, safari:platformBuildVersion: 20D91, safari:platformVersion: 11.2.3, safari:useSimulator: false, setWindowRect: true, strictFileInteractability: false, webkit:WebRTC: {DisableICECandidateFiltering: false, DisableInsecureMediaCapture: false}}


Session ID: 8D3D6E9B-FE11-43F0-8225-8DD38A14E068


*** Element info: {Using=xpath, value=//input[@id='email']}
 

harishp1906

Well-Known Member
Harish please can we have some shared documentation on API please.

Please share the notepad used during class and the definition doco used last week on HTML etc....

Also has the power points used in class been shared yet? Please let me know where can I get access to it. Thanks.
Hey Caroline, I will share the slides as well the notepad this week.
 

harishp1906

Well-Known Member
Hi Harish,

While executing the code for Safari browser, I am seeing "NosuchElementExecption" while doing send keys operation.

Can you please advice.

Code used :

public
void dloginCredentials() {


WebElement emailTextBox=driver.findElement(By.xpath("//input[@id='email']"));
WebElement Password= driver.findElement(By.xpath("//input[@id='passwd']"));
WebElement LoginButton=driver.findElement(By.xpath("//button[@id='SubmitLogin']"));

WebDriverWait wait1=new WebDriverWait(driver,10);


//Step 2 wait for an element to display or load in the webpage
wait1.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@id='email']")));
emailTextBox.sendKeys("varunbhatia84@gmail.com");

//Step 3 wait for an element to display or load in the webpage
wait1.until(ExpectedConditions.visibilityOf(Password));
Password.sendKeys("varun123");
//Step 2 wait for an element to display or load in the webpage
wait1.until(ExpectedConditions.visibilityOf(LoginButton));
LoginButton.click();
System.out.println("Login successful"+'\n');


}

Exception thrown :

FAILED: dloginCredentials


org.openqa.selenium.NoSuchElementException:


For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html


Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'


System info: host: 'Hridhaans-MacBook-Pro.local', ip: '2405:201:4008:850:f104:ae6:ea00:777f%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.16', java.version: '1.8.0_281'


Driver info: org.openqa.selenium.safari.SafariDriver


Capabilities {acceptInsecureCerts: false, browserName: Safari, browserVersion: 14.0.3, javascriptEnabled: true, platform: MAC, platformName: MAC, safari:automaticInspection: false, safari:automaticProfiling: false, safari:diagnose: false, safari:platformBuildVersion: 20D91, safari:platformVersion: 11.2.3, safari:useSimulator: false, setWindowRect: true, strictFileInteractability: false, webkit:WebRTC: {DisableICECandidateFiltering: false, DisableInsecureMediaCapture: false}}


Session ID: 8D3D6E9B-FE11-43F0-8225-8DD38A14E068


*** Element info: {Using=xpath, value=//input[@id='email']}
Hi Varun,

Can you please share the base URL, I need to check the xpath once.
 

harishp1906

Well-Known Member
Hi Harish ,

While running the TestNG file and dont see the option TestNG Suite to run the program I tried running from the configurations also but it does not work.I get the below error.

org.testng.TestNGException:
TestNG by default disables loading DTD from unsecured Urls. If you need to explicitly load the DTD from a http url, please do so by using the JVM argument [-Dtestng.dtd.http=true]
at org.testng.xml.TestNGContentHandler.resolveEntity(TestNGContentHandler.java:115)
at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(Unknown Source)

Error attached below
Hi Niki,

Try updating the below values in your xml file,

Just change all yours

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"

on https:

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd"
 

harishp1906

Well-Known Member
Dear Sir,
I need some help. I have a problem with testing on a website. The code basically
1> Get webElements via xpath
2> Print a stub that contains a number of webElement count
3> Sleep for 2 secs
4> Refresh the page
5> Get webElements via xpath
6> Print a stub that contains a number of webElement count

Step 2 output count 10
Step 6 - If I refresh the page (Step 4), the count becomes 0. Without Step 4, the count is 10.

Please advise how can I refresh the page and get the webElement count number to be 10?

Thank you.

List<WebElement> webElements = driver.findElements(By.xpath("//div[@class='form-horizontal bgp-radio-group']/div/div/div/label/parent::div/parent::div//parent::div/div[2]/label[1]/span"));
System.out.println("hello " + webElements.size());

Thread.sleep(2000L);

// Refresh Page
driver.navigate().refresh();
webElements = driver.findElements(By.xpath("//div[@class='form-horizontal bgp-radio-group']/div/div/div/label/parent::div/parent::div//parent::div/div[2]/label[1]/span"));
System.out.println("hello " + webElements.size());
Hi Seah,

You are try the refresh option from webdriver or you can try to navigate the same url again by giving navigate().to() method.
 

harishp1906

Well-Known Member
Hi Caroline, reletive xpath is small which can search elements anywhere on the webpage. so //input[1] is just sufficient to identify the web element on the given web page. while absolute xpath is long as it always start from the html tag like /html/body till the web element path.
Thanks Rohini for helping Caroline.
 

rohini aher_2

Customer
Customer
Hi Harish ,

While running the TestNG file and dont see the option TestNG Suite to run the program I tried running from the configurations also but it does not work.I get the below error.

org.testng.TestNGException:
TestNG by default disables loading DTD from unsecured Urls. If you need to explicitly load the DTD from a http url, please do so by using the JVM argument [-Dtestng.dtd.http=true]
at org.testng.xml.TestNGContentHandler.resolveEntity(TestNGContentHandler.java:115)
at com.sun.org.apache.xerces.internal.util.EntityResolverWrapper.resolveEntity(Unknown Source)

Error attached below
Hi niki, can you share the code as well?
 

Niki Sweta Sahay

Customer
Customer
I am attaching the codes for testng.xml and a class called ParallelExecution on which we were running the TestNG suite in the class
 

Attachments

  • Error TestNGSuite.txt
    1.2 KB · Views: 1

varunbhatia84

Member
Alumni
Hi Harish,
I was working on the PF model, I created two packages( 1 will have object file, 2nd will have Test case files)
1. Login Page Element Object and Test Case class--Here we click on sign in link--which worked fine
2. Next I created a new object file to pass email ID ,password and click on sign in link
When I make Test case class for the object class, I am not able to see the methods for the Test case class

I have attached code for your reference
 

Attachments

  • ObjectModel Issue.pdf
    362.2 KB · Views: 4
Hi Caroline, reletive xpath is small which can search elements anywhere on the webpage. so //input[1] is just sufficient to identify the web element on the given web page. while absolute xpath is long as it always start from the html tag like /html/body till the web element path.
Thanks Rohini.
 

rohini aher_2

Customer
Customer
I am attaching the codes for testng.xml and a class called ParallelExecution on which we were running the TestNG suite in the class

I am attaching the codes for testng.xml and a class called ParallelExecution on which we were running the TestNG suite in the class
Hi niki, you have to modify the xml file, line no 2 from <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> with this line <!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">. You have to give https instead of http.
 

varunbhatia84

Member
Alumni
Hi Harish,
Following details are required in respect to MAC with selenium :
1. Alternative to Auto IT programme.
2. GIT hub commands for MAC
3. Previous query where send keys command is not working for MAC
4.Also specific setting required to run programme in MAC.

I will let you know further queries in respect to MAC once I try to work on project.
 

harishp1906

Well-Known Member
Hi Harish,
I was working on the PF model, I created two packages( 1 will have object file, 2nd will have Test case files)
1. Login Page Element Object and Test Case class--Here we click on sign in link--which worked fine
2. Next I created a new object file to pass email ID ,password and click on sign in link
When I make Test case class for the object class, I am not able to see the methods for the Test case class

I have attached code for your reference
Hi Varun,

The issue here is, you haven't written Main method or used @Test annotation in your Test case 2 class. We need to create the object for the class inside the main method or @Test annotation and you will be able to access the methods inside the objects class.

Ex:

WebDriver driver;

@Test

public void Testcase2()

{
SignInElementsObjects sp = new SignInElementsObjects(driver);
sp.emailID();

}
 

harishp1906

Well-Known Member
Any updates?

Hi Varun,

I executed the same script in my Mac machine and I did not face any issues on execution. Sharing the code below.

I believe there might be wait issue on running in your Mac, try to give wait commands after loading the page and try out.

public class LoginTestCase1 {


public static void main(String args[]){

System.setProperty("webdriver.chrome.driver", "./BrowserUtils/chromedriver.exe");

WebDriver driver = new ChromeDriver();

driver.get("http://www.automationpractice.com/index.php?controller=authentication&back=my-account");

WebElement emailTextBox=driver.findElement(By.xpath("//input[@id='email']"));
WebElement Password= driver.findElement(By.xpath("//input[@id='passwd']"));
WebElement LoginButton=driver.findElement(By.xpath("//button[@id='SubmitLogin']"));

WebDriverWait wait1=new WebDriverWait(driver,10);


//Step 2 wait for an element to display or load in the webpage
wait1.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@id='email']")));
emailTextBox.sendKeys("varunbhatia84@gmail.com");

//Step 3 wait for an element to display or load in the webpage
wait1.until(ExpectedConditions.visibilityOf(Password));
Password.sendKeys("varun123");
//Step 2 wait for an element to display or load in the webpage
wait1.until(ExpectedConditions.visibilityOf(LoginButton));
LoginButton.click();
System.out.println("Login successful"+'\n');


}


}
 

harishp1906

Well-Known Member
Hi Harish,
Following details are required in respect to MAC with selenium :
1. Alternative to Auto IT programme.
2. GIT hub commands for MAC
3. Previous query where send keys command is not working for MAC
4.Also specific setting required to run programme in MAC.

I will let you know further queries in respect to MAC once I try to work on project.

Hi Varun,

Please find my responses below,

Question1:Currently there is no such tool which is alternative of AutoIT. From Selenium stand point we use AutoIT majorly on Upload file scenario. You can use Robot class for uploading file.

Example:

public static void setClipboardData(String string) {
//StringSelection is a class that can be used for copy and paste operations.
StringSelection stringSelection = new StringSelection(string);
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
}
public static void uploadFile(String fileLocation) {
try {
//Setting clipboard with file location
setClipboardData(fileLocation);
//native key strokes for CTRL, V and ENTER keys
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (Exception exp) {
exp.printStackTrace();
}
}

Question2: For Mac there are few additional steps from installation stand point. Other steps on git are same what we saw in class. Please find the below link for step by step details.


Question 3: Have already addressed it above.

Question 4: Can you please be specific on what program are you trying to run. I believe you are able to execute selenium code with Java in your mac machine. Let me know if there is anything apart from this.
 
Hi Harish

Just checking if these dependencies are correct for ReportNG

<!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/velocity/velocity-dep -->
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity-dep</artifactId>
<version>1.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
</dependency>

@harishp1906

Thanks
 

harishp1906

Well-Known Member
Hi Harish

Just checking if these dependencies are correct for ReportNG

<!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/velocity/velocity-dep -->
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity-dep</artifactId>
<version>1.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
</dependency>

@harishp1906

Thanks
Hi Caroline,

Its correct, just sharing the ones shown in class below. Also just a reminder on "Extent Reports", dont forget to try that one out! :)

<dependency>
<groupId>velocity</groupId>
<artifactId>velocity-dep</artifactId>
<version>1.4</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.google.inject/guice -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.relevantcodes/extentreports -->
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
 
Top