// Find item using id:
const myElement = await driver.$('id:myElementSelector');
// Click element
await myElement.click();
**********************************************
// Find element using XPath
const myElement1 = await driver.$('//xpath/to/element');
// Click element
await myElement1.click();
**********************************************
// Find an item using Accessibility id:
const myElement2 = await driver.$('~accessibilityid:');
// Click element
await myElement2.click();
**********************************************
// Wait for 3 seconds
await driver.pause(3000)
**********************************************
// Clear and Sendkeys to element
const element = await driver.$('id:myInputid:');
await element.setValue("example@mail.com"); // Assigning a value to Input
await element.clearValue(); // Clearing the content of the input element
**********************************************
// Add a value to an input or textarea element found by given selector.
let input = await $('.input')
await input.addValue('test')
**********************************************
// Swipe action with start XY and end XY coordinates
driver.touchAction([
{ action: 'press', x: 100, y: 200 }, // Starting point
{ action: 'moveTo', x: 100, y: 100 }, // target point
'release' // Drag action release
]);
**********************************************
// Find an item using id:
const myElement =await driver.$('id:myElementid:');
// Perform a swipe after finding the item
myElement.touchAction([
{ action: 'press', x: 100, y: 200 }, // Starting point
{ action: 'moveTo', x: 100, y: 100 }, // target point
'release' // Drag action release
]);
**********************************************
// Target a specific location for the swipe action
driver.touchAction([
{ action: 'press', x: 100, y: 200 }, // Başlangıç noktası
{ action: 'moveTo', x: 100, y: 100 }, // Hedef noktası
'release' // Sürükleme işlemi serbest bırakma
]);
**********************************************
//Get attribute of element and compare the text
const elem =await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]").getText();
or
const elem =await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]").getAttribute("text");
or
const elem =await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]").getAttribute("value");
if(elem=="Kaydol"){
await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]").click();
}
**********************************************
//Custom Logging
driver.log("my custom log)
**********************************************
//You can define a variable in the header and use the variable you define in the steps on the Case Management screen.
var username = "example"
driver.setValue(variable)
driver.log("**********"+username);
username = "ahmet mehmet"
driver.log("******"+username);
**********************************************
//Take Screenshot
await driver.saveScreen();
**********************************************
//Assert example with console log
const myText = await driver.$('(//*[contains(@name,"Kaydol") or contains(@label,"Kaydol")])[2]')
const text = await myText.getText()
await driver.log("***********"+text)
assert(text === 'Kaydol')
assert.equal(text,"Kaydol")
**********************************************
// Assert with example to use Expect
const elem =await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]").getText();
// Compare expected text and actual text.
expect(elem).to.equal("Atla");
**********************************************
// Expectation: The element exists
const elem =await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]").getText();
expect(elem).to.exist;
**********************************************
// Expectation: The text of the element should be equal to a certain value.
var elem =await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]");
expect(await elem.getText()).to.equal('Expected Text');
**********************************************
//Double-click on an element.
const myButton = await $('id:myButton')
await myButton.doubleClick()
**********************************************
// Expectation: The element exists
var elem =await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]")
assert.ok(await elem.isExisting(), 'Element bulunamadı');
**********************************************
// Expectation: Element to be visible
var elem =await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]")
assert.ok(await elem.isDisplayed(), 'Element görünür değil');
**********************************************
// Expectation: The text of the element should be equal to a certain value
var elem =await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]")
assert.strictEqual(await elem.getText(), 'Expected Text', 'Element metni beklenen değere eşit değil');
**********************************************
// Assert with notEqual example
var text = await driver.$("(//*[contains(@value,'Kaydol') or contains(@name,'Kaydol') or contains(@label,'Kaydol')])[1]").getText();
assert.notEqual(text,"Giriş")
**********************************************
// In WebdriverIO, you can use the Node.js built-in assert.strictEqual method for strict equality assertions. This assertion method compares two values using the strict equality operator (===), ensuring that both the value and the type are the same.
var myText4 = await driver.$('(//*[contains(@name,"Atla") or contains(@label,"Atla")])[1]')
var text4 = await myText4.getAttribute("name")
var el5 = await driver.$("(//*[contains(@value,'Atla') or contains(@name,'Atla') or contains(@label,'Atla')])[1]");
var text5 =await el5.getAttribute("name")
assert.strictEqual(text4, text5, `text4 ${text4} !== text5 ${text5}`);
// AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2
|